#!/usr/bin/perl -w use strict; use Net::SNMP; # this script gets passed a machine name ($machine_name) # and then an unknown number of commands if(!defined($ARGV[0])) { print "this scripts takes arguments example: test.pl machine.name command1 command2 command3"; exit(1); } my $machine_name = $ARGV[0]; my $community = 'public'; my $snmp_port = 161; my @Commands; my $i; for ($i=1; $i < $#ARGV; $i++) { push @Commands, $ARGV[$i]; } #test to make sure variables have values. print "/nMachine:$machine_name"; foreach my $command_test (@Commands) { print "command: $command_test\n"; } print "Building Session..."; my ($session, $error) = Net::SNMP->session( -hostname => $machine_name, -community => $community, -port => $snmp_port ); ################################# ### This code above used to be... ### my ($session, $error) = Net::SNMP->session( ### -hostname => shift || 'localhost', ### -community => shift || 'public', ### -port => shift || 161 ### ); ################################# if (!defined($session)) { printf("ERROR in session: %s.\n",$error); exit 1; } ### general OID for system up time my $sysUpTime = '1.3.6.1.2.1.1.3.0'; ### These are Cisco OID's which i use for the AS5400 bank my $ModemsAvailable = '1.3.6.1.4.1.9.9.47.1.1.7.0'; my $ModemsUnavailable = '1.3.6.1.4.1.9.9.47.1.1.8.0'; my $result = $session->get_request( -varbindlist => [$sysUpTime] ); if(!defined($result)) { print "error in result: %s, status:%s.\n",$session->error,$session->error_status); $session->close; exit 1; } my $result2 = $session->get_request( -varbindlist => [$ModemsAvailable] ); if(!defined($result2)) { print "error in result2: %s, status:%s.\n",$session->error,$session->error_status); $session->close; exit 1; } my $result3 = $session->get_request( -varbindlist => [$ModemsUnavailable] }; if(!defined($result3)) { print "error in result3: %s, status:%s.\n",$session->error,$session->error_status); $session->close; exit 1; } print "\nSystem uptime for host: '%s' is %s\n",$session->hostname, $result->{$sysUpTime} ); print "\nModems Available for host: '%s' is %s\n",$session->hostname, $result->{$sysUpTime} ); print "\nModems Unavailable for host: '%s' is %s\n",$session->hostname, $result->{$sysUpTime} ); exit 0;