Re: [Nagios-devel] perl external command example

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

Re: [Nagios-devel] perl external command example

Post by Guest »

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

shadih rahman wrote:
> 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
> "ACKNOWLEDGE_HOST_PROBLEM;
> hostname;1;1;1;1;sr2690;testing
> "1233162775
>
>
> my code is like this.
>
>
> #!/usr/bin/perl
> #use strict;
> #use Getopt::Long qw(:config no_ignore_case);
> use warnings;
> use Data::Dumper;
>
> use Getopt::Long ;
>
> my ($action, $host, $service, $username, $comment, $HELP);
> my $now=`date +%s`;
> chomp ( $now );

# Easier/portable (you could also call time() directly in the printf
below instead of using a variable):

my $time = time()

> my $commandfile='/var/log/nagios/rw/nagios.cmd';
>
> open CF, ">$commandfile" or die $!;

I'd suggest opening the pipe only when you want to write to it, or at
least after parsing the arguments. Ex. you could open and close it in
the send_to_named_pipe function.

>
> [...]
>
> sub send_to_named_pipe {
> my ($command ) = @_;
> chomp ( $command );
>
> if ( defined ( $command ) ) {
> print CF "\"$command\n\"$now";

# I guess you meant something like this:
printf CF "[%i] %s\n", $now, $command;

>
> [...]
>

Anyhow, if you're still stuck try outputing to a standard file, then
compare the lines you get with known working commands.


- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJgKpc6dZ+Kt5BchYRAq2eAJ9L+1+ssz+ntkmGFRY/mrbD2XLdQgCgpZGl
qCsSxMrK30Kg6ydRqDwGefQ=
=eRMt
-----END PGP SIGNATURE-----





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked