Example #1
0
    if (!isset($mydata['hostname']) || $mydata['hostname'] == '' || !isset($mydata['checkname']) || $mydata['checkname'] == '') {
        $msg = "Invalid request: Expecting either check_id or hostname AND checkname";
        header("HTTP/1.0 400 {$msg}");
        print $msg;
        exit;
    }
    //$event->set_check_id(null);
    $event->set_check_name($mydata['checkname']);
    $event->set_hostname($mydata['hostname']);
    $event->set_key1($mydata['key1']);
    $event->set_key2($mydata['key2']);
}
// Parse message data, to extract message and performance data
$msg_data = parse_perf_data($mydata['message']);
$event->set_info_msg($msg_data['message']);
$event->set_performance_data($msg_data['perf_data']);
// Now  we can use handle_event() to figure out if this is a new
// or exitsing event. It will do all the updating for us
// and call notify() in the event class
$status = $event->handle_event();
//print status line
$resp_mesg = "Successfull {$status} for event_id: " . $event->get_event_id();
//header("HTTP/1.0 200 OK $resp_mesg");
print $resp_mesg;
function parse_perf_data($message)
{
    // Now we need to parse the $message and filter out performance data
    // Message can have multiple perf_data fields
    // perf data always comes after a | sign
    // 'label'=value[UOM];[warn];[crit];[min];[max]
    // For now we don't implement [warn];[crit];[min];[max] , just the data
Example #2
0
// Base dir for scripts
$script_dir = "check-scripts";
// Get check info
// Create check object
$check = new Check($check_id);
// Start timer and exec check script
$time_start = microtime(true);
$script = "{$script_dir}/" . $check->get_parsed_check_script();
$check_result = exec_check($script);
// Now create a new Event object
// Store the info we know from Check object
// and check results
$event = new Event();
$event->set_status($check_result['status']);
$event->set_info_msg($check_result['message']);
$event->set_performance_data($check_result['perf_data']);
$event->set_check_id($check->get_check_id());
$event->set_script($script);
$event->set_check_name($check->get_name());
$event->set_hostname($check->get_hostname());
$event->set_key1($check->get_key1());
$event->set_key2($check->get_key2());
// Now  we can use handle_event() to figure out if this is a new
// or exitsing event. It will do all the updating for us
// and call notify() in the event class
$event->handle_event();
$time_end = microtime(true);
$time = $time_end - $time_start;
//print status line
print "{$script} => status: " . $event->get_status() . "  " . trim($event->get_info_msg());
if ($check_result['perf_data'] != "") {