Dear All,

I have developed a small plugin for NagiOS ( Infrastructure monitoring tool ) which reports number of VMs running in the Machine.

#!/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;
When I execute this code. I am getting correct output, but with couple of warnings.
[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
Can anyone Please help me to get rid of these warnings. Thanks in advance

In reply to Getting error while developing a simple NagiOS plugin by tpvinay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.