Can someone please give me an example how to submit external command
using perl script. I am trying to do this and its now working. The
command I am passing to named pipe is something like this. Thanks<br>"ACKNOWLEDGE_HOST_PROBLEM;<div id=":y2" class="ArwC7c ckChnd">hostname;1;1;1;1;sr2690;testing<br>
"1233162775<br><br><br>my code is like this.<br><br><br>#!/usr/bin/perl <br>#use strict;<br>#use Getopt::Long qw(:config no_ignore_case);<br>use warnings;<br>use Data::Dumper;<br><br>use Getopt::Long ;<br><br>my ($action, $host, $service, $username, $comment, $HELP);<br>
my $now=`date +%s`;<br>chomp ( $now );<br>my $commandfile='/var/log/nagios/rw/nagios.cmd';<br><br>open CF, ">$commandfile" or die $!;<br><br>my $usage = <<EOF;<br> usage: $0 -a action -H host -s service -u username -c commnent <br>
<br>Options:<br> -a --action<br> -m, --host=STRING<br> Host name or IP Address<br> -s, --service=STRING<br> Service Name <br> -u, --username=STRING<br> The user to authenticate<br> -c, --comment=STRING<br> Comment here<br>
-h, --help<br> Print detailed help screen<br>EOF<br><br># handle cmdline args<br>GetOptions( "a|action=s" => \$action,<br> "m|host=s" => \$host,<br> "s|service=s" => \$service,<br>
"u|username=s" => \$username,<br> "c|comment=s" => \$comment,<br> "h|help" => \$HELP<br> );<br>#print "$usage" if ($HELP && $action eq '');<br>
if ( $HELP && ( ! ( defined ( $action) ) ) ) {<br>print "$usage";<br>}<br>&process_command();<br><br>sub process_command {<br> #if (( $action eq 'status') || ( $action eq 'check') || ( $action eq 'reschedule') <br>
# || ( $action eq 'acknowledge') || ( $action eq 'ack') || ($action eq 'dis_check') <br> # || ($action eq 'ena_check') || ($action eq 'dis_not') || ($action eq 'ena_not')) { <br>
<br> if ( $action eq 'acknowledge' ) {<br> process_acknowledge ();<br> }<br> elsif ( $action eq 'reschedule' ) {<br> process_reschedule ();<br> }<br> else {<br>print
" Only possible actions are status check reschedule acknowledge
disable_check enable_check disable_notification and
enable_notification\n";<br>
}<br>}<br><br>sub process_acknowledge { <br> if ( defined ( $service ) ) {<br> send_to_named_pipe ( "ACKNOWLEDGE_SVC_PROBLEM;$host;$service;1;1;1;$username;$comment" );<br> }<br> else {<br> send_to_named_pipe ( "ACKNOWLEDGE_HOST_PROBLEM;$host;1;1;1;1;$username;$comment" );<br>
}<br>}<br><br>sub process_reschedule {<br> if ( defined ( $service ) ) {<br> send_to_named_pipe ( "SCHEDULE_FORCED_SVC_CHECK;host1;service1;1110741500" );<br> }<br> else {<br> send_to_named_pipe ( "SCHEDULE_FORCED_HOST_CHECK;$host;1110741500\n" );<br>
}<br>}<br>sub send_to_named_pipe {<br> my ($command ) = @_;<br> chomp ( $command );<br><br> if ( defined ( $command ) ) {<br> print CF "\"$command\n\"$now";<br><br><br> }<br><br>} <br>close CF;</div>
<br clear="all"><br>-- <br>Cordially,<br>Shadhin Rahman<br>