Hilfe bei perl - (nagios - ups)

25/01/2012 - 16:59 von Helmut Harnisch | Report spam
Hallo,
ich habe gar keine Ahnung von perl (bis jetzt).
Ich habe ein Skript für nagios (Serverüberwachung) gefunden, das mir den
Zustand der Notstromversorgung anzeigen soll.

Die meisten Fehler konnte ich schon verbessern (bisher kann ich nur bash
- aber man lernt ja dazu ...)
Allerdings bekomme ich den Fehler betr. Zeile 141
nicht weg.

Kann jemand helfen?


== begin -bash-3.00$ ./check_snmp_mge_ups -H 192.168.1.144 -C public
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_EN"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Global symbol "$W_STATE" requires explicit package name at
./check_snmp_mge_ups line 141.
Execution of ./check_snmp_mge_ups aborted due to compilation errors.

end =
Das perl Skript:

#!/usr/local/bin/perl -w
# Author : Roderick Derks (roderick@r71.nl)
# Written for the St. Elisabeth Hospital in Tilburg, The Netherlands
# Date : februari 5, 2008
# check_snmp_mge_ups
#
# 20080908 - roderick - minor bugs removed
#
# 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.
#
#################################################################

use strict;
use Getopt::Std;
# globale variabelen:
#use vars qw($opt_h $opt_H $opt_C $opt_g);
our($opt_h, $opt_H, $opt_C, $opt_g);



my $PROGNAME = "check_snmp_mge_ups";

my $STATE_CRITICAL = 2;
my $STATE_WARNING = 1;
my $STATE_UNKNOWN = 3;
my $STATE_OK = 0;
my $STATE = $STATE_OK; # used this later on in the script

&getopts("h:H:C:g")||die "ERROR: Unknown option. -help for help";
if ($opt_h) {
&print_usage;
}

sub print_usage {
print "check_snmp_mge_ups -H [ IP|HOSTNAME ] -C SNMPCOMMUNITY";
exit $STATE_UNKNOWN;
}


my $IP = $opt_H;
my $COMMUNITY = $opt_C;

#$warning=$opt_w;
#$critical=$opt_c;

my $warning_backup_time = 600;
my $warning_charge_level = 60;
my $warning_output_load = 80;
my $critical_backup_time = 300; #300
my $critical_charge_level = 70; #40
my $critical_output_load = 90; #40

#my %options=();




# get the values
my $backup_time =`snmpwalk -v 1 -c $COMMUNITY $IP enterprises.705.1.5.1.0`;
my $batt_charge_level =`snmpwalk -v 1 -c $COMMUNITY $IP
enterprises.705.1.5.2.0`;
my $output_load =`snmpwalk -v 1 -c $COMMUNITY $IP
enterprises.705.1.7.2.1.4.1`;

chomp $backup_time;
chomp $batt_charge_level;
chomp $output_load;

#print "$backup_time";
#print "$batt_charge_level";
#print "$output_load";

# FILTER
if ( $backup_time ) {
$backup_time =~s/SNMPv2-SMI::enterprises.705.1.5.1.0 = INTEGER: //g;
}
else {
print "Unknown : No response while querying for the the amount of
backup time left on host $IP";
exit $STATE_UNKNOWN;
}
if ( $batt_charge_level ) {
$batt_charge_level =~s/SNMPv2-SMI::enterprises.705.1.5.2.0 INTEGER: //g;
}
else {
print "Unknown : No response while querying for the percentage of
battery charge level on host $IP";
exit $STATE_UNKNOWN;
}
if ( $output_load ) {
$output_load =~s/SNMPv2-SMI::enterprises.705.1.7.2.1.4.1 = INTEGER:
//g;
}
else {
print "Unknown : No response while querying for the percentage of
output load on host $IP";
exit $STATE_UNKNOWN;
}

#$OUTPUT="backuptime left:${backup_time}seconds - batt charge
level:${batt_charge_level}% - Output
load:${output_load}%|BCKP_TIME=$backup_time
BATT_CHARGE=$batt_charge_level OUTPUT_LOAD=$output_load";

my $REGEX="BCKP_TIME=$backup_time BATT_CHARGE=$batt_charge_level
OUTPUT_LOAD=$output_load";

#if ( $backup_time <= $critical_backup_time or $batt_charge_level <$critical_charge_level or $output_load <= $critical_output_load ) {
# print "Status is CRITICAL. $OUTPUT";
# exit $STATE_CRITICAL;
# }


if ( $backup_time <= $critical_backup_time ) {
my $C_STATE = 2;
$backup_time = "*${backup_time}*";
}
elsif ( $backup_time <= $warning_backup_time ) {
my $W_STATE = 1;
$backup_time = "*${backup_time}*";
}
if ( $batt_charge_level <= $critical_charge_level ) {
my $C_STATE = 2;
$batt_charge_level = "*${batt_charge_level}*";
}
elsif ( $batt_charge_level <= $warning_charge_level ) {
my $W_STATE = 1;
$batt_charge_level = "*${batt_charge_level}*";
}
if ( $output_load >= $critical_output_load ) {
my $C_STATE = 2;
$output_load = "*${output_load}*";
}
elsif ( $output_load >= $warning_output_load ) {
my $W_STATE = 1;
$output_load = "*${output_load}*";
}

#print "STATE $STATE";

my $OUTPUT="backuptime left: ${backup_time} seconds - batt charge level:
${batt_charge_level}% - Output load: ${output_load}%|$REGEX";

if ( $W_STATE == 1 ) {
print "Status is WARNING: $OUTPUT";
exit $STATE_WARNING;
}
if ( my $C_STATE == 2 ) {
print "Status is CRITICAL: $OUTPUT";
exit $STATE_CRITICAL;
}
else {
print "Status is OK. $OUTPUT";
exit $STATE_OK;
}


# = End ==
 

Lesen sie die antworten

#1 Jan Pluntke
25/01/2012 - 18:05 | Warnen spam
"Helmut Harnisch" wrote

ich habe gar keine Ahnung von perl (bis jetzt).
Ich habe ein Skript für nagios (Serverüberwachung) gefunden, das mir den
Zustand der Notstromversorgung anzeigen soll.

Die meisten Fehler konnte ich schon verbessern (bisher kann ich nur bash
- aber man lernt ja dazu ...)
Allerdings bekomme ich den Fehler betr. Zeile 141
nicht weg.

Kann jemand helfen?


== begin > -bash-3.00$ ./check_snmp_mge_ups -H 192.168.1.144 -C public
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_EN"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Global symbol "$W_STATE" requires explicit package name at
./check_snmp_mge_ups line 141.
Execution of ./check_snmp_mge_ups aborted due to compilation errors.

end =>
Das perl Skript:



[...]

if ( $backup_time <= $critical_backup_time ) {
my $C_STATE = 2;
$backup_time = "*${backup_time}*";
}
elsif ( $backup_time <= $warning_backup_time ) {
my $W_STATE = 1;
$backup_time = "*${backup_time}*";
}



my macht $W_STATE (und vorher auch $C_STATE) zu einer lokalen
Variable, die nur innerhalb des umgebenden Blocks existiert.

if ( $W_STATE == 1 ) {
print "Status is WARNING: $OUTPUT";
exit $STATE_WARNING;
}



Hier gibt es die Variable nicht mehr.

Gruß
Jan

Ähnliche fragen