commit 0762973bddde267ebb6ec0783ef5b6ec56d4d48a Author: Arne Baeumler Date: Thu Nov 2 21:48:08 2017 +0100 prototyping diff --git a/plugins/snmp/README.md b/plugins/snmp/README.md new file mode 100644 index 0000000..351ad3a --- /dev/null +++ b/plugins/snmp/README.md @@ -0,0 +1,5 @@ +# Usage + +ยดยดยด +./check_snmp.pl -t snmpd -m net -H 192.168.178.100 -c jai3hoiv6aiNg5eikaezie1aengeen7o +``` diff --git a/plugins/snmp/check_snmp.pl b/plugins/snmp/check_snmp.pl new file mode 100755 index 0000000..d4506ca --- /dev/null +++ b/plugins/snmp/check_snmp.pl @@ -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); diff --git a/plugins/snmp/libs/TYPE/SNMPD.pm b/plugins/snmp/libs/TYPE/SNMPD.pm new file mode 100644 index 0000000..5cfd925 --- /dev/null +++ b/plugins/snmp/libs/TYPE/SNMPD.pm @@ -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;