prototyping

This commit is contained in:
Arne Baeumler 2017-11-02 21:48:08 +01:00
commit 0762973bdd
3 changed files with 117 additions and 0 deletions

5
plugins/snmp/README.md Normal file
View File

@ -0,0 +1,5 @@
# Usage
´´´
./check_snmp.pl -t snmpd -m net -H 192.168.178.100 -c jai3hoiv6aiNg5eikaezie1aengeen7o
```

84
plugins/snmp/check_snmp.pl Executable file
View File

@ -0,0 +1,84 @@
#!/usr/bin/perl -tw
use strict;
use warnings;
use lib './libs';
use Getopt::Long qw(:config no_ignore_case);
use Data::Dumper;
use Net::SNMP;
my $verbose = '';
my $type = '';
my $mode = '';
my $host = '';
my $community = '';
GetOptions (
'c=s' => \$community,
'h' => \&help,
'H=s' => \$host,
'm=s' => \$mode,
't=s' => \$type,
'community=s' => \$community,
'help' => \&help,
'host=s' => \$host,
'mode=s' => \$mode,
'type=s' => \$type,
);
my $typeMap = {
'snmpd' => 'TYPE::SNMPD',
'cisco' => 'TYPE::CISCO',
'huawei' => 'TYPE::HUAWEI'
};
my $modeMap = {
'cpu' => \&get_cpu,
'temp' => \&get_temp,
'net' => \&get_net
};
my $t = $typeMap->{$type};
eval "use $t";
my $object = eval { $t->new() };
my $result = eval { $modeMap->{$mode}->() };
sub get_cpu {
}
sub get_temp {
}
sub get_net {
print "Get Net Data...\n";
my %params;
my ($snmp,$error) = Net::SNMP->session(
-hostname => $host,
-community => $community,
-nonblocking => 0
);
my $result = $snmp->get_table(-baseoid => $object->{NET}->{IfTable});
print Dumper($result);
return (%params);
}
sub help {
print qq{
Usage: $0 [...]
-h --help print help page
-v --verbose do some verbose stuff
};
return(0);
}
exit(0);

View File

@ -0,0 +1,28 @@
package TYPE::SNMPD;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw();
our $VERSION = 1.00;
my $oidMap = {
CPU => { CPU0 => '' },
TEMP => { TEMP0 => '' },
NET => {
IfTable => '.1.3.6.1.2.1.2',
IfInOct => '',
IfOutOct => '',
IfInErr => '',
IfOutErr => '',
},
};
sub new {
my ($class) = @_;
my $self = bless($oidMap,$class);
return($self);
}
1;