I don't think $line will every be empty - you probably ought to chomp it, or test for non-whitespace.
And you still have unnecessary tests in your if-elsif. For example, if $score is NOT greater-than $warnrate, it IS NECESSARILY less-than-or-equal-to $warnrate.
Consider:
use strict;
my $radio = $ARGV[0];
my $warnrate = $ARGV[1];
my $critrate = $ARGV[2];
chomp(my $line = `/usr/bin/snmpwalk -v1 -c PTsnmp $radio .1.3.6.1.4.1.
+5454.1.40.2.4.0`;
if ($line !~ /\S/) {
print "snmpwalk returned nothing, timeout likely occurred.\n";
exit 3;
} elsif ($critrate > $warnrate) {
print "Make sure your critical value is less than or equal to your
+warning value.\n";
exit 5;
} else {
my $score = (split(' ', $line))[3];
my ($msg,$status) = $score > $warnrate ? ('OK',0)
: ( $score > $critrate ? ('WARNING',1)
: ('CRITICAL',2));
print "$msg, rf is $score. |Mbps=$score\n";
exit $status;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|