cesargarza has asked for the wisdom of the Perl Monks concerning the following question:

Hey PerlMonks I am not sure is this the right place to ask this question ? if not, please guide me. My problem, i have a perl script running in the Linux box to get the XML from Activemq server.it seems like there is a problem with GET element in the script. Anyone can help me please ? I am not familiar with Perl at all. I am able to get the result through URL - example (http://10.10.10.10:8161/admin/xml/queues.jsp) ---------------------------------------
#!/usr/bin/perl -w # Nagios plugin to check the current messages waiting in the ActiveMQ +queue. # Author: Maxim Janssens # Company: Synquad BV # Website: http://www.synquad.nl # Email: maxim@synquad.nl use strict; use Switch; use LWP::Simple; my $address = "localhost"; my $port = "8161"; my $page = get "http://$address:$port/admin/xml/queues.jsp" or die "Ca +nnot get XML file: $!\n";; my (%args, %queues); my %error=('ok'=>0,'warning'=>1,'critical'=>2,'unknown'=>3); my ($warninglevel, $criticallevel, $tmp, $evalcount, $switch, $queuese +lect, $queuevalue); my $key = my $value = my $i = my $k = 0; my $exitcode = "unknown"; for(my $m = 0; $m <= $#ARGV; $m++){ if($ARGV[$m] =~ /^\-/){ if($ARGV[$m] eq "-w"||"-c"||"-q"){ $switch = $ARGV[$m]; $args{$switch} = (); if($switch eq "-q"){ $k = 1; } } else { &help; } } else { if($switch eq "-q"){ $args{$switch} = $ARGV[$m]; } elsif($ARGV[$m] =~ /[0-9]{1,5}/){ $args{$switch} = $ARGV[$m]; } else { &help; } } } # main(); $warninglevel = $args{"-w"}; $criticallevel = $args{"-c"}; if($k == 1) { $queueselect = $args{"-q"}; } &getinfo; if($k == 1){ foreach my $str (keys %queues){ if($queueselect eq $str){ $queuevalue = $queues{$queueselect}; + last; } else { next; } } if($queuevalue eq ''){ $exitcode = "unknown"; exit $error{"$exitco +de"};} else { &checkstatus($queuevalue,$queueselect); } } else { while(($key, $value) = each(%queues)){ &checkstatus($value,$key); +} } # Subroutines sub getinfo { my @lines = split ' ', $page; foreach my $line (@lines){ if($line =~ /name/i || $line =~ /size/i){ $line =~ s/^name="//g; $line =~ s/^size="//g; $line =~ s/"(>)?$//g; if($i == 1){ $queues{$tmp} = $line; $i = 0; } else{ $tmp = $line; $i++; } } } } sub checkstatus { my $val=shift; my $key=shift; switch($val){ case { $val <= $warninglevel } { print "OK +- $key holding: $val msgs "; $exitcode = "ok" } case { $val > $warninglevel && $val <= $criticallevel } + { print "WARNING - $key holding: $val msgs "; $exitcode = "warning" +} case { $val > $criticallevel } { print "CRI +TICAL - $key holding: $val msgs "; $exitcode = "critical" } else { &help; } } } sub help { print "Usage: activemq_watch -w <warninglevel> -c <criticallevel> +(-p <queue>)\n"; $exitcode = "unknown"; exit $error{"$exitcode"}; } exit $error{"$exitcode"};
----------------------------------------------- If anyone get difficulty to read the script so i put the web link from where i get the script http://exchange.nagios.org/directory/Plugins/Java-Applications-and-Servers/ActiveMQ_Watch/details thanks

Replies are listed 'Best First'.
Re: Error in the script
by marinersk (Priest) on Sep 12, 2013 at 16:28 UTC
    1. Please use <p> and <br> tags to break up your paragraphs and lines better and please use <code> and </clode> tags to make your code easier to read. You will probably find you get more and better answers if you have mercy on us old folks, not to mention the young folks also.
      Nicely done, thank you!
    2. I suspect you might be doing your get earlier thank you think.
      Please consider doing a print "\$page = '$page'\n"; right after the my $page = get line.
      Maybe that will help us see what's happening.

      Nicely done, thank you!

      Now you :)