Problem plugin

Subhendu Ghosh sghosh at sghosh.org
Mon May 5 23:28:10 CEST 2003


Have you tried the supported check_ifoperstatus plugin ?

-sg

On 5 May 2003, kleysonr wrote:

> 
> What the problem in the plugin? In the netsaint the follow plugin working very well, but in the nagios do not work.
> The plugin uses SNMP to find out whether a particular port on a Cisco router is up.
> 
> Check interfaces : snmpwalk <host> <community> .1.3.6.1.2.1.2.2.1.2
> 
> check_ciscoif -H <ip_router> -c public -i Serial1/0.1
> 
> #!/usr/bin/perl -w
> #
> #use strict;
> #use lib $main::runtimedir;
> use vars qw( $host $port $community $oid $interface $session $error $verbose $opt_V $opt_h $response $runtimedit $PROGNAME $exval $result );
> use Getopt::Long;
> use Net::SNMP qw( snmp_event_loop );
> use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
> 
> sub print_help ();
> sub print_usage ();
> 
> $port = '161';
> $oidstr = '1.3.6.1.2.1.2.2.1.2';
> $oid = '1.3.6.1.2.1.2.2.1.8';
> # ifOperStatus: operational status of an interface
> # Values for each interface are:
> #  1 - up
> #  2 - down
> #  3 - testing
> #  4 - unknown
> #  5 - dormant
> #  6 - not present
> #  7 - lower layer down
> 
> $ENV{'PATH'}='';
> $ENV{'BASH_ENV'}='';
> $ENV{'ENV'}='';
> 
> Getopt::Long::Configure('bundling');
> GetOptions
>         ("V"   => $opt_V,     "version"     => $opt_V,
>          "h"   => $opt_h,     "help"        => $opt_h,
>          "v"   => $verbose,   "verbose"     => $verbose,
>          "H=s" => $host,      "host=s"      => $host,
>          "p:i" => $port,      "port:i"      => $port,
>          "i=s" => $interface, "interface=s" => $interface,
>          "c=s" => $community, "community=s" => $community);
> 
> 
> 
> #
> # Parse the standard options.
> #
> 
> if ($opt_V) {
>         print_revision($PROGNAME,' $Revision: 1.1 $ '); #'
>         exit $ERRORS{'OK'};
> }
> 
> 
> if ($opt_h) {
>         print_help();
>         exit $ERRORS{'OK'};
> }
> 
> $host = shift unless ($host);
> 
> if (!defined $host || !defined $interface || !defined $community) {
>     &print_usage();
>     exit 1;
> }
> 
> #
> # Install the signal handler.
> #
> 
> $SIG{ INT } = &handler;
> 
> #
> # Make an SNMP client object.
> #
> 
> print "Connecting to $community@$host:$portn" if ($verbose);
> 
> 
> ( $session, $error ) = Net::SNMP->session(
>                                           -hostname    => shift || $host,
>                                           -community   => shift || $community,
>                                           -port        => shift || $port
>                                           );
> 
> if( ! defined( $session ) ) {
>     print STDERR "Error establishing SNMP connection to $host, abortingn";
>     exit 1;
> }
> 
> #
> # Use it to get the service table.
> #
> 
> # Get INTEGER interface
> print "Requesting $oidstrn" if ($verbose);
> 
> $response = $session->get_table($oidstr);
> 
> EXIT: foreach $key (sort keys %$response) {
>    if($$response{$key} eq $interface) {
>       ($f,$f,$f,$f,$f,$f,$f,$f,$f,$f,$interface) = split(/./,$key);
>       last EXIT;
>    }
> }
> 
> # Get STATUS interface
> 
> $snmpIfOperStatus = $oid . "." . $interface;
> print "Requesting $snmpIfOperStatusn" if ($verbose);
> 
> $result = $session->get_request(
>                     -varbindlist => [$snmpIfOperStatus]
>                     );
> 
> $response = 0;
> $response = $result->{$snmpIfOperStatus};  # Default is CRITICAL: The service isn't listed.
> 
> snmp_event_loop();  # Here it may get softened as we parse the reply.
> 
> # Deal with out-of-bounds answers.
> if (($response < 0) || ($response > ) { $response = 8; }
> 
> # Map SNMP result codes to Netsaint result codes.
> print "INTERFACE "
>     . ("CRITICAL: i/f $interface not listed or no reply",
>        "OK: i/f $interface is UP",
>        "CRITICAL: i/f $interface is DOWN",
>        "WARNING: i/f $interface is TESTING",
>        "CRITICAL: i/f $interface ststus is UNKNOWN",
>        "WARNING: i/f $interface is DORMANT",
>        "CRITICAL: i/f $interface is NOT PRESENT",
>        "CRITICAL: i/f $interface status is 'LOWER LAYER DOWN'",
>        "CRITICAL: i/f $interface listed with undecipherable value",
>        )[$response]
>     . "n";
> $exval = (2,0,2,1,2,1,2,2,2)[$response];
> 
> #print $response;
> exit $exval;
> #exit 0;
> #print "->response: $response  ->exval: $exvaln";
> 
> # Signal handler, probably nearly always triggered by SIGINT.
> 
> sub handler
> {
>     $session->close();
>     die "Received signal SIG".( shift );
> }
> 
> # User-friendliness, such as it is.
> 
> sub print_usage () {
>         print "Usage:
>    $PROGNAME -H hostname [ -p port ] -c community -i interface [--verbose]
>    $PROGNAME --help
>    $PROGNAME --version
> ";
> }
> 
> sub print_help () {
>         print_revision($PROGNAME,'$Revision: 1.1 $ ');
>         print "Copyright (c) 2001 Tim Deegan
> 
> Check NT service list for a particular service, by SNMP
> 
> ";
>         print_usage();
>         print "
> -H --host=HOST
>    Choose host to query
> -p --port=PORT
>    Pick a port number (default is 161)
> -s --interface=INTERFACE
>    Which interface name to check
> -c --community=COMMUNITY
>    SNMP community string
> -v, --verbose
>    Print some extra debugging information (not advised for normal operation)
> -V, --version
>    Show version and license information
> -h, --help
>    Show this help screen
> 
> ";
> 
> support();
> }
> 

-- 




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list