Find the answer to your Linux question:
Results 1 to 2 of 2
Hey, Not sure if anyone around here uses nagios, but I'm having a very strange problem that I'm looking for any and all suggestions on. Basically, the issue that I'm ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    2

    Nagios monitor problem


    Hey,

    Not sure if anyone around here uses nagios, but I'm having a very strange problem that I'm looking for any and all suggestions on.

    Basically, the issue that I'm having is that I have a couple of temperature plugins that are reporting errors in Nagios and at the command line they're exiting in 0:

    check7204temp.pl - Return code of 255 is out of bounds
    and
    checkciscotemp.pl - Return code of 9 is out of bounds

    If I run a "echo $?" at the command line after running the command successfully, I get 0.

    Thanks for any help anyone can provide!! My perms are 755 and nagios user owns the plugins and I've run successfully with nagios user and got 0 output. I'm really stumped!!

    Here's the code for the plugins:

    *******************************************
    check7204temp.pl:

    #!/usr/bin/perl -w

    # check_ciscotemp.pl

    #

    # Copyright (C) 2000 Leland E. Vandervort # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version.

    #

    # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details.

    #

    # you should have received a copy of the GNU General Public License # along with this program (or with Nagios); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA ####################################

    # Nagios pluging to check inlet and outlet temperatures on # Cisco router platforms which support environmental monitoring # (7200, 7500, GSR12000...) ####################################

    # default temperature thresholds are 30C for inlet, 40C outlet.

    # if input or output is less than thresholds, returns OK # if equal to (the temps don't change that rapidly) returns WARNING # if greater than threshold, returns CRITICAL # if undetermined, or cannot access environmental, returns UNKNOWN # (in accordance with the plugin coding guidelines) ####################################

    use Net::SNMP;

    use Getopt::Long;

    #use strict;

    &Getopt::Long::config('auto_abbrev');

    #my $critical_vals;

    #my $warning_vals;

    #my $inlet_warn;

    #my $outlet_warn;

    #my $status;

    my $response = "";

    my $timeout = 10;

    my $community = "blah";

    my $port = 161;

    my $INTAKE_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.1"; my $OUTLET_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.3"; my $in_temp; my $out_temp; my $inlet_thresh = 30; my $outlet_thresh = 34; my $hostnm; #my $OID; #my $session; #my $state; #my $error;

    my %STATUSCODE = ( 'UNKNOWN' => '-1',

    'OK' => '0',

    'WARNING' => '1',

    'CRITICAL' => '2');

    my $state = "UNKNOWN";

     

    $SIG{'ALRM'} = sub {

    print "ERROR: No snmp response from $hostnm (sigALRM)\n";

    exit($STATUSCODE{"UNKNOWN"});

    };

    Getopt::Long::Configure('bundling');

    $status = GetOptions

    ("community=s", \$community,

    "C=s", \$community,

    "H=s", \$hostnm,

    "hostname=s", \$hostnm,

    "port=i", \$port,

    "timeout=i", \$timeout,

    "c=s", \$critical_vals,

    "w=s", \$warning_vals,

    "ithresh=i", \$inlet_thresh,

    "othresh=i", \$outlet_thresh);


    if($status == 0) {

    &show_help;

    }

    unless (defined($hostnm)) {

    $hostnm = shift || &show_help;

    }

    if (defined($critical_vals)) {

    if ($critical_vals =~ m/^([0-9]+)[,:]([0-9]+)$/) {

    ($inlet_thresh,$outlet_thresh) = ($1, $2);

    } else {

    die "Cannot Parse Critical Thresholds\n";

    }

    }

    if (defined($warning_vals)) {

    if ($warning_vals =~ m/^([0-9]+)[:,]([0-9]+)$/) {

    ($inlet_warn,$outlet_warn) = ($1, $2);

    } else {

    die "Cannot Parse Warning Thresholds\n";

    }

    }else{

    $inlet_warn=$inlet_thresh;

    $outlet_warn=$outlet_thresh;

    }

    alarm($timeout);

    $in_temp = &SNMPGET($INTAKE_TEMP);

    $out_temp = &SNMPGET($OUTLET_TEMP);

    if (($in_temp < $inlet_thresh) && ($out_temp < $outlet_thresh)) {

    $state = "OK";

    }

    elsif (($in_temp == $inlet_thresh) || ($out_temp == $outlet_thresh)) {

    if(($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {

    $state = "CRITICAL";

    }

    else {

    $state = "WARNING";

    }

    }

    elsif (($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {

    $state = "CRITICAL";

    }

    else {

    $state = "WARNING";

    }

    print "$state Inlet Temp: $in_temp Outlet Temp: $out_temp\n"; exit($STATUSCODE{$state});

    sub show_help {

    printf("\nPerl envmon temperature plugin for Nagios\n");

    printf("Usage:\n");

    printf("

    check_ciscotemp [options] <hostname>

    Options:

    -C snmp-community

    -p snmp-port

    -i input temperature threshold

    -o output temperature threshold

    ");

    printf("Copyright (C)2000 Leland E. Vandervort\n");

    printf("check_ciscotemp comes with absolutely NO WARRANTY either implied or explicit\n");

    printf("This program is licensed under the terms of the\n");

    printf("GNU General Public License\n(check source code for details)\n\n\n");

    exit($STATUSCODE{"UNKNOWN"});

    }

    sub SNMPGET {

    $OID = shift;

    ($session,$error) = Net::SNMP->session(

    Hostname => $hostnm,

    Community => $community,

    Port => $port

    );

    if(!defined($session)) {

    printf("$state %s\n", $error);

    exit($STATUSCODE{$state});

    }

    if(!defined($response = $session->get_request($OID))) {

    printf("$state %s\n", $session->error());

    $session->close();

    exit($STATUSCODE{$state});

    }

    $session->close();

    return($response->{$OID});

    }

    ************************************************** *****
    code for checkciscotemp.pl 

    #!/usr/bin/perl -w

    # check_ciscotemp.pl

    #

    # Copyright (C) 2000 Leland E. Vandervort # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version.

    #

    # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details.

    #

    # you should have received a copy of the GNU General Public License # along with this program (or with Nagios); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA ####################################

    # Nagios pluging to check inlet and outlet temperatures on # Cisco router platforms which support environmental monitoring # (7200, 7500, GSR12000...) ####################################

    # default temperature thresholds are 30C for inlet, 40C outlet.

    # if input or output is less than thresholds, returns OK # if equal to (the temps don't change that rapidly) returns WARNING # if greater than threshold, returns CRITICAL # if undetermined, or cannot access environmental, returns UNKNOWN # (in accordance with the plugin coding guidelines) ####################################

    use Net::SNMP;

    use Getopt::Long;

    #use strict;

    &Getopt::Long::config('auto_abbrev');

    #my $critical_vals;

    #my $warning_vals;

    #my $inlet_warn;

    #my $outlet_warn;

    #my $status;

    my $response = "";

    my $timeout = 10;

    my $community = "blah";

    my $port = 161;

    my $INTAKE_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.1"; my $OUTLET_TEMP = "1.3.6.1.4.1.9.9.13.1.3.1.3.3"; my $in_temp; my $out_temp; my $inlet_thresh = 22; my $outlet_thresh = 32; my $hostnm; #my $OID; #my $session; #my $state; #my $error;

    my %STATUSCODE = ( 'UNKNOWN' => '-1',

    'OK' => '0',

    'WARNING' => '1',

    'CRITICAL' => '2');

    my $state = "UNKNOWN";

     

    $SIG{'ALRM'} = sub {

    print "ERROR: No snmp response from $hostnm (sigALRM)\n";

    exit($STATUSCODE{"UNKNOWN"});

    };

    Getopt::Long::Configure('bundling');

    $status = GetOptions

    ("community=s", \$community,

    "C=s", \$community,

    "H=s", \$hostnm,

    "hostname=s", \$hostnm,

    "port=i", \$port,

    "timeout=i", \$timeout,

    "c=s", \$critical_vals,

    "w=s", \$warning_vals,

    "ithresh=i", \$inlet_thresh,

    "othresh=i", \$outlet_thresh);


    if($status == 0) {

    &show_help;

    }

    unless (defined($hostnm)) {

    $hostnm = shift || &show_help;

    }

    if (defined($critical_vals)) {

    if ($critical_vals =~ m/^([0-9]+)[,:]([0-9]+)$/) {

    ($inlet_thresh,$outlet_thresh) = ($1, $2);

    } else {

    die "Cannot Parse Critical Thresholds\n";

    }

    }

    if (defined($warning_vals)) {

    if ($warning_vals =~ m/^([0-9]+)[:,]([0-9]+)$/) {

    ($inlet_warn,$outlet_warn) = ($1, $2);

    } else {

    die "Cannot Parse Warning Thresholds\n";

    }

    }else{

    $inlet_warn=$inlet_thresh;

    $outlet_warn=$outlet_thresh;

    }

    alarm($timeout);

    $in_temp = &SNMPGET($INTAKE_TEMP);

    $out_temp = &SNMPGET($OUTLET_TEMP);

    if (($in_temp < $inlet_thresh) && ($out_temp < $outlet_thresh)) {

    $state = "OK";

    }

    elsif (($in_temp == $inlet_thresh) || ($out_temp == $outlet_thresh)) {

    if(($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {

    $state = "CRITICAL";

    }

    else {

    $state = "WARNING";

    }

    }

    elsif (($in_temp > $inlet_thresh) || ($out_temp > $outlet_thresh)) {

    $state = "CRITICAL";

    }

    else {

    $state = "WARNING";

    }

    print "$state Inlet Temp: $in_temp Outlet Temp: $out_temp\n"; exit($STATUSCODE{$state});

    sub show_help {

    printf("\nPerl envmon temperature plugin for Nagios\n");

    printf("Usage:\n");

    printf("

    check_ciscotemp [options] <hostname>

    Options:

    -C snmp-community

    -p snmp-port

    -i input temperature threshold

    -o output temperature threshold

    ");

    printf("Copyright (C)2000 Leland E. Vandervort\n");

    printf("check_ciscotemp comes with absolutely NO WARRANTY either implied or explicit\n");

    printf("This program is licensed under the terms of the\n");

    printf("GNU General Public License\n(check source code for details)\n\n\n");

    exit($STATUSCODE{"UNKNOWN"});

    }

    sub SNMPGET {

    $OID = shift;

    ($session,$error) = Net::SNMP->session(

    Hostname => $hostnm,

    Community => $community,

    Port => $port

    );

    if(!defined($session)) {

    printf("$state %s\n", $error);

    exit($STATUSCODE{$state});

    }

    if(!defined($response = $session->get_request($OID))) {

    printf("$state %s\n", $session->error());

    $session->close();

    exit($STATUSCODE{$state});

    }

    $session->close();

    return($response->{$OID});

    }

    *********************************************

    Thanks,

    missimo79

  2. #2
    Just Joined!
    Join Date
    Aug 2010
    Location
    Italy
    Posts
    35
    Hello, from my experience when the plguin work from the command line and not in Nagios it means there is some environment problem.
    The user that run nagios is the same of the command line ?
    Perhaps he miss some path ?

    Try to check these things making maybe the plugin more verbose with some echo "your variables" > /tmp/plugindebug

    Good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •