Skip to content

Commit

Permalink
Better organize execution flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Buchalter committed Jan 18, 2013
1 parent 273d2a9 commit c8382ea
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions check_json.pl
Expand Up @@ -52,50 +52,50 @@
eval {

$json_response = decode_json($response->content);
print "JSON repsonse decoded successfully."
print "JSON repsonse decoded successfully.";

} or do {
print "Unable to decode JSON, invalid response?";
exit EXIT_CRITICAL;
};
$status = EXIT_OK;

$status = EXIT_OK;
if ($opts{d}) {

if ($opts{d}) {
if ( -e $opts{d}) {

if ( -e $opts{d}) {
my $hash_import = do $opts{d};

my %attr_check = %{$hash_import};

my $hash_import = do $opts{d};

my %attr_check = %{$hash_import};
my @errors;

my @errors;
for my $key (sort keys %attr_check) {
for my $attr (sort keys %{$attr_check{$key}}) {
my $have = $json_response->{products}{$key}{now}{$attr};
my $expect = $attr_check{$key}{$attr};
push @errors, "For key $key, attribute $attr, expected '$expect', but got '$have'"
unless $have eq $expect;
}
}

for my $key (sort keys %attr_check) {
for my $attr (sort keys %{$attr_check{$key}}) {
my $have = $json_response->{products}{$key}{now}{$attr};
my $expect = $attr_check{$key}{$attr};
push @errors, "For key $key, attribute $attr, expected '$expect', but got '$have'"
unless $have eq $expect;
}
}

if (@errors) {
print "Errors:\n", map { "$_\n" } @errors;
$status = EXIT_CRITICAL;
if (@errors) {
print "Errors:\n", map { "$_\n" } @errors;
$status = EXIT_CRITICAL;
}
else {
print "Found expected content.";
$status = EXIT_OK;
}
}
else {
print "Found expected content.";
$status = EXIT_OK;
}
}
else {
print "Unable to find data file $opts{d}";
$status = EXIT_UNKNOWN;
print "Unable to find data file $opts{d}";
$status = EXIT_UNKNOWN;
}
}
}

exit $status;
exit $status;

} or do {
print "Unable to decode JSON, invalid response?";
exit EXIT_CRITICAL;
};

sub HELP_MESSAGE
{
Expand Down

0 comments on commit c8382ea

Please sign in to comment.