12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- use strict;
- use warnings;
- my $p_script = shift;
- my @p_args = @ARGV;
- if (! $p_script) {
- exit_usage(1);
- }
- my $p_stdout;
- my $p_pid = open($p_stdout, '-|', "$p_script @p_args 2>&1");
- if (! defined($p_pid)) {
- print "CRITICAL: Failed to execute plugin ($p_script): $!\n";
- print "Commandline: $p_script @p_args\n";
- exit 2;
- }
- my @p_output = <$p_stdout>;
- if (waitpid($p_pid, 0) != $p_pid) {
- print "UNKNOWN: Lost track of plugin process\n";
- exit 3;
- }
- my $p_rc = $?;
- my $p_sig = $p_rc & 127;
- my $p_cd = $p_rc & 128;
- $p_rc >>= 8;
- close $p_stdout;
- if ($p_sig || $p_cd) {
- print "CRITICAL: Plugin died with signal $p_sig (exit code: $p_rc)"
- . ($p_cd ? " (core dumped)" : "") . "\n";
- $p_rc = 2;
- }
- if ($p_rc == 255) {
- print "CRITICAL: Plugin died with status 255 "
- . "(see details for more info)\n";
- print "Commandline: $p_script @p_args\n";
- }
- my $p_output = join('', @p_output);
- print $p_output;
- if (($p_rc < 0) || ($p_rc > 3)) {
- $p_rc = 3;
- }
- exit $p_rc;
- sub exit_usage {
- my $status = shift || 0;
- print STDERR "Usage: $0 <plugin> [<args>]\n";
- exit $status;
- }
|