check_exec.pl
changeset 2 ded3b78c61b1
parent 1 9b0a5c2b7ebc
child 3 211e08d0d2b8
equal deleted inserted replaced
1:9b0a5c2b7ebc 2:ded3b78c61b1
    64         exit $ERRORS{CRITICAL};
    64         exit $ERRORS{CRITICAL};
    65     };
    65     };
    66 
    66 
    67     my @cmd = ($run_file);
    67     my @cmd = ($run_file);
    68 
    68 
    69     open(OUTPUT, "-|") or do {
    69 	exec(@cmd) or print "EXEC CRITICAL: Couldn't exec $run_file ($!)";
    70         open(STDERR, ">&STDOUT");
       
    71         system(@cmd);
       
    72     };
       
    73 
       
    74     my $result = <OUTPUT>;
       
    75 
       
    76     close(OUTPUT);
       
    77 
       
    78     if ($? == -1) {
       
    79         print "EXEC CRITICAL: Failed to execute: $!\n";
       
    80         cleanup($run_file);
       
    81         exit $ERRORS{CRITICAL};
       
    82     }
       
    83     elsif ($? & 127) {
       
    84         printf "EXEC CRITICAL: Child died with signal %d, %s coredump\n",
       
    85           ($? & 127), ($? & 128) ? 'with' : 'without';
       
    86         cleanup($run_file);
       
    87         exit $ERRORS{CRITICAL};
       
    88     }
       
    89     else {
       
    90         my $rc = $? >> 8;
       
    91         if ($rc == $ERRORS{OK}) {
       
    92             print "EXEC OK: $result";
       
    93             cleanup($run_file);
       
    94             exit $ERRORS{OK};
       
    95         }
       
    96         elsif ($rc == $ERRORS{WARNING}) {
       
    97             print "EXEC WARNING: $result";
       
    98             cleanup($run_file);
       
    99             exit $ERRORS{WARNING};
       
   100         }
       
   101         elsif ($rc == $ERRORS{CRITICAL}) {
       
   102             print "EXEC CRITICAL: $result";
       
   103             cleanup($run_file);
       
   104             exit $ERRORS{CRITICAL};
       
   105         }
       
   106         elsif ($rc == $ERRORS{UNKNOWN}) {
       
   107             print "EXEC UNKNOWN: $result";
       
   108             cleanup($run_file);
       
   109             exit $ERRORS{UNKNOWN};
       
   110         }
       
   111         elsif ($rc == $ERRORS{DEPENDENT}) {
       
   112             print "EXEC DEPENDENT: $result";
       
   113             cleanup($run_file);
       
   114             exit $ERRORS{DEPENDENT};
       
   115         }
       
   116     }
       
   117 }
    70 }
   118 
    71 
   119 sub cleanup($) {
    72 sub cleanup($) {
   120     my $file = shift;
    73     my $file = shift;
   121 
    74