$mid]); if (!$monitor) { ajaxError("No monitor found for id $mid."); return; } if (!$monitor->canEdit()) { ajaxError('Insufficient permissions'); return; } $action = empty($_REQUEST['action']) ? '' : $_REQUEST['action']; $score = empty($_REQUEST['score']) ? 0 : validCardinal($_REQUEST['score']); $cause = empty($_REQUEST['cause']) ? '' : $_REQUEST['cause']; $text = empty($_REQUEST['text']) ? '' : $_REQUEST['text']; $showtext = empty($_REQUEST['showtext']) ? '' : $_REQUEST['showtext']; if (!is_scalar($cause) or !is_scalar($text) or !is_scalar($showtext)) { ajaxError('cause, text and showtext must be single values'); return; } if ($action == 'show') { } else if ($action == 'enable') { if (!$monitor->enable()) { ajaxError('Unable to enable monitor '.$mid.', is it running?'); } } else if ($action == 'disable') { if (!$monitor->disable()) { ajaxError('Unable to disable monitor '.$mid.', is it running?'); } } else if ($action == 'on') { if ( $score == 0 ) { ZM\Warning('Triggering on with invalid score will have no result.'); ajaxError('Triggering on requires a score greater than 0.'); } if (!$monitor->TriggerEventOn($score, $cause, $text)) { ajaxError('Unable to trigger monitor '.$mid.', is it running?'); } if ($showtext) $monitor->TriggerShowtext($showtext); ZM\Info("Trigger action:'$action' cause:'$cause'"); # Because we aren't a persistent daemon here, we can't handle delays #if ( $delay ) { #my $action_text = $id.'|cancel'; #handleDelay($delay, $connection, $action_text); #} } else if ($action == 'off') { $last_event_id = $monitor->GetLastEventId(); if ($monitor->TriggerEventOff() === false) { ajaxError('Unable to trigger monitor '.$mid.', is it running?'); } if ($showtext) $monitor->TriggerShowtext($showtext); ZM\Info("Trigger '$action'"); # Wait til it's finished $wait_until = time() + 10; while ($monitor->InAlarm() && ($last_event_id == $monitor->GetLastEventId()) && time() < $wait_until) { # Tenth of a second usleep(100000); } $monitor->TriggerEventCancel(); ajaxResponse(['event_id'=>$last_event_id]); } else { ZM\Warning("Invalid action $action"); ajaxError("Invalid action $action"); } ajaxResponse(); } else { ajaxError('Insufficient permissions'); } ?>