function update_trigger_status($triggerids, $status) { zbx_value2array($triggerids); // first update status for child triggers $upd_chd_triggers = array(); $db_chd_triggers = get_triggers_by_templateid($triggerids); while ($db_chd_trigger = DBfetch($db_chd_triggers)) { $upd_chd_triggers[$db_chd_trigger['triggerid']] = $db_chd_trigger['triggerid']; } if (!empty($upd_chd_triggers)) { update_trigger_status($upd_chd_triggers, $status); } add_event($triggerids, TRIGGER_VALUE_UNKNOWN); return DBexecute('UPDATE triggers SET status=' . $status . ' WHERE ' . DBcondition('triggerid', $triggerids)); }
$sql = 'SELECT triggerid, description FROM triggers' . ' WHERE ' . DBcondition('triggerid', $_REQUEST['g_triggerid']); $result = DBSelect($sql); while ($trigger = DBfetch($result)) { $triggers[$trigger['triggerid']] = $trigger; } if ($_REQUEST['go'] == 'activate') { $status = TRIGGER_STATUS_ENABLED; $status_old = array('status' => 0); $status_new = array('status' => 1); } else { $status = TRIGGER_STATUS_DISABLED; $status_old = array('status' => 1); $status_new = array('status' => 0); } DBstart(); $result = update_trigger_status($_REQUEST['g_triggerid'], $status); if ($result) { foreach ($_REQUEST['g_triggerid'] as $id => $triggerid) { $serv_status = isset($_REQUEST['group_enable']) ? get_service_status_of_trigger($triggerid) : 0; update_services($triggerid, $serv_status); // updating status to all services by the dependency add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER, $triggerid, $triggers[$triggerid]['description'], 'triggers', $status_old, $status_new); } } $result = DBend($result); show_messages($result, S_STATUS_UPDATED, S_CANNOT_UPDATE_STATUS); } else { if (isset($_REQUEST['copy']) && isset($_REQUEST['g_triggerid']) && $_REQUEST['go'] == 'copy_to') { if (isset($_REQUEST['copy_targetid']) && $_REQUEST['copy_targetid'] > 0 && isset($_REQUEST['copy_type'])) { if (0 == $_REQUEST['copy_type']) { /* hosts */
} else { if (str_in_array($_REQUEST['go'], array('activate', 'disable')) && isset($_REQUEST['g_triggerid'])) { $options = array('triggerids' => $_REQUEST['g_triggerid'], 'editable' => 1, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND); $triggers = CTrigger::get($options); $triggerids = zbx_objectValues($triggers, 'triggerid'); if ($_REQUEST['go'] == 'activate') { $status = TRIGGER_STATUS_ENABLED; $status_old = array('status' => 1); $status_new = array('status' => 0); } else { $status = TRIGGER_STATUS_DISABLED; $status_old = array('status' => 0); $status_new = array('status' => 1); } DBstart(); $go_result = update_trigger_status($triggerids, $status); if ($go_result) { foreach ($triggers as $tnum => $trigger) { $serv_status = isset($_REQUEST['group_enable']) ? get_service_status_of_trigger($trigger['triggerid']) : 0; update_services($trigger['triggerid'], $serv_status); // updating status to all services by the dependency $host = reset($trigger['hosts']); add_audit_ext(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_TRIGGER, $trigger['triggerid'], $host['host'] . ':' . $trigger['description'], 'triggers', $status_old, $status_new); } } $go_result = DBend($go_result); show_messages($go_result, S_STATUS_UPDATED, S_CANNOT_UPDATE_STATUS); } else { if ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['copy']) && isset($_REQUEST['g_triggerid'])) { if (isset($_REQUEST['copy_targetid']) && $_REQUEST['copy_targetid'] > 0 && isset($_REQUEST['copy_type'])) { if (0 == $_REQUEST['copy_type']) {
function update_trigger_status($triggerids, $status) { zbx_value2array($triggerids); // first update status for child triggers $upd_chd_triggers = array(); $db_chd_triggers = get_triggers_by_templateid($triggerids); while ($db_chd_trigger = DBfetch($db_chd_triggers)) { $upd_chd_triggers[$db_chd_trigger['triggerid']] = $db_chd_trigger['triggerid']; } if (!empty($upd_chd_triggers)) { update_trigger_status($upd_chd_triggers, $status); } DBexecute('UPDATE triggers SET status=' . $status . ' WHERE ' . DBcondition('triggerid', $triggerids)); if ($status != TRIGGER_STATUS_ENABLED) { addEvent($triggerids, TRIGGER_VALUE_UNKNOWN); DBexecute('UPDATE triggers SET lastchange=' . time() . ', value=' . TRIGGER_VALUE_UNKNOWN . ' WHERE ' . DBcondition('triggerid', $triggerids) . ' AND value<>' . TRIGGER_VALUE_UNKNOWN); } return true; }