} } if (!empty($scripts_by_hosts)) { $menus = "[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus; } $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?hostid=" . $trigger_host['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; $menus = rtrim($menus, ','); $menus = 'show_popup_menu(event,[' . $menus . '],180);'; $maint_span = null; if ($trigger_host['maintenance_status']) { $text = $trigger_host['maintenance_type'] ? S_NO_DATA_MAINTENANCE : S_NORMAL_MAINTENANCE; $text = ' [' . $text . ']'; $maint_span = new CSpan($text, 'orange pointer'); $maintenanceOptions = array('maintenanceids' => $trigger_host['maintenanceid'], 'output' => API_OUTPUT_EXTEND); $maintenances = CMaintenance::get($maintenanceOptions); $maintenance = reset($maintenances); $maint_hint = new CSpan($maintenance['name'] . ($maintenance['description'] == '' ? '' : ': ' . $maintenance['description'])); $maint_span->setHint($maint_hint); } $hosts_span = new CSpan($trigger_host['host'], 'link_menu'); $hosts_span->setAttribute('onclick', 'javascript: ' . $menus); $hosts_list[] = $hosts_span; $hosts_list[] = $maint_span; $hosts_list[] = ', '; } array_pop($hosts_list); $host = new CCol($hosts_list); $host->addStyle('white-space: normal;'); // }}} host JS menu $status = new CSpan(trigger_value2str($trigger['value']), get_trigger_value_style($trigger['value']));
private static function maintenance($action, $params) { CMaintenance::$error = array(); switch ($action) { default: $result = call_user_func(array('CMaintenance', $action), $params); } self::$result = $result; }
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; }
/** * Update maintenances * * @param _array $maintenances * @return boolean */ public static function update($maintenances) { global $USER_DETAILS; $maintenances = zbx_toArray($maintenances); $maintenanceids = zbx_objectValues($maintenances, 'maintenanceid'); try { self::BeginTransaction(__METHOD__); if ($USER_DETAILS['type'] == USER_TYPE_ZABBIX_USER) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } // Maintenance permissions $hostids = array(); $groupids = array(); $options = array('maintenanceids' => zbx_objectValues($maintenances, 'maintenanceid'), 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1); $upd_maintenances = self::get($options); foreach ($maintenances as $maintenance) { if (!isset($upd_maintenances[$maintenance['maintenanceid']])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } //checkig wheter a maintence with this name and different already exists //first, getting all maintences with the same name as this $options = array('filter' => array('name' => $maintenance['name'])); $received_maintenaces = CMaintenance::get($options); //now going though a result, to find records with different id, then our object foreach ($received_maintenaces as $r_maintenace) { if ($r_maintenace['maintenanceid'] != $maintenance['maintenanceid']) { //error! Maintenance with this name already exists self::exception(ZBX_API_ERROR_PARAMETERS, S_MAINTENANCE . ' [ ' . $maintenance['name'] . ' ] ' . S_ALREADY_EXISTS_SMALL); } } $hostids = array_merge($hostids, $maintenance['hostids']); $groupids = array_merge($groupids, $maintenance['groupids']); } if (empty($hostids) && empty($groupids)) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_GROUP_OR_HOST_NEEDED); } // hosts permissions $options = array('hostids' => $hostids, 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1); $upd_hosts = CHost::get($options); foreach ($hostids as $hostid) { if (!isset($upd_hosts[$hostid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } // groups permissions $options = array('groupids' => $groupids, 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1); $upd_groups = CHostGroup::get($options); foreach ($groupids as $groupid) { if (!isset($upd_groups[$groupid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } $timeperiodids = array(); $sql = 'SELECT DISTINCT tp.timeperiodid ' . ' FROM timeperiods tp, maintenances_windows mw ' . ' WHERE ' . DBcondition('mw.maintenanceid', $maintenanceids) . ' AND tp.timeperiodid=mw.timeperiodid '; $db_timeperiods = DBselect($sql); while ($timeperiod = DBfetch($db_timeperiods)) { $timeperiodids[] = $timeperiod['timeperiodid']; } DB::delete('timeperiods', DBcondition('timeperiodid', $timeperiodids)); DB::delete('maintenances_windows', DBcondition('maintenanceid', $maintenanceids)); $tid = 0; $update = array(); $timeperiods = array(); $insert_timeperiods = array(); foreach ($maintenances as $mnum => $maintenance) { $db_fields = array('maintenanceid' => null); if (!check_db_fields($db_fields, $maintenance)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect parameters used for Maintenance'); } $update[$mnum] = array('values' => $maintenance, 'where' => array('maintenanceid=' . $maintenance['maintenanceid'])); foreach ($maintenance['timeperiods'] as $timeperiod) { $tid++; $insert_timeperiods[$tid] = $timeperiod; $timeperiods[$tid] = $mnum; } } DB::update('maintenances', $update); $timeperiodids = DB::insert('timeperiods', $insert_timeperiods); $insert_windows = array(); foreach ($timeperiods as $tid => $mnum) { $insert_windows[] = array('timeperiodid' => $timeperiodids[$tid], 'maintenanceid' => $maintenances[$mnum]['maintenanceid']); } DB::insert('maintenances_windows', $insert_windows); DB::delete('maintenances_hosts', DBcondition('maintenanceid', $maintenanceids)); DB::delete('maintenances_groups', DBcondition('maintenanceid', $maintenanceids)); $insert_hosts = array(); $insert_groups = array(); foreach ($maintenances as $mnum => $maintenance) { foreach ($maintenance['hostids'] as $hostid) { $insert_hosts[] = array('hostid' => $hostid, 'maintenanceid' => $maintenance['maintenanceid']); } foreach ($maintenance['groupids'] as $groupid) { $insert_groups[] = array('groupid' => $groupid, 'maintenanceid' => $maintenance['maintenanceid']); } } DB::insert('maintenances_hosts', $insert_hosts); DB::insert('maintenances_groups', $insert_groups); self::EndTransaction(true, __METHOD__); return true; } catch (APIException $e) { self::EndTransaction(false, __METHOD__); $error = $e->getErrors(); $error = reset($error); self::setError(__METHOD__, $e->getCode(), $error); return false; } }