You are here

New to PLugin's - need some Perl help

2 posts / 0 new
Last post
jradin_87686
jradin_87686's picture
New to PLugin's - need some Perl help

Any help would be greatly appreciated. Downloaded a Perl plugin, made the neccasary changes (OID's) and get the following errors:

nagios/libexec/check_room_monitor_digital_temp.pl -H 192.168.1.202 -C 'public'
RETURN CODE: 2 (CRITICAL)
ERROR: /usr/local/nagios/libexec/check_room_monitor_digital_temp.pl: 22: :not found /usr/local/nagios/libexec/check_room_monitor_digital_temp.pl: 23: use: not found /usr/local/nagios/libexec/check_room_monitor_digital_temp.pl: 23: : not found /usr/local/nagios/libexec/check_room_monitor_digital_temp.pl: 24: use: not found /usr/local/nagios/libexec/check_room_monitor_digital_temp.pl: 24: : not found /usr/local/nagios/libexec/check_room_monitor_digital_temp.pl: 25: : not found /usr/local/nagios/libexec/check_room_monitor_digital_temp.pl: 26: Syntax error: "(" unexpected Note: Errors without any output - this will be displayed as '(null)' in status screens

Here is the code:

# /etc/perl
#
# AUTHORS:
#    Copyright (C) 2003-2013 Opsview Limited. All rights reserved
#
#    This file is part of Opsview
#
#    Opsview 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.
#
#    Opsview 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 Opsview; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

use strict;
use warnings;

use FindBin qw($Bin);
use lib "/opt/opsview/perl/lib/perl5", "$Bin/../lib";
use Net::SNMP;
use Opsview::NagiosPlugin::SNMP;

my $np = Opsview::NagiosPlugin::SNMP->new(
    usage     => "Usage: %s",
    shortname => "check_snmp_apc_exttempprove",
    version   => "2.1.1",
    blurb     => "APC UPS external temperature probe reading",
    snmp      => {
        "snmp-version" => 1,
        "snmp-timeout" => 2,
    },
);

$np->add_arg(
    spec => "warning|w=s",
    help => qq{-w, --warning=INTEGER
    Warning threshold (as %)},
    default => 85,
);

$np->add_arg(
    spec => "critical|c=s",
    help => qq{-c, --critical=INTEGER
    Critical threshold (as %)},
    default => 90,
);

$np->getopts;

my $warning  = $np->opts->warning;
my $critical = $np->opts->critical;

my $oid_sysDescr   = ".1.3.6.1.4.1.3854.1";
my $oid_SensorTemp = ".1.3.6.1.4.1.3854.1.2.2.1.16.1.3.0";

my $status       = 0;
my $returnstring = "";

my $s = $np->snmp;

main();

# Close the session
$s->close();

if ( $returnstring eq "" ) {
    $status = 3;
}

if ( $status == 0 ) {
    print "Status is OK - $returnstring\n";

    # print "$returnstring\n";
}
elsif ( $status == 1 ) {
    print "Status is a WARNING level - $returnstring\n";
}
elsif ( $status == 2 ) {
    print "Status is CRITICAL - $returnstring\n";
}
else {
    print "Status is UNKNOWN\n";
}

exit $status;

####################################################################
# This is where we gather data via SNMP and return results         #
####################################################################

sub main {

    my $oid_RequiredSensorTemp = $oid_SensorTemp;
    my $RequiredSensorTemp;
    my $temp;
    if ( !defined( $s->get_request($oid_RequiredSensorTemp) ) ) {
        if ( !defined( $s->get_request($oid_sysDescr) ) ) {
            $returnstring = "SNMP agent not responding";
            $status       = 1;
            return 1;
        }
        else {
            $returnstring = "SNMP OID does not exist";
            $status       = 1;
            return 1;
        }
    }
    foreach ( $s->var_bind_names() ) {
        $RequiredSensorTemp = $s->var_bind_list()->{$_};
    }

    $temp = sprintf "Temperature probe: %.1f C|temperature=%.1f",
      $RequiredSensorTemp, $RequiredSensorTemp;

    append($temp);

    if ( $RequiredSensorTemp >= $warning ) {
        $status = 1;
    }
    if ( $RequiredSensorTemp >= $critical ) {
        $status = 2;
    }
}

####################################################################
# Appends string to existing $returnstring                         #
####################################################################

sub append {
    my $appendstring = $_[0];
    $returnstring = "$returnstring$appendstring";
}

feytullahede
feytullahede's picture
perl interpreter

Hi,

You have to put the perl interpreter path on top of your code as follows (path may change on different os). So your shell knows how to run it.

#!/usr/bin/perl

Or you must explicitly run the perl script with perl interpreter like this.

# perl ./script.pl

Regards,

Feytullah