#!/usr/bin/perl

# Arguments
# 0 = name of host in service definition
# 1 = name/description of service in service definition
# 2 = return code
# 3 = output

# [<timestamp>] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<description>;<return_code>;<plugin_output>
#
# Sample usage: /usr/local/bin/submit_check_result pc2 PING 2 down 
#
# The command socket for Nagios under Debian is here: /var/lib/nagios2/rw/ 
#

my $host = $ARGV[0];
my $service = $ARGV[1];
my $value = $ARGV[2];
my $mesg = $ARGV[3];

my $time = time;


# Update the directory if nagios.cmd is somewhere else for your OS

open CMD, ">>/var/lib/nagios2/rw/nagios.cmd" || die;
print CMD "[$time] PROCESS_SERVICE_CHECK_RESULT;$host;$service;$value;$mesg\n";
close CMD;
