JSON output to Nagios
Posted: Mon May 07, 2012 12:18 pm
Hello, wondering if anyone might be able to help me out... I'm new to Nagios and received a JSON perl (custom) perl script from a developer... only problem is it doesn't seem to output any useful data to Nagios... I receive "(Service check did not exit properly)" ... I'm not sure that the script is correctly formated for proper output... but very lost
... here's a copy of the code if anyone can take a peek and advise... Thank you...
Code: Select all
#!/usr/bin/perl
use LWP::UserAgent;
use JSON;
use Time::Format qw(%time %strftime %manip);
$e = 0;
$s = 1;
my $start= $time{'yyyy/mm/dd hh:mm:ss', time-$s*60*60};
my $end = $time{'yyyy/mm/dd hh:mm:ss', time-$e*60*60};
my $param = "{\"params\":{\"msg\":\"values\"
,\"id1\":0
,\"id2\":0
,\"size\":100
,\"options\":\"sort-descending\"
,\"fieldName\":\"did\"
,\"where\":\"time=".$start ."-" . $end . "\"}}'";
$urlget = "http://10.1.1.1:12345/sdk?&force-content-type=application/json&expiry=0";
my $ua = LWP::UserAgent->new;
my $json = JSON->new;
my $basic = "10.1.1.1:12345";
$ua->agent('bot1.0');
$ua->credentials($basic,"exampletechnology","username" => "password");
my $request = $ua->post($urlget, Content_Type => "application/json", Content => $param);
$test = $json->decode($request->content);
my $count = 0;
my @urls;
my %balls;
my $state = 0;
foreach (@{$test->{"results"}->{"fields"}})
{
push(@urls, $_->{value});
$count++;
$balls{$_->{group}}->{ $_->{type}} = $_->{value} ;
}
#foreach $line (@urls) {
# print "$line \n";
# }
#print "$count\n";
if ($count == 13) {
print "OK\n";
exit (0);
} else {
print "CRITICAL\n";
exit (2);
}