protected function doAction() { $sortField = $this->getInput('sort', CProfile::get('web.proxies.php.sort', 'host')); $sortOrder = $this->getInput('sortorder', CProfile::get('web.proxies.php.sortorder', ZBX_SORT_UP)); CProfile::update('web.proxies.php.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.proxies.php.sortorder', $sortOrder, PROFILE_TYPE_STR); $config = select_config(); $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder, 'config' => ['max_in_table' => $config['max_in_table']]]; $data['proxies'] = API::Proxy()->get(['output' => ['proxyid', 'host', 'status', 'lastaccess', 'tls_connect', 'tls_accept'], 'selectHosts' => ['hostid', 'name', 'status'], 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]); // sorting & paging order_result($data['proxies'], $sortField, $sortOrder); $url = (new CUrl('zabbix.php'))->setArgument('action', 'proxy.list'); $data['paging'] = getPagingLine($data['proxies'], $sortOrder, $url); foreach ($data['proxies'] as &$proxy) { order_result($proxy['hosts'], 'name'); } unset($proxy); // get proxy IDs for a *selected* page $proxyIds = array_keys($data['proxies']); if ($proxyIds) { // calculate performance $dbPerformance = DBselect('SELECT h.proxy_hostid,SUM(1.0/i.delay) AS qps' . ' FROM hosts h,items i' . ' WHERE h.hostid=i.hostid' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.delay<>0' . ' AND i.flags<>' . ZBX_FLAG_DISCOVERY_PROTOTYPE . ' AND ' . dbConditionInt('h.proxy_hostid', $proxyIds) . ' GROUP BY h.proxy_hostid'); while ($performance = DBfetch($dbPerformance)) { $data['proxies'][$performance['proxy_hostid']]['perf'] = round($performance['qps'], 2); } // get items $items = API::Item()->get(['proxyids' => $proxyIds, 'groupCount' => true, 'countOutput' => true, 'webitems' => true, 'monitored' => true]); foreach ($items as $item) { $data['proxies'][$item['proxy_hostid']]['item_count'] = $item['rowscount']; } } $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of proxies')); $this->setResponse($response); }
protected function doAction() { $sortField = $this->getInput('sort', CProfile::get('web.media_types.php.sort', 'description')); $sortOrder = $this->getInput('sortorder', CProfile::get('web.media_types.php.sortorder', ZBX_SORT_UP)); CProfile::update('web.media_type.php.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.media_types.php.sortorder', $sortOrder, PROFILE_TYPE_STR); $config = select_config(); $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder]; // get media types $data['mediatypes'] = API::Mediatype()->get(['output' => ['mediatypeid', 'description', 'type', 'smtp_server', 'smtp_helo', 'smtp_email', 'exec_path', 'gsm_modem', 'username', 'status'], 'limit' => $config['search_limit'] + 1, 'editable' => true, 'preservekeys' => true]); if ($data['mediatypes']) { // get media types used in actions $actions = API::Action()->get(['output' => ['actionid', 'name'], 'selectOperations' => ['operationtype', 'opmessage'], 'mediatypeids' => array_keys($data['mediatypes'])]); foreach ($data['mediatypes'] as &$mediaType) { $mediaType['typeid'] = $mediaType['type']; $mediaType['type'] = media_type2str($mediaType['type']); $mediaType['listOfActions'] = []; foreach ($actions as $action) { foreach ($action['operations'] as $operation) { if ($operation['operationtype'] == OPERATION_TYPE_MESSAGE && $operation['opmessage']['mediatypeid'] == $mediaType['mediatypeid']) { $mediaType['listOfActions'][$action['actionid']] = ['actionid' => $action['actionid'], 'name' => $action['name']]; } } } order_result($mediaType['listOfActions'], 'name'); } unset($mediaType); order_result($data['mediatypes'], $sortField, $sortOrder); } $url = (new CUrl('zabbix.php'))->setArgument('action', 'mediatype.list'); $data['paging'] = getPagingLine($data['mediatypes'], $sortOrder, $url); $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of media types')); $this->setResponse($response); }
protected function doAction() { $sortField = $this->getInput('sort', CProfile::get('web.scripts.php.sort', 'name')); $sortOrder = $this->getInput('sortorder', CProfile::get('web.scripts.php.sortorder', ZBX_SORT_UP)); CProfile::update('web.scripts.php.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.scripts.php.sortorder', $sortOrder, PROFILE_TYPE_STR); $config = select_config(); $data = ['uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder]; // list of scripts $data['scripts'] = API::Script()->get(['output' => ['scriptid', 'name', 'command', 'host_access', 'usrgrpid', 'groupid', 'type', 'execute_on'], 'editable' => true, 'limit' => $config['search_limit'] + 1]); // sorting & paging order_result($data['scripts'], $sortField, $sortOrder); $url = (new CUrl('zabbix.php'))->setArgument('action', 'script.list'); $data['paging'] = getPagingLine($data['scripts'], $sortOrder, $url); // find script host group name and user group name. set to '' if all host/user groups used. $usrgrpids = []; $groupids = []; foreach ($data['scripts'] as &$script) { $script['userGroupName'] = null; // all user groups $script['hostGroupName'] = null; // all host groups if ($script['usrgrpid'] != 0) { $usrgrpids[] = $script['usrgrpid']; } if ($script['groupid'] != 0) { $groupids[] = $script['groupid']; } } unset($script); if ($usrgrpids) { $userGroups = API::UserGroup()->get(['output' => ['name'], 'usrgrpids' => $usrgrpids, 'preservekeys' => true]); foreach ($data['scripts'] as &$script) { if ($script['usrgrpid'] != 0 && array_key_exists($script['usrgrpid'], $userGroups)) { $script['userGroupName'] = $userGroups[$script['usrgrpid']]['name']; } unset($script['usrgrpid']); } unset($script); } if ($groupids) { $hostGroups = API::HostGroup()->get(['output' => ['name'], 'groupids' => $groupids, 'preservekeys' => true]); foreach ($data['scripts'] as &$script) { if ($script['groupid'] != 0 && array_key_exists($script['groupid'], $hostGroups)) { $script['hostGroupName'] = $hostGroups[$script['groupid']]['name']; } unset($script['groupid']); } unset($script); } $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of scripts')); $this->setResponse($response); }
/** * Find user theme or get default theme. * * @param array $userData * * @return string */ function getUserTheme($userData) { $config = select_config(); if (isset($config['default_theme'])) { $css = $config['default_theme']; } if (isset($userData['theme']) && $userData['theme'] != THEME_DEFAULT) { $css = $userData['theme']; } if (!isset($css)) { $css = ZBX_DEFAULT_THEME; } return $css; }
protected function doAction() { $filter = ['groupids' => null, 'maintenance' => null, 'severity' => null, 'trigger_name' => '', 'extAck' => 0]; if (CProfile::get('web.dashconf.filter.enable', 0) == 1) { // groups if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) { // null mean all groups $filter['groupids'] = null; } else { $filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value'); $hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value'); if ($hideHostGroupIds) { // get all groups if no selected groups defined if (!$filter['groupids']) { $dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]); $filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid'); } $filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds); // get available hosts $dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]); $availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid'); $dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]); $disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid'); $filter['hostids'] = array_diff($availableHostIds, $disabledHostIds); } else { if (!$filter['groupids']) { // null mean all groups $filter['groupids'] = null; } } } // hosts $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1); $filter['maintenance'] = $maintenance == 0 ? 0 : null; // triggers $severity = CProfile::get('web.dashconf.triggers.severity', null); $filter['severity'] = zbx_empty($severity) ? null : explode(';', $severity); $filter['severity'] = zbx_toHash($filter['severity']); $filter['trigger_name'] = CProfile::get('web.dashconf.triggers.name', ''); $config = select_config(); $filter['extAck'] = $config['event_ack_enable'] ? CProfile::get('web.dashconf.events.extAck', 0) : 0; } $this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]])); }
/** * @param string $options['name'] * @param int $options['value'] (optional) Default: TRIGGER_SEVERITY_NOT_CLASSIFIED * @param bool $options['all'] (optional) */ public function __construct(array $options = []) { parent::__construct(); $id = zbx_formatDomId($options['name']); $this->addClass(ZBX_STYLE_RADIO_SEGMENTED); $this->setId($id); if (!array_key_exists('value', $options)) { $options['value'] = TRIGGER_SEVERITY_NOT_CLASSIFIED; } $severity_from = array_key_exists('all', $options) && $options['all'] ? -1 : TRIGGER_SEVERITY_NOT_CLASSIFIED; $config = select_config(); for ($severity = $severity_from; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { $name = $severity == -1 ? _('all') : getSeverityName($severity, $config); $class = $severity == -1 ? null : getSeverityStyle($severity); $radio = (new CInput('radio', $options['name'], $severity))->setId(zbx_formatDomId($options['name'] . '_' . $severity)); if ($severity === $options['value']) { $radio->setAttribute('checked', 'checked'); } parent::addItem((new CListItem([$radio, new CLabel($name, $options['name'] . '_' . $severity)]))->addClass($class)); } }
public function bodyToString() { $this->cleanItems(); $config = select_config(); // array of triggers (not classified, information, warning, average, high, disaster) in problem state $triggersProblemState = []; // number of triggers in OK state $triggersOkState = 0; $options = ['output' => ['triggerid', 'priority', 'value'], 'monitored' => true, 'skipDependent' => true]; if ($this->groupid != 0) { $options['groupids'] = $this->groupid; } $triggers = API::Trigger()->get($options); foreach ($triggers as $trigger) { switch ($trigger['value']) { case TRIGGER_VALUE_TRUE: if (!array_key_exists($trigger['priority'], $triggersProblemState)) { $triggersProblemState[$trigger['priority']] = 0; } $triggersProblemState[$trigger['priority']]++; break; case TRIGGER_VALUE_FALSE: $triggersOkState++; } } $severityCells = [getSeverityCell(null, $config, $triggersOkState . SPACE . _('Ok'), true)]; for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { $severityCount = isset($triggersProblemState[$severity]) ? $triggersProblemState[$severity] : 0; $severityCells[] = getSeverityCell($severity, $config, $severityCount . SPACE . getSeverityName($severity, $config), !$severityCount); } if ($this->style == STYLE_HORIZONTAL) { $this->addRow($severityCells); } else { foreach ($severityCells as $severityCell) { $this->addRow($severityCell); } } return parent::bodyToString(); }
/** * Generate table for dashboard triggers popup. * * @see make_system_status * * @param array $triggers * @param array $ackParams * @param array $actions * * @return CTableInfo */ function makeTriggersPopup(array $triggers, array $ackParams, array $actions) { $config = select_config(); $popupTable = new CTableInfo(); $popupTable->setAttribute('style', 'width: 400px;'); $popupTable->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host'), _('Issue'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions'))); CArrayHelper::sort($triggers, array(array('field' => 'lastchange', 'order' => ZBX_SORT_DOWN))); foreach ($triggers as $trigger) { // unknown triggers $unknown = SPACE; if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) { $unknown = new CDiv(SPACE, 'status_icon iconunknown'); $unknown->setHint($trigger['error'], '', 'on'); } // ack if ($config['event_ack_enable']) { $ack = isset($trigger['event']['eventid']) ? getEventAckState($trigger['event'], true, true, $ackParams) : _('No events'); } else { $ack = null; } // action $action = isset($trigger['event']['eventid']) && isset($actions[$trigger['event']['eventid']]) ? $actions[$trigger['event']['eventid']] : _('-'); $popupTable->addRow(array(get_node_name_by_elid($trigger['triggerid']), $trigger['hosts'][0]['name'], getSeverityCell($trigger['priority'], $trigger['description']), zbx_date2age($trigger['lastchange']), $unknown, $ack, $action)); } return $popupTable; }
$data = array(); $data['form_refresh'] = get_request('form_refresh', 0); // form has been submitted if ($data['form_refresh']) { $data['ok_period'] = get_request('ok_period'); $data['blink_period'] = get_request('blink_period'); $data['problem_unack_color'] = get_request('problem_unack_color'); $data['problem_ack_color'] = get_request('problem_ack_color'); $data['ok_unack_color'] = get_request('ok_unack_color'); $data['ok_ack_color'] = get_request('ok_ack_color'); $data['problem_unack_style'] = get_request('problem_unack_style'); $data['problem_ack_style'] = get_request('problem_ack_style'); $data['ok_unack_style'] = get_request('ok_unack_style'); $data['ok_ack_style'] = get_request('ok_ack_style'); } else { $config = select_config(false); $data['ok_period'] = $config['ok_period']; $data['blink_period'] = $config['blink_period']; $data['problem_unack_color'] = $config['problem_unack_color']; $data['problem_ack_color'] = $config['problem_ack_color']; $data['ok_unack_color'] = $config['ok_unack_color']; $data['ok_ack_color'] = $config['ok_ack_color']; $data['problem_unack_style'] = $config['problem_unack_style']; $data['problem_ack_style'] = $config['problem_ack_style']; $data['ok_unack_style'] = $config['ok_unack_style']; $data['ok_ack_style'] = $config['ok_ack_style']; } $triggerDisplayingForm = new CView('administration.general.triggerDisplayOptions.edit', $data); $cnf_wdgt->addItem($triggerDisplayingForm->render()); $cnf_wdgt->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
protected function selectData() { $this->data = array(); $now = time(null); if (isset($this->stime)) { $this->from_time = $this->stime; $this->to_time = $this->stime + $this->period; } else { $this->to_time = $now - SEC_PER_HOUR * $this->from; $this->from_time = $this->to_time - $this->period; } $strvaluelength = 0; // we need to know how long in px will be our legend // fetch values for items with the "last" function $lastValueItems = array(); foreach ($this->items as $item) { if ($item['calc_fnc'] == CALC_FNC_LST) { $lastValueItems[] = $item; } } if ($lastValueItems) { $history = Manager::History()->getLast($lastValueItems); } $config = select_config(); for ($i = 0; $i < $this->num; $i++) { $item = get_item_by_itemid($this->items[$i]['itemid']); $type = $this->items[$i]['calc_type']; $from_time = $this->from_time; $to_time = $this->to_time; $sql_arr = array(); // override item history setting with housekeeping settings if ($config['hk_history_global']) { $item['history'] = $config['hk_history']; } $trendsEnabled = $config['hk_trends_global'] ? $config['hk_trends'] > 0 : $item['trends'] > 0; if (!$trendsEnabled || $item['history'] * SEC_PER_DAY > time() - ($from_time + $this->period / 2)) { $this->dataFrom = 'history'; array_push($sql_arr, 'SELECT h.itemid,' . 'AVG(h.value) AS avg,MIN(h.value) AS min,' . 'MAX(h.value) AS max,MAX(h.clock) AS clock' . ' FROM history h' . ' WHERE h.itemid=' . zbx_dbstr($this->items[$i]['itemid']) . ' AND h.clock>=' . zbx_dbstr($from_time) . ' AND h.clock<=' . zbx_dbstr($to_time) . ' GROUP BY h.itemid', 'SELECT hu.itemid,' . 'AVG(hu.value) AS avg,MIN(hu.value) AS min,' . 'MAX(hu.value) AS max,MAX(hu.clock) AS clock' . ' FROM history_uint hu' . ' WHERE hu.itemid=' . zbx_dbstr($this->items[$i]['itemid']) . ' AND hu.clock>=' . zbx_dbstr($from_time) . ' AND hu.clock<=' . zbx_dbstr($to_time) . ' GROUP BY hu.itemid'); } else { $this->dataFrom = 'trends'; array_push($sql_arr, 'SELECT t.itemid,' . 'AVG(t.value_avg) AS avg,MIN(t.value_min) AS min,' . 'MAX(t.value_max) AS max,MAX(t.clock) AS clock' . ' FROM trends t' . ' WHERE t.itemid=' . zbx_dbstr($this->items[$i]['itemid']) . ' AND t.clock>=' . zbx_dbstr($from_time) . ' AND t.clock<=' . zbx_dbstr($to_time) . ' GROUP BY t.itemid', 'SELECT t.itemid,' . 'AVG(t.value_avg) AS avg,MIN(t.value_min) AS min,' . 'MAX(t.value_max) AS max,MAX(t.clock) AS clock' . ' FROM trends_uint t' . ' WHERE t.itemid=' . zbx_dbstr($this->items[$i]['itemid']) . ' AND t.clock>=' . zbx_dbstr($from_time) . ' AND t.clock<=' . zbx_dbstr($to_time) . ' GROUP BY t.itemid'); } $this->data[$this->items[$i]['itemid']][$type]['last'] = isset($history[$item['itemid']]) ? $history[$item['itemid']][0]['value'] : null; $this->data[$this->items[$i]['itemid']][$type]['shift_min'] = 0; $this->data[$this->items[$i]['itemid']][$type]['shift_max'] = 0; $this->data[$this->items[$i]['itemid']][$type]['shift_avg'] = 0; foreach ($sql_arr as $sql) { $result = DBselect($sql); while ($row = DBfetch($result)) { $this->data[$this->items[$i]['itemid']][$type]['min'] = $row['min']; $this->data[$this->items[$i]['itemid']][$type]['max'] = $row['max']; $this->data[$this->items[$i]['itemid']][$type]['avg'] = $row['avg']; $this->data[$this->items[$i]['itemid']][$type]['clock'] = $row['clock']; } unset($row); } switch ($this->items[$i]['calc_fnc']) { case CALC_FNC_MIN: $fncName = 'min'; break; case CALC_FNC_MAX: $fncName = 'max'; break; case CALC_FNC_LST: $fncName = 'last'; break; case CALC_FNC_AVG: default: $fncName = 'avg'; } $item_value = empty($this->data[$this->items[$i]['itemid']][$type][$fncName]) ? 0 : abs($this->data[$this->items[$i]['itemid']][$type][$fncName]); if ($type == GRAPH_ITEM_SUM) { $this->background = $i; $graph_sum = $item_value; } $this->sum += $item_value; $convertedUnit = zbx_strlen(convert_units(array('value' => $item_value, 'units' => $this->items[$i]['units']))); $strvaluelength = max($strvaluelength, $convertedUnit); } if (isset($graph_sum)) { $this->sum = $graph_sum; } $this->shiftlegendright += $strvaluelength * 7; }
// get permissions $userType = CWebUser::getType(); if ($userType == USER_TYPE_SUPER_ADMIN) { $data['rwHost'] = true; } elseif ($userType == USER_TYPE_ZABBIX_ADMIN) { $rwHost = API::Host()->get(['output' => ['hostid'], 'hostids' => $hostId, 'editable' => true]); $data['rwHost'] = (bool) $rwHost; } else { $data['rwHost'] = false; } // view generation $hostinventoriesView = new CView('inventory.host.view', $data); $hostinventoriesView->render(); $hostinventoriesView->show(); } else { $data = ['config' => select_config(), 'hosts' => [], 'sort' => $sortField, 'sortorder' => $sortOrder]; // filter $data['pageFilter'] = new CPageFilter(['groups' => ['real_hosts' => true], 'groupid' => getRequest('groupid')]); /* * Filter */ if (hasRequest('filter_set')) { CProfile::update('web.hostinventories.filter_field', getRequest('filter_field', ''), PROFILE_TYPE_STR); CProfile::update('web.hostinventories.filter_field_value', getRequest('filter_field_value', ''), PROFILE_TYPE_STR); CProfile::update('web.hostinventories.filter_exact', getRequest('filter_exact', 0), PROFILE_TYPE_INT); } elseif (hasRequest('filter_rst')) { DBStart(); CProfile::delete('web.hostinventories.filter_field'); CProfile::delete('web.hostinventories.filter_field_value'); CProfile::delete('web.hostinventories.filter_exact'); DBend();
/** * Get group authentication type. * * @param array $groupIds * @param int $maxGuiAccess * * @return int */ function getGroupAuthenticationType($groupIds, $maxGuiAccess = null) { $config = select_config(); switch (getGroupsGuiAccess($groupIds, $maxGuiAccess)) { case GROUP_GUI_ACCESS_SYSTEM: return $config['authentication_type']; case GROUP_GUI_ACCESS_INTERNAL: return $config['authentication_type'] == ZBX_AUTH_HTTP ? ZBX_AUTH_HTTP : ZBX_AUTH_INTERNAL; default: return $config['authentication_type']; } }
/** * Create DIV with latest problem triggers. * * If no sortfield and sortorder are defined, the sort indicater in the column name will not be displayed. * * @param array $filter['groupids'] * @param array $filter['hostids'] * @param array $filter['maintenance'] * @param int $filter['extAck'] * @param int $filter['severity'] * @param int $filter['limit'] * @param string $filter['sortfield'] * @param string $filter['sortorder'] * @param string $backurl * * @return CDiv */ function make_latest_issues(array $filter = [], $backurl) { // hide the sort indicator if no sortfield and sortorder are given $show_sort_indicator = isset($filter['sortfield']) || isset($filter['sortorder']); if (isset($filter['sortfield']) && $filter['sortfield'] !== 'lastchange') { $sort_field = [$filter['sortfield'], 'lastchange']; $sort_order = [$filter['sortorder'], ZBX_SORT_DOWN]; } else { $sort_field = ['lastchange']; $sort_order = [ZBX_SORT_DOWN]; } $options = ['groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored' => true, 'maintenance' => $filter['maintenance'], 'search' => $filter['trigger_name'] !== '' ? ['description' => $filter['trigger_name']] : null, 'filter' => ['priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE]]; $triggers = API::Trigger()->get(array_merge($options, ['output' => ['triggerid', 'expression', 'description', 'url', 'priority', 'lastchange', 'comments', 'error', 'state'], 'selectHosts' => ['hostid'], 'selectLastEvent' => ['eventid', 'acknowledged', 'objectid', 'clock', 'ns'], 'withLastEventUnacknowledged' => isset($filter['extAck']) && $filter['extAck'] == EXTACK_OPTION_UNACK ? true : null, 'skipDependent' => true, 'sortfield' => $sort_field, 'sortorder' => $sort_order, 'limit' => isset($filter['limit']) ? $filter['limit'] : DEFAULT_LATEST_ISSUES_CNT, 'preservekeys' => true, 'expandComment' => true])); $triggers = CMacrosResolverHelper::resolveTriggerUrls($triggers); // don't use withLastEventUnacknowledged and skipDependent because of performance issues $triggers_total_count = API::Trigger()->get(array_merge($options, ['countOutput' => true])); // get acknowledges $hostids = []; $eventids = []; foreach ($triggers as $trigger) { foreach ($trigger['hosts'] as $host) { $hostids[$host['hostid']] = true; } if ($trigger['lastEvent']) { $eventids[] = $trigger['lastEvent']['eventid']; } } $config = select_config(); if ($config['event_ack_enable'] && $eventids) { $event_acknowledges = API::Event()->get(['output' => ['eventid'], 'eventids' => $eventids, 'select_acknowledges' => API_OUTPUT_EXTEND, 'preservekeys' => true]); } // actions $actions = makeEventsActions($eventids); // indicator of sort field if ($show_sort_indicator) { $sort_div = (new CDiv())->addClass($filter['sortorder'] === ZBX_SORT_DOWN ? ZBX_STYLE_ARROW_DOWN : ZBX_STYLE_ARROW_UP); } $table = (new CTableInfo())->setHeader([$show_sort_indicator && $filter['sortfield'] === 'hostname' ? [_('Host'), $sort_div] : _('Host'), $show_sort_indicator && $filter['sortfield'] === 'priority' ? [_('Issue'), $sort_div] : _('Issue'), $show_sort_indicator && $filter['sortfield'] === 'lastchange' ? [_('Last change'), $sort_div] : _('Last change'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions')]); $hostids = array_keys($hostids); $scripts = API::Script()->getScriptsByHosts($hostids); // get hosts $hosts = API::Host()->get(['hostids' => $hostids, 'output' => ['hostid', 'name', 'status', 'maintenance_status', 'maintenance_type', 'maintenanceid'], 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true]); $maintenanceids = []; foreach ($hosts as $host) { if ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) { $maintenanceids[$host['maintenanceid']] = true; } } if ($maintenanceids) { $maintenances = API::Maintenance()->get(['maintenanceids' => array_keys($maintenanceids), 'output' => ['name', 'description'], 'preservekeys' => true]); } // triggers foreach ($triggers as $trigger) { $host_list = []; foreach ($trigger['hosts'] as $trigger_host) { $host = $hosts[$trigger_host['hostid']]; $host_name = (new CSpan($host['name']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); if ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) { $maintenance_icon = (new CSpan())->addClass(ZBX_STYLE_ICON_MAINT)->addClass(ZBX_STYLE_CURSOR_POINTER); if (array_key_exists($host['maintenanceid'], $maintenances)) { $maintenance = $maintenances[$host['maintenanceid']]; $hint = $maintenance['name'] . ' [' . ($host['maintenance_type'] ? _('Maintenance without data collection') : _('Maintenance with data collection')) . ']'; if ($maintenance['description']) { $hint .= "\n" . $maintenance['description']; } $maintenance_icon->setHint($hint); } $host_name = (new CSpan([$host_name, $maintenance_icon]))->addClass(ZBX_STYLE_REL_CONTAINER); } $host_list[] = $host_name; $host_list[] = ', '; } array_pop($host_list); // unknown triggers $unknown = ''; if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) { $unknown = makeUnknownIcon($trigger['error']); } // trigger has events if ($trigger['lastEvent']) { // description $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $trigger['lastEvent']['clock'], 'ns' => $trigger['lastEvent']['ns']])); } else { // description $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $trigger['lastchange'], 'ns' => '999999999'])); } if ($config['event_ack_enable']) { if ($trigger['lastEvent']) { $trigger['lastEvent']['acknowledges'] = $event_acknowledges[$trigger['lastEvent']['eventid']]['acknowledges']; $ack = getEventAckState($trigger['lastEvent'], $backurl); } else { $ack = (new CSpan(_('No events')))->addClass(ZBX_STYLE_GREY); } } else { $ack = null; } // description if ($trigger['lastEvent'] || $trigger['comments'] !== '' || $trigger['url'] !== '') { $description = (new CSpan($description))->setHint(make_popup_eventlist($trigger, $backurl), '', true, 'max-width: 500px')->addClass(ZBX_STYLE_LINK_ACTION); } $description = (new CCol($description))->addClass(getSeverityStyle($trigger['priority'])); // clock $clock = new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $trigger['lastchange']), 'events.php?filter_set=1&triggerid=' . $trigger['triggerid'] . '&period=' . ZBX_PERIOD_DEFAULT . '&stime=' . date(TIMESTAMP_FORMAT, $trigger['lastchange'])); // actions $action_hint = $trigger['lastEvent'] && isset($actions[$trigger['lastEvent']['eventid']]) ? $actions[$trigger['lastEvent']['eventid']] : SPACE; $table->addRow([new CCol($host_list), $description, $clock, zbx_date2age($trigger['lastchange']), $unknown, $ack, (new CCol($action_hint))->addClass(ZBX_STYLE_NOWRAP)]); } // initialize blinking zbx_add_post_js('jqBlink.blink();'); $info = _n('%1$d of %2$d issue is shown', '%1$d of %2$d issues are shown', count($triggers), $triggers_total_count); return [$table, $info]; }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $output = []; $items = API::Item()->get(['output' => ['itemid', 'hostid', 'name', 'key_', 'value_type', 'valuemapid'], 'selectHosts' => ['name'], 'itemids' => $this->itemids, 'webitems' => true, 'preservekeys' => true]); $items = CMacrosResolverHelper::resolveItemNames($items); $stime = zbxDateToTime($this->timeline['stime']); $firstItem = reset($items); $iv_string = [ITEM_VALUE_TYPE_LOG => 1, ITEM_VALUE_TYPE_TEXT => 1]; $iv_numeric = [ITEM_VALUE_TYPE_FLOAT => 1, ITEM_VALUE_TYPE_UINT64 => 1]; if ($this->action == HISTORY_VALUES || $this->action == HISTORY_LATEST) { $options = ['history' => $firstItem['value_type'], 'itemids' => $this->itemids, 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN]; if ($this->action == HISTORY_LATEST) { $options['limit'] = 500; } elseif ($this->action == HISTORY_VALUES) { $config = select_config(); // interval start value is non-inclusive, hence the + 1 second $options['time_from'] = $stime + 1; $options['time_till'] = $stime + $this->timeline['period']; $options['limit'] = $config['search_limit']; } // text log if (isset($iv_string[$firstItem['value_type']])) { $isManyItems = count($items) > 1; $useLogItem = $firstItem['value_type'] == ITEM_VALUE_TYPE_LOG; $useEventLogItem = strpos($firstItem['key_'], 'eventlog[') === 0; if (empty($this->plaintext)) { $historyTable = (new CTableInfo())->setHeader([(new CColHeader(_('Timestamp')))->addClass(ZBX_STYLE_CELL_WIDTH), $isManyItems ? _('Item') : null, $useLogItem ? (new CColHeader(_('Local time')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Source')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Severity')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Event ID')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, _('Value')]); } if ($this->filter !== '' && in_array($this->filterTask, [FILTER_TASK_SHOW, FILTER_TASK_HIDE])) { $options['search'] = ['value' => $this->filter]; if ($this->filterTask == FILTER_TASK_HIDE) { $options['excludeSearch'] = 1; } } $options['sortfield'] = 'id'; $historyData = API::History()->get($options); foreach ($historyData as $data) { $data['value'] = rtrim($data['value'], " \t\r\n"); if (empty($this->plaintext)) { $item = $items[$data['itemid']]; $host = reset($item['hosts']); $color = null; if ($this->filter !== '') { $haystack = mb_strtolower($data['value']); $needle = mb_strtolower($this->filter); $pos = mb_strpos($haystack, $needle); if ($pos !== false && $this->filterTask == FILTER_TASK_MARK) { $color = $this->markColor; } elseif ($pos === false && $this->filterTask == FILTER_TASK_INVERT_MARK) { $color = $this->markColor; } switch ($color) { case MARK_COLOR_RED: $color = ZBX_STYLE_RED; break; case MARK_COLOR_GREEN: $color = ZBX_STYLE_GREEN; break; case MARK_COLOR_BLUE: $color = ZBX_STYLE_BLUE; break; } } $row = []; $row[] = (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock'])))->addClass(ZBX_STYLE_NOWRAP)->addClass($color); if ($isManyItems) { $row[] = (new CCol($host['name'] . NAME_DELIMITER . $item['name_expanded']))->addClass($color); } if ($useLogItem) { $row[] = $data['timestamp'] != 0 ? (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['timestamp'])))->addClass(ZBX_STYLE_NOWRAP)->addClass($color) : ''; // if this is a eventLog item, showing additional info if ($useEventLogItem) { $row[] = (new CCol($data['source']))->addClass(ZBX_STYLE_NOWRAP)->addClass($color); $row[] = $data['severity'] != 0 ? (new CCol(get_item_logtype_description($data['severity'])))->addClass(ZBX_STYLE_NOWRAP)->addClass(get_item_logtype_style($data['severity'])) : ''; $row[] = $data['logeventid'] != 0 ? (new CCol($data['logeventid']))->addClass(ZBX_STYLE_NOWRAP)->addClass($color) : ''; } } $row[] = (new CCol(new CPre(zbx_nl2br($data['value']))))->addClass($color); $historyTable->addRow($row); } else { $output[] = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock']) . ' ' . $data['clock'] . ' ' . htmlspecialchars($data['value']); } } if (empty($this->plaintext)) { $output[] = $historyTable; } } else { if (empty($this->plaintext)) { $historyTable = (new CTableInfo())->setHeader([(new CColHeader(_('Timestamp')))->addClass(ZBX_STYLE_CELL_WIDTH), _('Value')]); } $options['sortfield'] = ['itemid', 'clock']; $historyData = API::History()->get($options); foreach ($historyData as $data) { $item = $items[$data['itemid']]; $value = rtrim($data['value'], " \t\r\n"); // format the value as float if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT) { sscanf($data['value'], '%f', $value); } // html table if (empty($this->plaintext)) { if ($item['valuemapid']) { $value = applyValueMap($value, $item['valuemapid']); } $historyTable->addRow([(new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock'])))->addClass(ZBX_STYLE_NOWRAP), new CPre(zbx_nl2br($value))]); } else { $output[] = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock']) . ' ' . $data['clock'] . ' ' . htmlspecialchars($value); } } if (empty($this->plaintext)) { $output[] = $historyTable; } } } // time control if (!$this->plaintext && str_in_array($this->action, [HISTORY_VALUES, HISTORY_GRAPH, HISTORY_BATCH_GRAPH])) { $graphDims = getGraphDims(); $this->timeline['starttime'] = date(TIMESTAMP_FORMAT, get_min_itemclock_by_itemid($firstItem['itemid'])); $this->dataId = 'historyGraph'; $timeControlData = ['periodFixed' => CProfile::get('web.history.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD]; if (($this->action == HISTORY_GRAPH || $this->action == HISTORY_BATCH_GRAPH) && !isset($iv_string[$firstItem['value_type']])) { $containerId = 'graph_cont1'; $output[] = (new CDiv())->addClass('center')->setId($containerId); $timeControlData['id'] = $this->getDataId(); $timeControlData['containerid'] = $containerId; $timeControlData['src'] = $this->getGraphUrl($this->itemids); $timeControlData['objDims'] = $graphDims; $timeControlData['loadSBox'] = 1; $timeControlData['loadImage'] = 1; $timeControlData['dynamic'] = 1; } else { $timeControlData['id'] = $this->getDataId(); $timeControlData['mainObject'] = 1; } if ($this->mode == SCREEN_MODE_JS) { $timeControlData['dynamic'] = 0; return 'timeControl.addObject("' . $this->getDataId() . '", ' . CJs::encodeJson($this->timeline) . ', ' . CJs::encodeJson($timeControlData) . ');'; } else { zbx_add_post_js('timeControl.addObject("' . $this->getDataId() . '", ' . CJs::encodeJson($this->timeline) . ', ' . CJs::encodeJson($timeControlData) . ');'); } } if (!empty($this->plaintext)) { return $output; } else { if ($this->mode != SCREEN_MODE_JS) { $flickerfreeData = ['itemids' => $this->itemids, 'action' => $this->action == HISTORY_BATCH_GRAPH ? HISTORY_GRAPH : $this->action, 'filter' => $this->filter, 'filterTask' => $this->filterTask, 'markColor' => $this->markColor]; return $this->getOutput($output, true, $flickerfreeData); } } }
function update_config($configs) { $update = array(); if (isset($configs['work_period'])) { $timePeriodValidator = new CTimePeriodValidator(); if (!$timePeriodValidator->validate($configs['work_period'])) { error(_('Incorrect working time.')); return false; } } if (isset($configs['alert_usrgrpid'])) { if ($configs['alert_usrgrpid'] != 0 && !DBfetch(DBselect('SELECT u.usrgrpid FROM usrgrp u WHERE u.usrgrpid=' . zbx_dbstr($configs['alert_usrgrpid'])))) { error(_('Incorrect user group.')); return false; } } if (isset($configs['discovery_groupid'])) { $groupid = API::HostGroup()->get(array('groupids' => $configs['discovery_groupid'], 'output' => array('groupid'), 'preservekeys' => true)); if (empty($groupid)) { error(_('Incorrect host group.')); return false; } } // checking color values to be correct hexadecimal numbers $colors = array('severity_color_0', 'severity_color_1', 'severity_color_2', 'severity_color_3', 'severity_color_4', 'severity_color_5', 'problem_unack_color', 'problem_ack_color', 'ok_unack_color', 'ok_ack_color'); $colorvalidator = new CColorValidator(); foreach ($colors as $color) { if (isset($configs[$color]) && !is_null($configs[$color])) { if (!$colorvalidator->validate($configs[$color])) { error($colorvalidator->getError()); return false; } } } if (isset($configs['ok_period']) && !is_null($configs['ok_period']) && !ctype_digit($configs['ok_period'])) { error(_('"Display OK triggers" needs to be "0" or a positive integer.')); return false; } if (isset($configs['blink_period']) && !is_null($configs['blink_period']) && !ctype_digit($configs['blink_period'])) { error(_('"Triggers blink on status change" needs to be "0" or a positive integer.')); return false; } $currentConfig = select_config(); // check duplicate severity names and if name is empty. $names = array(); for ($i = 0; $i < TRIGGER_SEVERITY_COUNT; $i++) { $varName = 'severity_name_' . $i; if (!isset($configs[$varName]) || is_null($configs[$varName])) { $configs[$varName] = $currentConfig[$varName]; } if ($configs[$varName] == '') { error(_('Severity name cannot be empty.')); return false; } if (isset($names[$configs[$varName]])) { error(_s('Duplicate severity name "%s".', $configs[$varName])); return false; } else { $names[$configs[$varName]] = 1; } } foreach ($configs as $key => $value) { if (!is_null($value)) { if ($key == 'alert_usrgrpid') { $update[] = $key . '=' . ($value == '0' ? 'NULL' : $value); } else { $update[] = $key . '=' . zbx_dbstr($value); } } } if (count($update) == 0) { error(_('Nothing to do.')); return null; } return DBexecute('UPDATE config' . ' SET ' . implode(',', $update) . whereDbNode('configid', false)); }
public function __construct($options = array()) { global $ZBX_WITH_ALL_NODES; /* options = array( 'config' => {'DDFirst': [ allow_all, deny_all], select_latest: [true,false], 'individual': [true,false]}, 'groups' => [apiget filters], 'hosts' => [apiget filters], 'graphs' => [apiget filters], 'groupid' => groupid, 'hostid' => hostid, 'graphid' => graphid, 'triggerid' => triggerid ); */ $this->config['all_nodes'] = $ZBX_WITH_ALL_NODES; $this->config['select_latest'] = isset($options['config']['select_latest']); $config = select_config(); // Individual remember selections per page (not for menu) $this->config['individual'] = false; if (isset($options['config']['individual']) && !is_null($options['config']['individual'])) { $this->config['individual'] = true; } // DropDown $this->config['DDRemember'] = $config['dropdown_first_remember']; if (isset($options['config']['allow_all'])) { $this->config['DDFirst'] = ZBX_DROPDOWN_FIRST_ALL; } else { if (isset($options['config']['deny_all'])) { $this->config['DDFirst'] = ZBX_DROPDOWN_FIRST_NONE; } else { $this->config['DDFirst'] = $config['dropdown_first_entry']; } } // profiles $this->_getProfiles($options); if (!isset($options['groupid'], $options['hostid'])) { if (isset($options['graphid'])) { $this->_updateByGraph($options); } else { if (isset($options['triggerid'])) { $this->_updateByTrigger($options); } } } if (!isset($options['groupid'])) { if (isset($options['hostid'])) { $this->_updateByHost($options); } } // groups if (isset($options['groups'])) { if (!isset($options['groupid']) && isset($options['hostid'])) { $options['groupid'] = 0; } $this->_initGroups($options['groupid'], $options['groups']); } // hosts if (isset($options['hosts'])) { $this->_initHosts($options['hostid'], $options['hosts']); } // graphs if (isset($options['graphs'])) { $this->_initGraphs($options['graphid'], $options['graphs']); } // triggers if (isset($options['triggers'])) { $this->_initTriggers($options['triggerid'], $options['triggers']); } }
function getTriggerMassupdateFormData() { $data = array('visible' => getRequest('visible', array()), 'priority' => getRequest('priority', ''), 'dependencies' => getRequest('dependencies', array()), 'massupdate' => getRequest('massupdate', 1), 'parent_discoveryid' => getRequest('parent_discoveryid'), 'g_triggerid' => getRequest('g_triggerid', array()), 'priority' => getRequest('priority', 0), 'config' => select_config(), 'hostid' => getRequest('hostid', 0)); // get dependencies $data['dependencies'] = API::Trigger()->get(array('triggerids' => $data['dependencies'], 'output' => array('triggerid', 'flags', 'description'), 'preservekeys' => true, 'selectHosts' => array('hostid', 'name'))); foreach ($data['dependencies'] as &$dependency) { if (count($dependency['hosts']) > 1) { order_result($dependency['hosts'], 'name', ZBX_SORT_UP); } $dependency['hosts'] = array_values($dependency['hosts']); $dependency['hostid'] = $dependency['hosts'][0]['hostid']; } unset($dependency); order_result($data['dependencies'], 'description'); return $data; }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $output = array(); $stime = zbxDateToTime($this->timeline['stime']); $iv_string = array(ITEM_VALUE_TYPE_LOG => 1, ITEM_VALUE_TYPE_TEXT => 1); $iv_numeric = array(ITEM_VALUE_TYPE_FLOAT => 1, ITEM_VALUE_TYPE_UINT64 => 1); if ($this->action == 'showvalues' || $this->action == 'showlatest') { $options = array('history' => $this->item['value_type'], 'itemids' => array_keys($this->items), 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN); if ($this->action == 'showlatest') { $options['limit'] = 500; } elseif ($this->action == 'showvalues') { $config = select_config(); $options['time_from'] = $stime - 10; // some seconds to allow script to execute $options['time_till'] = $stime + $this->timeline['period']; $options['limit'] = $config['search_limit']; } // text log if (isset($iv_string[$this->item['value_type']])) { $isManyItems = count($this->items) > 1; $useLogItem = $this->item['value_type'] == ITEM_VALUE_TYPE_LOG; $useEventLogItem = strpos($this->item['key_'], 'eventlog[') === 0; if (empty($this->plaintext)) { $historyTable = new CTableInfo(_('No values found.')); $historyTable->setHeader(array(_('Timestamp'), $isManyItems ? _('Item') : null, $useLogItem ? _('Local time') : null, $useEventLogItem && $useLogItem ? _('Source') : null, $useEventLogItem && $useLogItem ? _('Severity') : null, $useEventLogItem && $useLogItem ? _('Event ID') : null, _('Value')), 'header'); } if (!zbx_empty($this->filter) && in_array($this->filterTask, array(FILTER_TASK_SHOW, FILTER_TASK_HIDE))) { $options['search'] = array('value' => $this->filter); if ($this->filterTask == FILTER_TASK_HIDE) { $options['excludeSearch'] = 1; } } $options['sortfield'] = 'id'; $historyData = API::History()->get($options); foreach ($historyData as $data) { $data['value'] = encode_log(trim($data['value'], "\r\n")); if (empty($this->plaintext)) { $item = $this->items[$data['itemid']]; $host = reset($item['hosts']); $color = null; if (isset($this->filter) && !zbx_empty($this->filter)) { $contain = zbx_stristr($data['value'], $this->filter); if ($contain && $this->filterTask == FILTER_TASK_MARK) { $color = $this->markColor; } if (!$contain && $this->filterTask == FILTER_TASK_INVERT_MARK) { $color = $this->markColor; } switch ($color) { case MARK_COLOR_RED: $color = 'red'; break; case MARK_COLOR_GREEN: $color = 'green'; break; case MARK_COLOR_BLUE: $color = 'blue'; break; } } $row = array(nbsp(zbx_date2str(_('Y.M.d H:i:s'), $data['clock']))); if ($isManyItems) { $row[] = $host['name'] . NAME_DELIMITER . $item['name_expanded']; } if ($useLogItem) { $row[] = $data['timestamp'] == 0 ? '-' : zbx_date2str(HISTORY_LOG_LOCALTIME_DATE_FORMAT, $data['timestamp']); // if this is a eventLog item, showing additional info if ($useEventLogItem) { $row[] = zbx_empty($data['source']) ? '-' : $data['source']; $row[] = $data['severity'] == 0 ? '-' : new CCol(get_item_logtype_description($data['severity']), get_item_logtype_style($data['severity'])); $row[] = $data['logeventid'] == 0 ? '-' : $data['logeventid']; } } $row[] = new CCol($data['value'], 'pre'); $newRow = new CRow($row); if (!is_null($color)) { $newRow->setAttribute('class', $color); } $historyTable->addRow($newRow); } else { $output[] = zbx_date2str(HISTORY_LOG_ITEM_PLAINTEXT, $data['clock']); $output[] = "\t" . $data['clock'] . "\t" . htmlspecialchars($data['value']) . "\n"; } } if (empty($this->plaintext)) { $output[] = $historyTable; } } else { if (empty($this->plaintext)) { $historyTable = new CTableInfo(_('No values found.')); $historyTable->setHeader(array(_('Timestamp'), _('Value'))); } $options['sortfield'] = array('itemid', 'clock'); $historyData = API::History()->get($options); foreach ($historyData as $data) { $item = $this->items[$data['itemid']]; $value = $data['value']; // format the value as float if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT) { sscanf($data['value'], '%f', $value); } // html table if (empty($this->plaintext)) { if ($item['valuemapid']) { $value = applyValueMap($value, $item['valuemapid']); } $historyTable->addRow(array(zbx_date2str(HISTORY_ITEM_DATE_FORMAT, $data['clock']), zbx_nl2br($value))); } else { $output[] = zbx_date2str(HISTORY_PLAINTEXT_DATE_FORMAT, $data['clock']); $output[] = "\t" . $data['clock'] . "\t" . htmlspecialchars($value) . "\n"; } } if (empty($this->plaintext)) { $output[] = $historyTable; } } } if ($this->action == 'showgraph' && !isset($iv_string[$this->item['value_type']])) { $this->dataId = 'historyGraph'; $containerId = 'graph_cont1'; $src = 'chart.php?itemid=' . $this->item['itemid'] . '&period=' . $this->timeline['period'] . '&stime=' . $this->timeline['stime'] . $this->getProfileUrlParams(); $output[] = new CDiv(null, 'center', $containerId); } // time control if (!$this->plaintext && str_in_array($this->action, array('showvalues', 'showgraph'))) { $graphDims = getGraphDims(); $this->timeline['starttime'] = date(TIMESTAMP_FORMAT, get_min_itemclock_by_itemid($this->item['itemid'])); $timeControlData = array('periodFixed' => CProfile::get('web.history.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD); if (!empty($this->dataId)) { $timeControlData['id'] = $this->getDataId(); $timeControlData['containerid'] = $containerId; $timeControlData['src'] = $src; $timeControlData['objDims'] = $graphDims; $timeControlData['loadSBox'] = 1; $timeControlData['loadImage'] = 1; $timeControlData['dynamic'] = 1; } else { $this->dataId = 'historyGraph'; $timeControlData['id'] = $this->getDataId(); $timeControlData['mainObject'] = 1; } if ($this->mode == SCREEN_MODE_JS) { $timeControlData['dynamic'] = 0; return 'timeControl.addObject("' . $this->getDataId() . '", ' . zbx_jsvalue($this->timeline) . ', ' . zbx_jsvalue($timeControlData) . ');'; } else { zbx_add_post_js('timeControl.addObject("' . $this->getDataId() . '", ' . zbx_jsvalue($this->timeline) . ', ' . zbx_jsvalue($timeControlData) . ');'); } } if (!empty($this->plaintext)) { return $output; } else { if ($this->mode != SCREEN_MODE_JS) { $flickerfreeData = array('itemids' => $this->itemids, 'action' => $this->action, 'filter' => $this->filter, 'filterTask' => $this->filterTask, 'markColor' => $this->markColor); return $this->getOutput($output, true, $flickerfreeData); } } }
check_fields($fields); $config = getRequest('config', CProfile::get('web.queue.config', 0)); CProfile::update('web.queue.config', $config, PROFILE_TYPE_INT); // fetch data $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); $queueRequests = [QUEUE_OVERVIEW => CZabbixServer::QUEUE_OVERVIEW, QUEUE_OVERVIEW_BY_PROXY => CZabbixServer::QUEUE_OVERVIEW_BY_PROXY, QUEUE_DETAILS => CZabbixServer::QUEUE_DETAILS]; $queueData = $zabbixServer->getQueue($queueRequests[$config], get_cookie('zbx_sessionid')); // check for errors error if ($zabbixServer->getError()) { error($zabbixServer->getError()); show_error_message(_('Cannot display item queue.')); require_once dirname(__FILE__) . '/include/page_footer.php'; } $widget = (new CWidget())->setTitle(_('Queue of items to be updated'))->setControls((new CForm('get'))->cleanItems()->addItem((new CList())->addItem((new CComboBox('config', $config, 'submit();'))->addItem(QUEUE_OVERVIEW, _('Overview'))->addItem(QUEUE_OVERVIEW_BY_PROXY, _('Overview by proxy'))->addItem(QUEUE_DETAILS, _('Details'))))); $table = new CTableInfo(); $severityConfig = select_config(); // overview if ($config == QUEUE_OVERVIEW) { $itemTypes = [ITEM_TYPE_ZABBIX, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_SIMPLE, ITEM_TYPE_SNMPV1, ITEM_TYPE_SNMPV2C, ITEM_TYPE_SNMPV3, ITEM_TYPE_INTERNAL, ITEM_TYPE_AGGREGATE, ITEM_TYPE_EXTERNAL, ITEM_TYPE_DB_MONITOR, ITEM_TYPE_IPMI, ITEM_TYPE_SSH, ITEM_TYPE_TELNET, ITEM_TYPE_JMX, ITEM_TYPE_CALCULATED]; $table->setHeader([_('Items'), _('5 seconds'), _('10 seconds'), _('30 seconds'), _('1 minute'), _('5 minutes'), _('More than 10 minutes')]); $queueData = zbx_toHash($queueData, 'itemtype'); foreach ($itemTypes as $type) { if (isset($queueData[$type])) { $itemTypeData = $queueData[$type]; } else { $itemTypeData = ['delay5' => 0, 'delay10' => 0, 'delay30' => 0, 'delay60' => 0, 'delay300' => 0, 'delay600' => 0]; } $table->addRow([item_type2str($type), getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $severityConfig, $itemTypeData['delay5'], !$itemTypeData['delay5']), getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $severityConfig, $itemTypeData['delay10'], !$itemTypeData['delay10']), getSeverityCell(TRIGGER_SEVERITY_WARNING, $severityConfig, $itemTypeData['delay30'], !$itemTypeData['delay30']), getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $severityConfig, $itemTypeData['delay60'], !$itemTypeData['delay60']), getSeverityCell(TRIGGER_SEVERITY_HIGH, $severityConfig, $itemTypeData['delay300'], !$itemTypeData['delay300']), getSeverityCell(TRIGGER_SEVERITY_DISASTER, $severityConfig, $itemTypeData['delay600'], !$itemTypeData['delay600'])]); } } elseif ($config == QUEUE_OVERVIEW_BY_PROXY) { $proxies = API::proxy()->get(['output' => ['hostid', 'host'], 'preservekeys' => true]);
/** * Create element with event acknowledges info. * If $event has subarray 'acknowledges', returned link will have hint with acknowledges. * * @param array $event event data * @param int $event['acknowledged'] * @param int $event['eventid'] * @param int $event['objectid'] * @param array $event['acknowledges'] * @param bool|string $backUrl if true, add backurl param to link with current page file name * @param bool $isLink if true, return link otherwise span * @param array $params additional params for link * * @return array|CLink|CSpan|null|string */ function getEventAckState($event, $backUrl = false, $isLink = true, $params = array()) { $config = select_config(); if (!$config['event_ack_enable']) { return null; } if ($isLink) { if (!empty($backUrl)) { if (is_bool($backUrl)) { global $page; $backurl = '&backurl=' . $page['file']; } else { $backurl = '&backurl=' . $backUrl; } } else { $backurl = ''; } $additionalParams = ''; foreach ($params as $key => $value) { $additionalParams .= '&' . $key . '=' . $value; } if ($event['acknowledged'] == 0) { $ack = new CLink(_('No'), 'acknow.php?eventid=' . $event['eventid'] . '&triggerid=' . $event['objectid'] . $backurl . $additionalParams, 'disabled'); } else { $ackLink = new CLink(_('Yes'), 'acknow.php?eventid=' . $event['eventid'] . '&triggerid=' . $event['objectid'] . $backurl . $additionalParams, 'enabled'); if (is_array($event['acknowledges'])) { $ackLinkHints = makeAckTab($event); if (!empty($ackLinkHints)) { $ackLink->setHint($ackLinkHints, '', '', false); } $ack = array($ackLink, ' (' . count($event['acknowledges']) . ')'); } else { $ack = array($ackLink, ' (' . $event['acknowledges'] . ')'); } } } else { if ($event['acknowledged'] == 0) { $ack = new CSpan(_('No'), 'on'); } else { $ack = array(new CSpan(_('Yes'), 'off'), ' (' . (is_array($event['acknowledges']) ? count($event['acknowledges']) : $event['acknowledges']) . ')'); } } return $ack; }
function get_triggers_unacknowledged($db_element, $count_problems = null, $ack = false) { $elements = array('hosts' => array(), 'hosts_groups' => array(), 'triggers' => array()); get_map_elements($db_element, $elements); if (empty($elements['hosts_groups']) && empty($elements['hosts']) && empty($elements['triggers'])) { return 0; } $config = select_config(); $options = array('nodeids' => get_current_nodeid(), 'monitored' => true, 'countOutput' => true, 'filter' => array(), 'limit' => $config['search_limit'] + 1); if ($ack) { $options['withAcknowledgedEvents'] = 1; } else { $options['withUnacknowledgedEvents'] = 1; } if ($count_problems) { $options['filter']['value'] = TRIGGER_VALUE_TRUE; } if (!empty($elements['hosts_groups'])) { $options['groupids'] = array_unique($elements['hosts_groups']); } if (!empty($elements['hosts'])) { $options['hostids'] = array_unique($elements['hosts']); } if (!empty($elements['triggers'])) { $options['triggerids'] = array_unique($elements['triggers']); } return API::Trigger()->get($options); }
/** * Delete UserGroups. * * @param array $usrgrpids * @return boolean */ public function delete($usrgrpids) { $usrgrpids = zbx_toArray($usrgrpids); $dbUsrgrps = $this->get(array('output' => array('usrgrpid', 'name'), 'usrgrpids' => $usrgrpids, 'preservekeys' => true)); if (empty($usrgrpids)) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.')); } if (USER_TYPE_SUPER_ADMIN != self::$userData['type']) { // GETTEXT: API exception self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only Super Admins can delete user groups.')); } // check, if this user group is used in one of the scripts. If so, it cannot be deleted $dbScripts = API::Script()->get(array('output' => array('scriptid', 'name', 'usrgrpid'), 'usrgrpids' => $usrgrpids, 'nopermissions' => true)); if (!empty($dbScripts)) { foreach ($dbScripts as $snum => $script) { if ($script['usrgrpid'] == 0) { continue; } self::exception(ZBX_API_ERROR_PARAMETERS, _s('User group "%1$s" is used in script "%2$s".', $dbUsrgrps[$script['usrgrpid']]['name'], $script['name'])); } } // check, if this user group is used in the config. If so, it cannot be deleted $config = select_config(); if (isset($dbUsrgrps[$config['alert_usrgrpid']])) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('User group [%s] is used in configuration for database down messages.', $dbUsrgrps[$config['alert_usrgrpid']]['name'])); } // delete action operation msg $operationids = array(); $sql = 'SELECT DISTINCT om.operationid' . ' FROM opmessage_grp om' . ' WHERE ' . dbConditionInt('om.usrgrpid', $usrgrpids); $dbOperations = DBselect($sql); while ($dbOperation = DBfetch($dbOperations)) { $operationids[$dbOperation['operationid']] = $dbOperation['operationid']; } DB::delete('opmessage_grp', array('usrgrpid' => $usrgrpids)); // delete empty operations $delOperationids = array(); $sql = 'SELECT DISTINCT o.operationid' . ' FROM operations o' . ' WHERE ' . dbConditionInt('o.operationid', $operationids) . ' AND NOT EXISTS(SELECT om.opmessage_grpid FROM opmessage_grp om WHERE om.operationid=o.operationid)'; $dbOperations = DBselect($sql); while ($dbOperation = DBfetch($dbOperations)) { $delOperationids[$dbOperation['operationid']] = $dbOperation['operationid']; } DB::delete('operations', array('operationid' => $delOperationids)); DB::delete('rights', array('groupid' => $usrgrpids)); DB::delete('users_groups', array('usrgrpid' => $usrgrpids)); DB::delete('usrgrp', array('usrgrpid' => $usrgrpids)); return array('usrgrpids' => $usrgrpids); }
function validate_group(&$PAGE_GROUPS, &$PAGE_HOSTS, $reset_host = true) { global $page; $config = select_config(); $dd_first_entry = $config['dropdown_first_entry']; $group_var = 'web.latest.groupid'; $host_var = 'web.latest.hostid'; $_REQUEST['groupid'] = get_request('groupid', CProfile::get($group_var, -1)); if ($_REQUEST['groupid'] < 0) { $PAGE_GROUPS['selected'] = $_REQUEST['groupid'] = 0; $PAGE_HOSTS['selected'] = $_REQUEST['hostid'] = 0; } if (!isset($_REQUEST['hostid']) || $reset_host) { $PAGE_HOSTS['selected'] = $_REQUEST['hostid'] = 0; } if ($PAGE_GROUPS['selected'] == 0 && $dd_first_entry == ZBX_DROPDOWN_FIRST_NONE) { $PAGE_GROUPS['groupids'] = array(); } $PAGE_GROUPS['selected'] = $_REQUEST['groupid']; if ($PAGE_GROUPS['original'] > -1) { CProfile::update('web.' . $page['menu'] . '.groupid', $_REQUEST['groupid'], PROFILE_TYPE_ID); } if ($PAGE_HOSTS['original'] > -1) { CProfile::update('web.' . $page['menu'] . '.hostid', $_REQUEST['hostid'], PROFILE_TYPE_ID); } CProfile::update($group_var, $_REQUEST['groupid'], PROFILE_TYPE_ID); CProfile::update($host_var, $_REQUEST['hostid'], PROFILE_TYPE_ID); }
/** * Get Triggers data. * * @param array $options * @param array $options['itemids'] * @param array $options['hostids'] * @param array $options['groupids'] * @param array $options['triggerids'] * @param array $options['applicationids'] * @param array $options['status'] * @param array $options['editable'] * @param array $options['count'] * @param array $options['pattern'] * @param array $options['limit'] * @param array $options['order'] * * @return array|int item data as array or false if error */ public function get(array $options = []) { $result = []; $userType = self::$userData['type']; $userid = self::$userData['userid']; $sqlParts = ['select' => ['triggers' => 't.triggerid'], 'from' => ['t' => 'triggers t'], 'where' => [], 'group' => [], 'order' => [], 'limit' => null]; $defOptions = ['groupids' => null, 'templateids' => null, 'hostids' => null, 'triggerids' => null, 'itemids' => null, 'applicationids' => null, 'functions' => null, 'inherited' => null, 'templated' => null, 'monitored' => null, 'active' => null, 'maintenance' => null, 'withUnacknowledgedEvents' => null, 'withAcknowledgedEvents' => null, 'withLastEventUnacknowledged' => null, 'skipDependent' => null, 'nopermissions' => null, 'editable' => null, 'lastChangeSince' => null, 'lastChangeTill' => null, 'group' => null, 'host' => null, 'only_true' => null, 'min_severity' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'expandDescription' => null, 'expandComment' => null, 'expandExpression' => null, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => null, 'selectHosts' => null, 'selectItems' => null, 'selectFunctions' => null, 'selectDependencies' => null, 'selectDiscoveryRule' => null, 'selectLastEvent' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null, 'limitSelects' => null]; $options = zbx_array_merge($defOptions, $options); // editable + PERMISSION CHECK if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) { $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ; $userGroups = getUserGroupsByUserId($userid); $sqlParts['where'][] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' LEFT JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE t.triggerid=f.triggerid ' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY i.hostid' . ' HAVING MAX(permission)<' . zbx_dbstr($permission) . ' OR MIN(permission) IS NULL' . ' OR MIN(permission)=' . PERM_DENY . ')'; } // groupids if (!is_null($options['groupids'])) { zbx_value2array($options['groupids']); sort($options['groupids']); $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items'] = 'items i'; $sqlParts['from']['hosts_groups'] = 'hosts_groups hg'; $sqlParts['where']['hgi'] = 'hg.hostid=i.hostid'; $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fi'] = 'f.itemid=i.itemid'; $sqlParts['where']['groupid'] = dbConditionInt('hg.groupid', $options['groupids']); if (!is_null($options['groupCount'])) { $sqlParts['group']['hg'] = 'hg.groupid'; } } // templateids if (!is_null($options['templateids'])) { zbx_value2array($options['templateids']); if (!is_null($options['hostids'])) { zbx_value2array($options['hostids']); $options['hostids'] = array_merge($options['hostids'], $options['templateids']); } else { $options['hostids'] = $options['templateids']; } } // hostids if (!is_null($options['hostids'])) { zbx_value2array($options['hostids']); $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items'] = 'items i'; $sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['hostids']); $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fi'] = 'f.itemid=i.itemid'; if (!is_null($options['groupCount'])) { $sqlParts['group']['i'] = 'i.hostid'; } } // triggerids if (!is_null($options['triggerids'])) { zbx_value2array($options['triggerids']); $sqlParts['where']['triggerid'] = dbConditionInt('t.triggerid', $options['triggerids']); } // itemids if (!is_null($options['itemids'])) { zbx_value2array($options['itemids']); $sqlParts['from']['functions'] = 'functions f'; $sqlParts['where']['itemid'] = dbConditionInt('f.itemid', $options['itemids']); $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; if (!is_null($options['groupCount'])) { $sqlParts['group']['f'] = 'f.itemid'; } } // applicationids if (!is_null($options['applicationids'])) { zbx_value2array($options['applicationids']); $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items_applications'] = 'items_applications ia'; $sqlParts['where']['a'] = dbConditionInt('ia.applicationid', $options['applicationids']); $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fia'] = 'f.itemid=ia.itemid'; } // functions if (!is_null($options['functions'])) { zbx_value2array($options['functions']); $sqlParts['from']['functions'] = 'functions f'; $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where'][] = dbConditionString('f.function', $options['functions']); } // monitored if (!is_null($options['monitored'])) { $sqlParts['where']['monitored'] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts h' . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=h.hostid' . ' AND (' . 'i.status<>' . ITEM_STATUS_ACTIVE . ' OR h.status<>' . HOST_STATUS_MONITORED . ')' . ')'; $sqlParts['where']['status'] = 't.status=' . TRIGGER_STATUS_ENABLED; } // active if (!is_null($options['active'])) { $sqlParts['where']['active'] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts h' . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=h.hostid' . ' AND h.status<>' . HOST_STATUS_MONITORED . ')'; $sqlParts['where']['status'] = 't.status=' . TRIGGER_STATUS_ENABLED; } // maintenance if (!is_null($options['maintenance'])) { $sqlParts['where'][] = ($options['maintenance'] == 0 ? 'NOT ' : '') . 'EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts h' . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=h.hostid' . ' AND h.maintenance_status=' . HOST_MAINTENANCE_STATUS_ON . ')'; $sqlParts['where'][] = 't.status=' . TRIGGER_STATUS_ENABLED; } // lastChangeSince if (!is_null($options['lastChangeSince'])) { $sqlParts['where']['lastchangesince'] = 't.lastchange>' . zbx_dbstr($options['lastChangeSince']); } // lastChangeTill if (!is_null($options['lastChangeTill'])) { $sqlParts['where']['lastchangetill'] = 't.lastchange<' . zbx_dbstr($options['lastChangeTill']); } // withUnacknowledgedEvents if (!is_null($options['withUnacknowledgedEvents'])) { $sqlParts['where']['unack'] = 'EXISTS (' . 'SELECT NULL' . ' FROM events e' . ' WHERE t.triggerid=e.objectid' . ' AND e.source=' . EVENT_SOURCE_TRIGGERS . ' AND e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' AND e.acknowledged=' . EVENT_NOT_ACKNOWLEDGED . ')'; } // withAcknowledgedEvents if (!is_null($options['withAcknowledgedEvents'])) { $sqlParts['where']['ack'] = 'NOT EXISTS (' . 'SELECT NULL' . ' FROM events e' . ' WHERE e.objectid=t.triggerid' . ' AND e.source=' . EVENT_SOURCE_TRIGGERS . ' AND e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' AND e.acknowledged=' . EVENT_NOT_ACKNOWLEDGED . ')'; } // templated if (!is_null($options['templated'])) { $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items'] = 'items i'; $sqlParts['from']['hosts'] = 'hosts h'; $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fi'] = 'f.itemid=i.itemid'; $sqlParts['where']['hi'] = 'h.hostid=i.hostid'; if ($options['templated']) { $sqlParts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE; } else { $sqlParts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE; } } // inherited if (!is_null($options['inherited'])) { if ($options['inherited']) { $sqlParts['where'][] = 't.templateid IS NOT NULL'; } else { $sqlParts['where'][] = 't.templateid IS NULL'; } } // search if (is_array($options['search'])) { zbx_db_search('triggers t', $options, $sqlParts); } // filter if (is_null($options['filter'])) { $options['filter'] = []; } if (is_array($options['filter'])) { if (!array_key_exists('flags', $options['filter'])) { $options['filter']['flags'] = [ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED]; } $this->dbFilter('triggers t', $options, $sqlParts); if (isset($options['filter']['host']) && !is_null($options['filter']['host'])) { zbx_value2array($options['filter']['host']); $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items'] = 'items i'; $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fi'] = 'f.itemid=i.itemid'; $sqlParts['from']['hosts'] = 'hosts h'; $sqlParts['where']['hi'] = 'h.hostid=i.hostid'; $sqlParts['where']['host'] = dbConditionString('h.host', $options['filter']['host']); } if (isset($options['filter']['hostid']) && !is_null($options['filter']['hostid'])) { zbx_value2array($options['filter']['hostid']); $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items'] = 'items i'; $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fi'] = 'f.itemid=i.itemid'; $sqlParts['where']['hostid'] = dbConditionInt('i.hostid', $options['filter']['hostid']); } } // group if (!is_null($options['group'])) { $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items'] = 'items i'; $sqlParts['from']['hosts_groups'] = 'hosts_groups hg'; $sqlParts['from']['groups'] = 'groups g'; $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fi'] = 'f.itemid=i.itemid'; $sqlParts['where']['hgi'] = 'hg.hostid=i.hostid'; $sqlParts['where']['ghg'] = 'g.groupid = hg.groupid'; $sqlParts['where']['group'] = ' g.name=' . zbx_dbstr($options['group']); } // host if (!is_null($options['host'])) { $sqlParts['from']['functions'] = 'functions f'; $sqlParts['from']['items'] = 'items i'; $sqlParts['from']['hosts'] = 'hosts h'; $sqlParts['where']['ft'] = 'f.triggerid=t.triggerid'; $sqlParts['where']['fi'] = 'f.itemid=i.itemid'; $sqlParts['where']['hi'] = 'h.hostid=i.hostid'; $sqlParts['where']['host'] = ' h.host=' . zbx_dbstr($options['host']); } // only_true if (!is_null($options['only_true'])) { $config = select_config(); $sqlParts['where']['ot'] = '((t.value=' . TRIGGER_VALUE_TRUE . ')' . ' OR ' . '((t.value=' . TRIGGER_VALUE_FALSE . ') AND (t.lastchange>' . (time() - $config['ok_period']) . ')))'; } // min_severity if (!is_null($options['min_severity'])) { $sqlParts['where'][] = 't.priority>=' . zbx_dbstr($options['min_severity']); } // limit if (!zbx_ctype_digit($options['limit']) || !$options['limit']) { $options['limit'] = null; } $sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts); $sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts); // return count or grouped counts via direct SQL count if (!is_null($options['countOutput']) && !$this->requiresPostSqlFiltering($options)) { $dbRes = DBselect($this->createSelectQueryFromParts($sqlParts), $options['limit']); while ($trigger = DBfetch($dbRes)) { if (!is_null($options['groupCount'])) { $result[] = $trigger; } else { $result = $trigger['rowscount']; } } return $result; } $result = zbx_toHash($this->customFetch($this->createSelectQueryFromParts($sqlParts), $options), 'triggerid'); // return count for post SQL filtered result sets if (!is_null($options['countOutput'])) { return count($result); } if ($result) { $result = $this->addRelatedObjects($options, $result); } // expandDescription if (!is_null($options['expandDescription']) && $result && array_key_exists('description', reset($result))) { $result = CMacrosResolverHelper::resolveTriggerNames($result); } // expandComment if (!is_null($options['expandComment']) && $result && array_key_exists('comments', reset($result))) { $result = CMacrosResolverHelper::resolveTriggerDescriptions($result); } // expand expression if ($options['expandExpression'] !== null && $result && array_key_exists('expression', reset($result))) { $result = CMacrosResolverHelper::resolveTriggerExpressions($result, ['resolve_usermacros' => true, 'resolve_macros' => true]); } // removing keys (hash -> array) if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } $result = $this->unsetExtraFields($result, ['state', 'expression'], $options['output']); return $result; }
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; }
if ($this->data['is_discovery_rule']) { $itemFormList->addRow(_('Keep lost resources period (in days)'), new CTextBox('lifetime', $this->data['lifetime'], ZBX_TEXTBOX_SMALL_SIZE, false, 64)); // append filter to formlist if (!empty($this->data['filter'])) { // exploding filter to two parts: before first ':' and after $pos = zbx_strpos($this->data['filter'], ':'); $filter_macro = zbx_substr($this->data['filter'], 0, $pos); $filter_value = zbx_substr($this->data['filter'], $pos + 1); } else { $filter_macro = ''; $filter_value = ''; } $itemFormList->addRow(_('Filter'), array(_('Macro'), SPACE, new CTextBox('filter_macro', $filter_macro, 13), SPACE, _('Regexp'), SPACE, new CTextBox('filter_value', $filter_value, 20))); $itemFormList->addRow(_('Allowed hosts'), new CTextBox('trapper_hosts', $this->data['trapper_hosts'], ZBX_TEXTBOX_STANDARD_SIZE), false, 'row_trapper_hosts'); } else { $dataConfig = select_config(); $keepHistory = array(); $keepHistory[] = new CNumericBox('history', $this->data['history'], 8); if ($dataConfig['hk_history_global'] && !$data['parent_discoveryid'] && !$data['is_template']) { $keepHistory[] = SPACE; if (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) { $keepHistory[] = new CSpan(_x('Overridden by', 'item_form')); $keepHistory[] = SPACE; $link = new CLink(_x('global housekeeping settings', 'item_form'), 'adm.housekeeper.php'); $link->setAttribute('target', '_blank'); $keepHistory[] = $link; $keepHistory[] = SPACE; $keepHistory[] = new CSpan('(' . _n('%1$s day', '%1$s days', $dataConfig['hk_history']) . ')'); } else { $keepHistory[] = new CSpan(_('Overriden by global housekeeping settings') . '(' . _n('%1$s day', '%1$s days', $dataConfig['hk_history']) . ')'); }
function drawMapHighligts(&$im, $map, $mapInfo) { $selements = $map['selements']; foreach ($selements as $selementId => $selement) { if (isset($selement['elementsubtype']) && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) { continue; } $elementInfo = $mapInfo[$selementId]; $img = get_png_by_selement($elementInfo); $iconX = imagesx($img); $iconY = imagesy($img); if ($map['highlight'] % 2 == SYSMAP_HIGHLIGHT_ON) { $hl_color = null; $st_color = null; if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_ON) { $hl_color = hex2rgb(getSeverityColor($elementInfo['priority'])); } if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_MAINTENANCE) { $st_color = hex2rgb('FF9933'); } if ($elementInfo['icon_type'] == SYSMAP_ELEMENT_ICON_DISABLED) { $st_color = hex2rgb('EEEEEE'); } $mainProblems = array(SYSMAP_ELEMENT_TYPE_HOST_GROUP => 1, SYSMAP_ELEMENT_TYPE_MAP => 1); if (isset($mainProblems[$selement['elementtype']])) { if (!is_null($hl_color)) { $st_color = null; } } elseif (!is_null($st_color)) { $hl_color = null; } if (!is_null($st_color)) { $r = $st_color[0]; $g = $st_color[1]; $b = $st_color[2]; imagefilledrectangle($im, $selement['x'] - 2, $selement['y'] - 2, $selement['x'] + $iconX + 2, $selement['y'] + $iconY + 2, imagecolorallocatealpha($im, $r, $g, $b, 0)); // shadow imagerectangle($im, $selement['x'] - 2 - 1, $selement['y'] - 2 - 1, $selement['x'] + $iconX + 2 + 1, $selement['y'] + $iconY + 2 + 1, imagecolorallocate($im, 120, 120, 120)); imagerectangle($im, $selement['x'] - 2 - 2, $selement['y'] - 2 - 2, $selement['x'] + $iconX + 2 + 2, $selement['y'] + $iconY + 2 + 2, imagecolorallocate($im, 220, 220, 220)); } if (!is_null($hl_color)) { $r = $hl_color[0]; $g = $hl_color[1]; $b = $hl_color[2]; imagefilledellipse($im, $selement['x'] + $iconX / 2, $selement['y'] + $iconY / 2, $iconX + 20, $iconX + 20, imagecolorallocatealpha($im, $r, $g, $b, 0)); imageellipse($im, $selement['x'] + $iconX / 2, $selement['y'] + $iconY / 2, $iconX + 20 + 1, $iconX + 20 + 1, imagecolorallocate($im, 120, 120, 120)); $config = select_config(); if (isset($elementInfo['ack']) && $elementInfo['ack'] && $config['event_ack_enable']) { imagesetthickness($im, 5); imagearc($im, $selement['x'] + $iconX / 2, $selement['y'] + $iconY / 2, $iconX + 20 - 3, $iconX + 20 - 3, 0, 359, imagecolorallocate($im, 50, 150, 50)); imagesetthickness($im, 1); } } } } }
/** * Returns paging line. * * @param array $items list of items * * @return CTable */ function getPagingLine(&$items) { global $page; $config = select_config(); $searchLimit = ''; if ($config['search_limit'] < count($items)) { array_pop($items); $searchLimit = '+'; } $rowsPerPage = CWebUser::$data['rows_per_page']; $itemsCount = count($items); $pagesCount = $itemsCount > 0 ? ceil($itemsCount / $rowsPerPage) : 1; $currentPage = getPageNumber(); if ($currentPage < 1) { $currentPage = 1; } if ($itemsCount < ($currentPage - 1) * $rowsPerPage) { $currentPage = $pagesCount; } $start = ($currentPage - 1) * $rowsPerPage; CProfile::update('web.paging.lastpage', $page['file'], PROFILE_TYPE_STR); CProfile::update('web.paging.page', $currentPage, PROFILE_TYPE_INT); // trim array with items to contain items for current page $items = array_slice($items, $start, $rowsPerPage, true); // viewed pages (better to use not odd) $pagingNavRange = 11; $endPage = $currentPage + floor($pagingNavRange / 2); if ($endPage < $pagingNavRange) { $endPage = $pagingNavRange; } if ($endPage > $pagesCount) { $endPage = $pagesCount; } $startPage = $endPage > $pagingNavRange ? $endPage - $pagingNavRange + 1 : 1; $pageLine = array(); $table = null; if ($pagesCount > 1) { $url = CUrlFactory::getContextUrl(); if ($startPage > 1) { $url->setArgument('page', 1); $pageLine[] = new CLink('<< ' . _x('First', 'page navigation'), $url->getUrl(), null, null, true); $pageLine[] = ' '; } if ($currentPage > 1) { $url->setArgument('page', $currentPage - 1); $pageLine[] = new CLink('< ' . _x('Previous', 'page navigation'), $url->getUrl(), null, null, true); $pageLine[] = ' | '; } for ($p = $startPage; $p <= $pagesCount; $p++) { if ($p > $endPage) { break; } if ($p == $currentPage) { $pagespan = new CSpan($p, 'bold textcolorstyles'); } else { $url->setArgument('page', $p); $pagespan = new CLink($p, $url->getUrl(), null, null, true); } $pageLine[] = $pagespan; $pageLine[] = ' | '; } array_pop($pageLine); if ($currentPage < $pagesCount) { $pageLine[] = ' | '; $url->setArgument('page', $currentPage + 1); $pageLine[] = new CLink(_x('Next', 'page navigation') . ' >', $url->getUrl(), null, null, true); } if ($p < $pagesCount) { $pageLine[] = ' '; $url->setArgument('page', $pagesCount); $pageLine[] = new CLink(_x('Last', 'page navigation') . ' >>', $url->getUrl(), null, null, true); } $table = new CTable(null, 'paging'); $table->addRow(new CCol($pageLine)); } $viewFromPage = ($currentPage - 1) * $rowsPerPage + 1; $viewTillPage = $currentPage * $rowsPerPage; if ($viewTillPage > $itemsCount) { $viewTillPage = $itemsCount; } $pageView = array(); $pageView[] = _('Displaying') . SPACE; if ($itemsCount > 0) { $pageView[] = new CSpan($viewFromPage, 'info'); $pageView[] = SPACE . _('to') . SPACE; } $pageView[] = new CSpan($viewTillPage, 'info'); $pageView[] = SPACE . _('of') . SPACE; $pageView[] = new CSpan($itemsCount, 'info'); $pageView[] = $searchLimit; $pageView[] = SPACE . _('found'); $pageView = new CSpan($pageView); zbx_add_post_js('insertInElement("numrows", ' . zbx_jsvalue($pageView->toString()) . ', "div");'); return $table; }
echo $page_title; ?> </title> <?php if (defined('ZBX_PAGE_DO_REFRESH') && $USER_DETAILS["refresh"]) { echo '<meta http-equiv="refresh" content="' . $USER_DETAILS["refresh"] . '" />'; } ?> <meta name="Author" content="ZABBIX SIA" /> <link rel="stylesheet" type="text/css" href="css.css" /> <?php if (isset($DB['DB']) && !is_null($DB['DB'])) { $css = false; $config = select_config(); if (isset($config['default_theme']) && file_exists('styles/' . $config['default_theme'])) { $css = $config['default_theme']; } if (isset($USER_DETAILS['theme']) && $USER_DETAILS['theme'] != ZBX_DEFAULT_CSS && $USER_DETAILS['alias'] != ZBX_GUEST_USER) { if (file_exists('styles/' . $USER_DETAILS['theme'])) { $css = $USER_DETAILS['theme']; } } if ($css) { echo '<link rel="stylesheet" type="text/css" href="styles/' . $css . '" />' . "\n"; $ico = ereg_replace('.*(\\_[a-z]+).*', "\\1", $css); if (file_exists('images/general/zabbix' . $ico . '.ico')) { echo '<link rel="shortcut icon" href="images/general/zabbix' . $ico . '.ico" />'; } else { echo '<link rel="shortcut icon" href="images/general/zabbix.ico" />';
$cmbConf = new CComboBox('configDropDown', 'adm.housekeeper.php', 'redirect(this.options[this.selectedIndex].value);'); $cmbConf->addItems(array('adm.gui.php' => _('GUI'), 'adm.housekeeper.php' => _('Housekeeping'), 'adm.images.php' => _('Images'), 'adm.iconmapping.php' => _('Icon mapping'), 'adm.regexps.php' => _('Regular expressions'), 'adm.macros.php' => _('Macros'), 'adm.valuemapping.php' => _('Value mapping'), 'adm.workingtime.php' => _('Working time'), 'adm.triggerseverities.php' => _('Trigger severities'), 'adm.triggerdisplayoptions.php' => _('Trigger displaying options'), 'adm.other.php' => _('Other'))); $form->addItem($cmbConf); $cnf_wdgt = new CWidget(null, 'hk'); $cnf_wdgt->addPageHeader(_('CONFIGURATION OF HOUSEKEEPING'), $form); $data['form_refresh'] = getRequest('form_refresh', 0); if ($data['form_refresh']) { $data['config']['hk_events_mode'] = getRequest('hk_events_mode'); $data['config']['hk_events_trigger'] = isset($_REQUEST['hk_events_trigger']) ? getRequest('hk_events_trigger') : $data['config']['hk_events_trigger']; $data['config']['hk_events_internal'] = isset($_REQUEST['hk_events_internal']) ? getRequest('hk_events_internal') : $data['config']['hk_events_internal']; $data['config']['hk_events_discovery'] = isset($_REQUEST['hk_events_discovery']) ? getRequest('hk_events_discovery') : $data['config']['hk_events_discovery']; $data['config']['hk_events_autoreg'] = isset($_REQUEST['hk_events_autoreg']) ? getRequest('hk_events_autoreg') : $data['config']['hk_events_autoreg']; $data['config']['hk_services_mode'] = getRequest('hk_services_mode'); $data['config']['hk_services'] = isset($_REQUEST['hk_services']) ? getRequest('hk_services') : $data['config']['hk_services']; $data['config']['hk_audit_mode'] = getRequest('hk_audit_mode'); $data['config']['hk_audit'] = isset($_REQUEST['hk_audit']) ? getRequest('hk_audit') : $data['config']['hk_audit']; $data['config']['hk_sessions_mode'] = getRequest('hk_sessions_mode'); $data['config']['hk_sessions'] = isset($_REQUEST['hk_sessions']) ? getRequest('hk_sessions') : $data['config']['hk_sessions']; $data['config']['hk_history_mode'] = getRequest('hk_history_mode'); $data['config']['hk_history_global'] = getRequest('hk_history_global'); $data['config']['hk_history'] = isset($_REQUEST['hk_history']) ? getRequest('hk_history') : $data['config']['hk_history']; $data['config']['hk_trends_mode'] = getRequest('hk_trends_mode'); $data['config']['hk_trends_global'] = getRequest('hk_trends_global'); $data['config']['hk_trends'] = isset($_REQUEST['hk_trends']) ? getRequest('hk_trends') : $data['config']['hk_trends']; } else { $data['config'] = select_config(false); } $houseKeeperForm = new CView('administration.general.housekeeper.edit', $data); $cnf_wdgt->addItem($houseKeeperForm->render()); $cnf_wdgt->show(); require_once dirname(__FILE__) . '/include/page_footer.php';