I have developed a small plugin for NagiOS ( Infrastructure monitoring tool ) which reports number of VMs running in the Machine.
When I execute this code. I am getting correct output, but with couple of warnings.#!/usr/bin/perl -w use strict; use Array::LineReader; use Getopt::Long; use vars qw($opt_w $opt_c $opt_h $opt_v); my(%ERRORS) = ( OK=>0, WARNING=>1, CRITICAL=>2, UNKNOWN=>3 ); my $VERSION = "1.1"; my $opt_w ; my $opt_c ; my $opt_v ; my $offcount =0; my $oncount =0; my $pausecount =0; my $linescount; my $pass = "gundannas"; my $message; my @array = (); my $i; my $status; #--------------------------------------------------------------------- +--------------------------------------------------------------------- +--- sub print_help () { printf "$0 plugin for Nagios check for count of Virtual Machines R +unning on a Host OS\n"; printf "help:\n"; printf " -w (--warn) Warning-Level, Default: 0\n"; printf " -c (--crit) Criticle-Level, Default: 2\n"; printf " -v Version\n"; printf " -h (--help) Help\n"; printf "\n"; print_usage(); } #--------------------------------------------------------------------- +--------------------------------------------------------------------- +--- sub print_usage () { print "Usage: $0 \n"; print " $0 -w 2 -c 0 \n"; print " $0 -w 3 -c 1 \n"; } #--------------------------------------------------------------------- +--------------------------------------------------------------------- +--- if ( @ARGV == 0 ) { print_help(); exit(0); } Getopt::Long::Configure('bundling'); GetOptions ("v" => \$opt_v, "version" => \$opt_v, "h" => \$opt_h, "help" => \$opt_h, "w:i" => \$opt_w, "warn" => \$opt_w, "c:i" => \$opt_c, "crit" => \$opt_c); if ( !$opt_w){$opt_w=2;} #Warning at just one running VM if ( !$opt_c){$opt_c=1;} #Set Critical at No running VMs if ($opt_v) { print "$0: $VERSION\n" ; exit $ERRORS{'OK'}; } if ($opt_h) { print_help(); exit $ERRORS{'OK'}; } @array = `echo $pass | sudo -S virsh list --all`; print @array; $linescount = scalar(@array); for ( $i = 2; $i <= $linescount; $i++ ) { if ( $array[$i] =~ m/shut off/i ) { $offcount = $offcount + 1 ; } elsif ( $array[$i] =~ m/running/i ) { $oncount = $oncount + 1 ; } elsif ( $array[$i] =~ m/paused/i ) { $pausecount = $pausecount + 1 ; } } if ( $oncount <= $opt_c ) { $status = $ERRORS{'CRITICAL'}; $message = " $oncount VMs Running" } elsif ( $oncount <= $opt_w ) { $status = $ERRORS{'WARNING'}; $message = "$oncount VMs Running" } else { $status = $ERRORS{'OK'}; $message = "$oncount VMs Running" } if( $message ) { if( $status == $ERRORS{OK} ) { print "OK: "; } elsif( $status == $ERRORS{WARNING} ) { print "WARNING: "; } elsif( $status == $ERRORS{CRITICAL} ) { print "CRITICAL: "; } print "$message\n"; } else { $status = $ERRORS{UNKNOWN}; print "No Data yet\n"; } exit $status;
Can anyone Please help me to get rid of these warnings. Thanks in advance[root@vinay plugins]# ./check_vms -w 2 -c 0 Id Name State ---------------------------------- - centos shut off - Fedora11 shut off - Fedora9 shut off Use of uninitialized value within @array in pattern match (m//) at ./c +heck_vms line 73. Use of uninitialized value within @array in pattern match (m//) at ./c +heck_vms line 73. Use of uninitialized value within @array in pattern match (m//) at ./c +heck_vms line 73. CRITICAL: 0 VMs Running
In reply to Getting error while developing a simple NagiOS plugin by tpvinay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |