#!/usr/bin/perl #use strict; use SNMP; use Getopt::Long; # Nagios specific #use lib "/opt/nagios/libexec"; #use utils qw(%ERRORS $TIMEOUT); # prototype sub checkInterfaces($$$$$$); $host="cisco-router"; $community = $o_community || "pubic"; $version = $o_version || "1"; $timeout = $o_timeout || "10000000"; $retries = $o_retries || "10"; # create session ($session, $error) = new SNMP::Session(    DestHost => $host,    Community => $community,    Version => $version,    Timeout => $timeout,    Retries => $retries); # if session does not exist ... exit if (!defined($session)) {    print "ERROR opening session\n";    exit $ERRORS{"UNKNOWN"}; }    # get Number of Interfaces on this Host    $ifcount = $session->get(["ifNumber",0]);    # get sysDescr field and check if device is a 375x l3-switch    #my $sysdescr = $session->get(["sysDescr",0]);    $num_o_errors = checkInterfaces(0, $ifcount, $session, $version, \@longerr, $host); sub checkInterfaces($$$$$$) {    my($index, $ifcount, $border, $version, $session, $host, $longerr, $not_to_search);    $index = $_[0];    $ifcount = $_[1];    $session= $_[2];    $version = $_[3];    $longerr = $_[4];    $host = $_[5];    my %admin_states = ((my $admin_state_ok=1)=>"adminUp",                        2=>"adminDown",                        3=>"adminTest");    my %oper_states = ((my $oper_state_ok=1)=>"up",                       2=>"down",                       3=>"testing",                       4=>"unknown",                       5=>"sleeping");    my $counter = 0;       my $if_state = new SNMP::VarList(                                  ["ifDescr"],                                  ["ifAdminStatus"],                                  ["ifOperStatus"],                                  ["ifAlias"],  # .1.3.6.1.2.1.31.1.1.1.18                                  ["ifName"]); # .1.3.6.1.2.1.31.1.1.1.1        my $desc;        my $desc2 = undef;        do {            my ($name,$admin,$oper,$desc1,$short) = $session->getnext($if_state);            $index++;            $desc = $desc1?$desc1:$desc2?$desc2:"N/A";            $short = $name if (!$short);            if ($session->{ErrorNum}) {                next if ($session->{ErrorNum}==2);                $counter++;                push @$longerr, "$host no session: $session->{ErrorStr}";                #last;            }            print "Name: $name, Admin-State: $admin, Oper-State: $oper, Desc: $desc, Shotname: $short\n";        } while ($index <= $ifcount-1); # -1 to get rid of last...unused...element    return $counter; }