Nagios alert in perl: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 18: | Line 18: | ||
[[Category:Perl]] | [[Category:Perl]] | ||
[[Category:Nagios]] | [[Category:Nagios]] | ||
[[Category: | [[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; }