function make_latest_issues($params = array()) { global $USER_DETAILS; $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY); $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array()); $scripts_by_hosts = get_accessible_scripts_by_hosts($available_hosts); $config = select_config(); $sql_select = ''; $sql_from = ''; $sql_where = ''; $limit = 20; if (!empty($params)) { if (isset($params['limit'])) { $limit = $params['limit']; } if (isset($params['groupid']) && $params['groupid'] > 0) { $sql_select .= ',g.name '; $sql_from .= ',groups g '; $sql_where .= ' AND g.groupid=hg.groupid ' . ' AND hg.groupid=' . $params['groupid']; } if (isset($params['hostid']) && $params['hostid'] > 0) { $sql_where .= ' AND h.hostid=' . $params['hostid']; } } $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, isset($params['groupid']) && $params['groupid'] > 0 ? S_GROUP : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS)); $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description,t.expression,t.priority,t.lastchange,t.value,h.host,h.hostid ' . $sql_select . ' FROM triggers t,hosts h,items i,functions f,hosts_groups hg ' . $sql_from . ' WHERE f.itemid=i.itemid ' . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.value=' . TRIGGER_VALUE_TRUE . $sql_where . ' ORDER BY t.lastchange DESC'; $result = DBselect($sql, $limit); while ($row = DBfetch($result)) { // Check for dependencies if (trigger_dependent($row["triggerid"])) { continue; } $host = null; $menus = ''; $host_nodeid = id2nodeid($row['hostid']); foreach ($scripts_by_hosts[$row['hostid']] as $id => $script) { $script_nodeid = id2nodeid($script['scriptid']); if (bccomp($host_nodeid, $script_nodeid) == 0) { $menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $row['hostid'] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=0&hostid=" . $row['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; $menus = rtrim($menus, ','); $menus = "show_popup_menu(event,[[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus . "],180);"; $host = new CSpan($row['host'], 'link'); $host->setAttribute('onclick', 'javascript: ' . $menus); $host->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $event_sql = 'SELECT DISTINCT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type, t.url ' . ' FROM events e, triggers t ' . ' WHERE e.object=' . EVENT_SOURCE_TRIGGERS . ' AND e.objectid=' . $row['triggerid'] . ' AND t.triggerid=e.objectid ' . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC'; $res_events = DBSelect($event_sql, 1); while ($row_event = DBfetch($res_events)) { $ack = NULL; if ($config['event_ack_enable']) { if ($row_event['acknowledged'] == 1) { $ack_info = make_acktab_by_eventid($row_event['eventid']); $ack_info->setAttribute('style', 'width: auto;'); $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_event['eventid'], 'action'); $ack->setHint($ack_info); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'], 'on'); } } // $description = expand_trigger_description($row['triggerid']); $description = expand_trigger_description_by_data(array_merge($row, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT); //actions $actions = get_event_actions_stat_hints($row_event['eventid']); $clock = new CLink(zbx_date2str(S_DATE_FORMAT_YMDHMS, $row_event['clock']), 'events.php?triggerid=' . $row['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock'], 'action'); if ($row_event['url']) { $description = new CLink($description, $row_event['url'], 'action', null, true); } else { $description = new CSpan($description, 'pointer'); } $description = new CCol($description, get_severity_style($row["priority"])); $description->setHint(make_popup_eventlist($row_event['eventid'], $row['type'])); $table->addRow(array(get_node_name_by_elid($row['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions)); } unset($row, $description, $actions, $alerts, $hint); } $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time()))); return $table; }
function make_small_eventlist($eventid, $trigger_data) { $table = new CTableInfo(); $table->setHeader(array(S_TIME, S_STATUS, S_DURATION, S_AGE, S_ACK, S_ACTIONS)); $rows = array(); $count = 0; $sql = 'SELECT * ' . ' FROM events ' . ' WHERE eventid<=' . $eventid . ' ORDER BY eventid DESC'; $result = DBselect($sql, 100); while (($row = DBfetch($result)) && $count < 20) { if (!empty($rows) && $rows[$count]['value'] != $row['value']) { $count++; } else { if (!empty($rows) && $rows[$count]['value'] == $row['value'] && $trigger_data['type'] == TRIGGER_MULT_EVENT_ENABLED && $row['value'] == TRIGGER_VALUE_TRUE) { $count++; } } $rows[$count] = $row; } $clock = time(); foreach ($rows as $id => $row) { $lclock = $clock; $clock = $row["clock"]; $duration = zbx_date2age($lclock, $clock); $value = new CCol(trigger_value2str($row['value']), get_trigger_value_style($row["value"])); $ack = new CSpan(S_NO, 'on'); if (1 == $row['acknowledged']) { $db_acks = get_acknowledges_by_eventid($row['eventid']); $rows = 0; while ($a = DBfetch($db_acks)) { $rows++; } $ack = array(new CLink(new CSpan(S_YES, 'off'), 'acknow.php?eventid=' . $row['eventid'], 'action'), SPACE . '(' . $rows . ')'); } //actions $actions = get_event_actions_stat_hints($row['eventid']); //-------- $table->AddRow(array(new CLink(date('Y.M.d H:i:s', $row['clock']), "tr_events.php?triggerid=" . $trigger_data['triggerid'] . '&eventid=' . $row['eventid'], "action"), $value, $duration, zbx_date2age($row['clock']), $ack, $actions)); } return $table; }
function make_latest_issues($filter = array()) { global $page; $config = select_config(); $limit = isset($filter['limit']) ? $filter['limit'] : 20; $options = array('groupids' => $filter['groupids'], 'monitored' => 1, 'maintenance' => $filter['maintenance'], 'skipDependent' => 1, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'select_groups' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'sortfield' => 'lastchange', 'sortorder' => ZBX_SORT_DOWN, 'limit' => $limit); if (isset($filter['hostids'])) { $options['hostids'] = $filter['hostids']; } $triggers = CTrigger::get($options); // GATHER HOSTS FOR SELECTED TRIGGERS {{{ $triggers_hosts = array(); foreach ($triggers as $tnum => $trigger) { // if trigger is lost(broken expression) we skip it if (empty($trigger['hosts'])) { unset($triggers[$tnum]); continue; } $triggers_hosts = array_merge($triggers_hosts, $trigger['hosts']); } $triggers_hosts = zbx_toHash($triggers_hosts, 'hostid'); $triggers_hostids = array_keys($triggers_hosts); // }}} GATHER HOSTS FOR SELECTED TRIGGERS $scripts_by_hosts = CScript::getScriptsByHosts($triggers_hostids); $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS)); $thosts_cache = array(); foreach ($triggers as $tnum => $trigger) { // Check for dependencies $group = reset($trigger['groups']); $host = reset($trigger['hosts']); $trigger['hostid'] = $host['hostid']; $trigger['host'] = $host['host']; $host = null; $menus = ''; $host_nodeid = id2nodeid($trigger['hostid']); foreach ($scripts_by_hosts[$trigger['hostid']] as $id => $script) { $script_nodeid = id2nodeid($script['scriptid']); if (bccomp($host_nodeid, $script_nodeid) == 0) { $menus .= "[" . zbx_jsvalue($script['name']) . ",\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $trigger['hostid'] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } if (!empty($scripts_by_hosts)) { $menus = "['" . S_TOOLS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus; } if (isset($thosts_cache[$trigger['hostid']])) { $hprofile = $thosts_cache[$trigger['hostid']]; } else { $hprofile = CHost::get(array('hostids' => $trigger['hostid'], 'output' => API_OUTPUT_SHORTEN, 'select_profile' => API_OUTPUT_EXTEND)); $hprofile = reset($hprofile); $thosts_cache[$hprofile['hostid']] = $hprofile; } $menus .= "['" . S_LINKS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=" . $group['groupid'] . '&hostid=' . $trigger['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; if (!empty($hprofile['profile'])) { $menus .= "['" . S_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=0')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } if (!empty($hprofile['profile_ext'])) { $menus .= "['" . S_EXTENDED_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=1')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } $menus = rtrim($menus, ','); $menus = 'show_popup_menu(event,[' . $menus . '],180);'; $host = new CSpan($trigger['host'], 'link_menu pointer'); $host->setAttribute('onclick', 'javascript: ' . $menus); //$host = new CSpan($trigger['host'],'link_menu pointer'); //$host->setAttribute('onclick','javascript: '.$menus); // Maintenance {{{ $trigger_host = $triggers_hosts[$trigger['hostid']]; $text = null; $style = 'link_menu'; if ($trigger_host['maintenance_status']) { $style .= ' orange'; $options = array('maintenanceids' => $trigger_host['maintenanceid'], 'output' => API_OUTPUT_EXTEND); $maintenances = CMaintenance::get($options); $maintenance = reset($maintenances); $text = $maintenance['name']; $text .= ' [' . ($trigger_host['maintenance_type'] ? S_NO_DATA_MAINTENANCE : S_NORMAL_MAINTENANCE) . ']'; } $host = new CSpan($trigger['host'], $style . ' pointer'); $host->setAttribute('onclick', 'javascript: ' . $menus); if (!is_null($text)) { $host->setHint($text, '', '', false); } // }}} Maintenance $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged' . ' FROM events e' . ' WHERE e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.objectid=' . $trigger['triggerid'] . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC'; $res_events = DBSelect($event_sql, 1); while ($row_event = DBfetch($res_events)) { $ack = NULL; if ($config['event_ack_enable']) { if ($row_event['acknowledged'] == 1) { $ack_info = make_acktab_by_eventid($row_event['eventid']); $ack_info->setAttribute('style', 'width: auto;'); $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'off'); $ack->setHint($ack_info, '', '', false); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'on'); } } // $description = expand_trigger_description($row['triggerid']); $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT); //actions $actions = get_event_actions_stat_hints($row_event['eventid']); $clock = new CLink(zbx_date2str(S_BLOCKS_LATEST_ISSUES_DATE_FORMAT, $row_event['clock']), 'events.php?triggerid=' . $trigger['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock']); if ($trigger['url']) { $description = new CLink($description, $trigger['url'], null, null, true); } else { $description = new CSpan($description, 'pointer'); } $description = new CCol($description, get_severity_style($trigger['priority'])); $description->setHint(make_popup_eventlist($row_event['eventid'], $trigger['type'], $trigger['triggerid']), '', '', false); $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions)); } unset($trigger, $description, $actions); } $table->setFooter(new CCol(S_UPDATED . ': ' . zbx_date2str(S_BLOCKS_LATEST_ISSUES_TIME_FORMAT))); return $table; }
function make_small_eventlist($eventid, $trigger_data) { $config = select_config(); $table = new CTableInfo(); $table->setHeader(array(S_TIME, S_STATUS, S_DURATION, S_AGE, $config['event_ack_enable'] ? S_ACK : null, S_ACTIONS)); $options = array('eventids' => $eventid, 'output' => API_OUTPUT_EXTEND); $curevent = CEvent::get($options); $curevent = reset($curevent); $clock = $curevent['clock']; $options = array('triggerids' => $trigger_data['triggerid'], 'eventid_till' => $curevent['eventid'], 'select_triggers' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'sortfield' => 'clock', 'sortorder' => ZBX_SORT_DOWN, 'limit' => 20); $events = CEvent::get($options); foreach ($events as $enum => $event) { $trigger = reset($event['triggers']); $event['type'] = $trigger['type']; $lclock = $clock; $clock = $event['clock']; $duration = zbx_date2age($lclock, $clock); if ($curevent['eventid'] == $event['eventid'] && ($nextevent = get_next_event($event))) { $duration = zbx_date2age($nextevent['clock'], $clock); } else { if ($curevent['eventid'] == $event['eventid']) { $duration = zbx_date2age($clock); } } $value = new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value'])); // if acknowledges are not disabled in configuration, let's show them if ($config['event_ack_enable']) { global $page; $backurl = urlencode(urlencode($page['file'] . '?eventid=' . $curevent['eventid'] . '&triggerid=' . $trigger_data['triggerid'])); if ($event['acknowledged'] == 1) { $rows = 0; $db_acks = get_acknowledges_by_eventid($event['eventid']); while ($a = DBfetch($db_acks)) { $rows++; } $ack = array(new CLink(S_YES, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $backurl, 'off'), ' (' . $rows . ')'); } else { $ack = array(new CLink(S_NO, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $backurl, 'on')); } } //actions $actions = get_event_actions_stat_hints($event['eventid']); //-------- $table->addRow(array(new CLink(zbx_date2str(S_EVENTS_SMALL_EVENT_LIST_DATE_FORMAT, $event['clock']), 'tr_events.php?triggerid=' . $trigger_data['triggerid'] . '&eventid=' . $event['eventid'], 'action'), $value, $duration, zbx_date2age($event['clock']), $config['event_ack_enable'] ? $ack : null, $actions)); } return $table; }