Nagios alert in perl: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
(Created page with "you could use the perl module, or you can just write to the cmd file. <pre> sub alert ( $$$$ ) { my ($host, $test, $code , $message); ($host, $test, $code , $message)...")
 
No edit summary
Line 15: Line 15:
}
}
</pre>
</pre>
[[Category:Perl]]
[[Category:Nagios]]

Revision as of 17:35, 5 October 2012

you could use the perl module, or you can just write to the cmd file.

sub alert ( $$$$ ) {
    my ($host, $test, $code , $message);
    ($host, $test, $code , $message) = @_;
    my $now = time;
    my $cmdfile = "/usr/local/nagios/var/rw/nagios.cmd";
    open(my $fh, ">", "/usr/local/nagios/var/rw/nagios.cmd")
     or die "$now [$$] CRITCAL cannot open > /usr/local/nagios/var/rw/nagios.cmd: $!";
    printf     "$now [$$] Alert: [%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" , $now , $host, $test , $code , $message ;
    printf $fh "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" , $now , $host, $test , $code , $message
     or die "$now [$$] CRITIAL Failed to write to /usr/local/nagios/var/rw/nagios.cmd\n";
    close $fh;
}