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 |
||
(2 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
} | } | ||
</pre> | </pre> | ||
[[Category:Perl]] | |||
[[Category:Nagios]] | |||
[[Category:Script]] |
Latest revision as of 14:54, 2 July 2021
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; }