Nagios alert in perl
From Federal Burro of Information
Jump to navigationJump to search
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; }