From 45d107edc15c7ab86814f827f2843ef31d41457d Mon Sep 17 00:00:00 2001 From: Christopher Kreft Date: Sun, 28 Apr 2013 20:07:31 +0200 Subject: [PATCH] now exit critical on connection error --- check_json.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/check_json.pl b/check_json.pl index c447274..c5d6c43 100755 --- a/check_json.pl +++ b/check_json.pl @@ -57,13 +57,17 @@ $ua->protocols_allowed( [ 'http', 'https'] ); $ua->parse_head(0); $ua->timeout($np->opts->timeout); -my $response = $ua->get($np->opts->URL); +my $response = ($ua->get($np->opts->URL)); -if ($response->header("content-type") ne 'application/json') { - $np->nagios_exit(UNKNOWN,"Content type is not JSON: ".$response->header("content-type")); +if ($response->is_success) { + if ($response->header("content-type") ne 'application/json') { + $np->nagios_exit(UNKNOWN,"Content type is not JSON: ".$response->header("content-type")); + } +} else { + $np->nagios_exit(CRITICAL, "Connection failed: ".$response->status_line); } -my $json_response = decode_json($response->content) ; #NAG-EXIT; +my $json_response = decode_json($response->content); if ($np->opts->verbose) { (print Dumper ($json_response))}; my $value;