8 getopts
('hr:C:c:s:o:', \
%opts);
11 my $STATE_WARNING = 1;
12 my $STATE_CRITICAL = 2;
13 my $STATE_UNKNOWN = 3;
15 if ($opts{'h'} || scalar(%opts) == 0) {
20 my $command = $opts{'c'};
22 print "You must provide a command to check.\n";
26 my $expected_output = $opts{'o'};
27 my $expected_status = $opts{'s'};
28 my $other_command = $opts{'C'};
30 if ($other_command eq '' and $expected_status eq '' and $expected_output eq '') {
34 my $cmd = $command . ' 2>&1';
36 if ($other_command ne '') {
37 $other_cmd = $other_command . ' 2>&1';
43 $cmd = "sudo -u $run_as -n $cmd";
45 if ($other_command ne '') {
46 $other_cmd = "sudo -u $run_as -n $other_cmd";
51 my $cmd_result = `$cmd`;
53 if ($other_command ne '') {
54 $other_cmd_result = `$other_cmd`;
55 chomp($other_cmd_result);
59 if ($cmd_result =~ /sudo/i) {
60 print "$command CRITICAL - No sudo right to run the command | result=1;;;;\n";
62 } elsif ($expected_status ne '') {
63 if ($? != $expected_status) {
64 print "$command CRITICAL - Response status $? | result=1;;;;\n";
65 exit($STATE_CRITICAL);
67 print "$command OK - Response status $? | result=0;;;;\n";
70 } elsif ($other_command ne '') {
71 if ($cmd_result ne $other_cmd_result) {
72 print "$command CRITICAL - Expected output not matching other command output | result=1;;;;\n";
73 exit($STATE_CRITICAL);
75 print "$command OK - Expected output matching other command output | result=0;;;;\n";
79 if ($cmd_result !~ /$expected_output/) {
80 print "$command CRITICAL - Expected output not matching | result=1;;;;\n";
81 exit($STATE_CRITICAL);
83 print "$command OK - Expected output matching | result=0;;;;\n";
90 Check whether the
given command responds as expected
. One of
-o
-C
or -s must be selected
.
94 Print detailed help screen
97 command to run
(required
)
100 other command to compare output
103 Run as user via sudo
.