#!/usr/bin/perl -wT # # check users on node # # syntax: # ./check_cpu --host= --community= [--warning=] [--critical=] # # jorgwirelessleiden.nl - 24 januari 2005 use strict; use Getopt::Long; use Net::SNMP; use XML::Simple; use Data::Dumper; # # settings # my $hostname = ""; my $community = "public"; my $warning = "50"; my $critical = "100"; GetOptions("hostname:s" => \$hostname, "community:s" => \$community, "warning:i" => \$warning, "critical:i" => \$critical); # # connect # my $errorcode = 0; my ($session, $error) = Net::SNMP->session(-hostname => $hostname, -community => $community, -timeout => 30, -retries => 0); if (! defined $session) { printf("ERROR Connecting: %s.\n", $error); exit 3; # unknown } # ipNetToMediaPhysAddress.* my $oid = ".1.3.6.1.2.1.4.22.1.2"; my $result = $session->get_table(-baseoid => $oid); if (!defined($result)) { # i give up... #printf("ERROR: %s.\n", $session->error); print("No response.\n"); $session->close; exit 3; # unknown } # # parse data # my %result2 = %{$result}; for my $key (keys %result2) { print $result2{$key} . "\n"; } # # exit # (0=ok 1=warning 2=critical 3=unknown 4=dependent) # print "errorcode: $errorcode\n"; $session->close; exit $errorcode;