Beispiel #1
0
/**
 * 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['screenid']
 * @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 $filter['backUrl']
 *
 * @return CDiv
 */
function make_latest_issues(array $filter = array())
{
    // hide the sort indicator if no sortfield and sortorder are given
    $showSortIndicator = isset($filter['sortfield']) || isset($filter['sortorder']);
    if (!isset($filter['sortfield'])) {
        $filter['sortfield'] = 'lastchange';
    }
    if (!isset($filter['sortorder'])) {
        $filter['sortorder'] = ZBX_SORT_DOWN;
    }
    $options = array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored' => true, 'maintenance' => $filter['maintenance'], 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE));
    $triggers = API::Trigger()->get(array_merge($options, array('withLastEventUnacknowledged' => isset($filter['extAck']) && $filter['extAck'] == EXTACK_OPTION_UNACK ? true : null, 'skipDependent' => true, 'output' => array('triggerid', 'state', 'error', 'url', 'expression', 'description', 'priority', 'lastchange'), 'selectHosts' => array('hostid', 'name'), 'selectLastEvent' => array('eventid', 'acknowledged', 'objectid', 'clock', 'ns'), 'sortfield' => $filter['sortfield'], 'sortorder' => $filter['sortorder'], 'limit' => isset($filter['limit']) ? $filter['limit'] : DEFAULT_LATEST_ISSUES_CNT)));
    // don't use withLastEventUnacknowledged and skipDependent because of performance issues
    $triggersTotalCount = API::Trigger()->get(array_merge($options, array('countOutput' => true)));
    // get acknowledges
    $eventIds = array();
    foreach ($triggers as $trigger) {
        if ($trigger['lastEvent']) {
            $eventIds[] = $trigger['lastEvent']['eventid'];
        }
    }
    if ($eventIds) {
        $eventAcknowledges = API::Event()->get(array('eventids' => $eventIds, 'select_acknowledges' => API_OUTPUT_EXTEND, 'preservekeys' => true));
    }
    foreach ($triggers as $tnum => $trigger) {
        // if trigger is lost (broken expression) we skip it
        if (empty($trigger['hosts'])) {
            unset($triggers[$tnum]);
            continue;
        }
        $host = reset($trigger['hosts']);
        $trigger['hostid'] = $host['hostid'];
        $trigger['hostname'] = $host['name'];
        if ($trigger['lastEvent']) {
            $trigger['lastEvent']['acknowledges'] = isset($eventAcknowledges[$trigger['lastEvent']['eventid']]) ? $eventAcknowledges[$trigger['lastEvent']['eventid']]['acknowledges'] : null;
        }
        $triggers[$tnum] = $trigger;
    }
    $hostIds = zbx_objectValues($triggers, 'hostid');
    // get hosts
    $hosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid', 'name', 'status', 'maintenance_status', 'maintenance_type', 'maintenanceid'), 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true));
    // actions
    $actions = getEventActionsStatHints($eventIds);
    // ack params
    $ackParams = isset($filter['screenid']) ? array('screenid' => $filter['screenid']) : array();
    $config = select_config();
    // indicator of sort field
    if ($showSortIndicator) {
        $sortDiv = new CDiv(SPACE, $filter['sortorder'] === ZBX_SORT_DOWN ? 'icon_sortdown default_cursor' : 'icon_sortup default_cursor');
        $sortDiv->addStyle('float: left');
        $hostHeaderDiv = new CDiv(array(_('Host'), SPACE));
        $hostHeaderDiv->addStyle('float: left');
        $issueHeaderDiv = new CDiv(array(_('Issue'), SPACE));
        $issueHeaderDiv->addStyle('float: left');
        $lastChangeHeaderDiv = new CDiv(array(_('Time'), SPACE));
        $lastChangeHeaderDiv->addStyle('float: left');
    }
    $table = new CTableInfo(_('No events found.'));
    $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, $showSortIndicator && $filter['sortfield'] === 'hostname' ? array($hostHeaderDiv, $sortDiv) : _('Host'), $showSortIndicator && $filter['sortfield'] === 'priority' ? array($issueHeaderDiv, $sortDiv) : _('Issue'), $showSortIndicator && $filter['sortfield'] === 'lastchange' ? array($lastChangeHeaderDiv, $sortDiv) : _('Last change'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions')));
    $scripts = API::Script()->getScriptsByHosts($hostIds);
    // triggers
    foreach ($triggers as $trigger) {
        $host = $hosts[$trigger['hostid']];
        $hostName = new CSpan($host['name'], 'link_menu');
        $hostName->setMenuPopup(getMenuPopupHost($host, $scripts[$host['hostid']]));
        // add maintenance icon with hint if host is in maintenance
        $maintenanceIcon = null;
        if ($host['maintenance_status']) {
            $maintenanceIcon = new CDiv(null, 'icon-maintenance-abs');
            // get maintenance
            $maintenances = API::Maintenance()->get(array('maintenanceids' => $host['maintenanceid'], 'output' => API_OUTPUT_EXTEND, 'limit' => 1));
            if ($maintenance = reset($maintenances)) {
                $hint = $maintenance['name'] . ' [' . ($host['maintenance_type'] ? _('Maintenance without data collection') : _('Maintenance with data collection')) . ']';
                if (isset($maintenance['description'])) {
                    // double quotes mandatory
                    $hint .= "\n" . $maintenance['description'];
                }
                $maintenanceIcon->setHint($hint);
                $maintenanceIcon->addClass('pointer');
            }
            $hostName->addClass('left-to-icon-maintenance-abs');
        }
        $hostDiv = new CDiv(array($hostName, $maintenanceIcon), 'maintenance-abs-cont');
        // unknown triggers
        $unknown = SPACE;
        if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) {
            $unknown = new CDiv(SPACE, 'status_icon iconunknown');
            $unknown->setHint($trigger['error'], '', 'on');
        }
        // trigger has events
        if ($trigger['lastEvent']) {
            // description
            $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, array('clock' => $trigger['lastEvent']['clock'], 'ns' => $trigger['lastEvent']['ns'])));
            // ack
            $ack = getEventAckState($trigger['lastEvent'], empty($filter['backUrl']) ? true : $filter['backUrl'], true, $ackParams);
        } else {
            // description
            $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, array('clock' => $trigger['lastchange'], 'ns' => '999999999')));
            // ack
            $ack = new CSpan(_('No events'), 'unknown');
        }
        // description
        if (!zbx_empty($trigger['url'])) {
            $description = new CLink($description, resolveTriggerUrl($trigger), null, null, true);
        } else {
            $description = new CSpan($description, 'pointer');
        }
        $description = new CCol($description, getSeverityStyle($trigger['priority']));
        if ($trigger['lastEvent']) {
            $description->setHint(make_popup_eventlist($trigger['triggerid'], $trigger['lastEvent']['eventid']), '', '', false);
        }
        // clock
        $clock = new CLink(zbx_date2str(_('d M Y H:i:s'), $trigger['lastchange']), 'events.php?triggerid=' . $trigger['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $trigger['lastchange']);
        // actions
        $actionHint = $trigger['lastEvent'] && isset($actions[$trigger['lastEvent']['eventid']]) ? $actions[$trigger['lastEvent']['eventid']] : SPACE;
        $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $hostDiv, $description, $clock, zbx_date2age($trigger['lastchange']), $unknown, $ack, $actionHint));
    }
    // initialize blinking
    zbx_add_post_js('jqBlink.blink();');
    $script = new CJSScript(get_js("jQuery('#hat_lastiss_footer').html('" . _s('Updated: %s', zbx_date2str(_('H:i:s'))) . "')"));
    $infoDiv = new CDiv(_n('%1$d of %2$d issue is shown', '%1$d of %2$d issues are shown', count($triggers), $triggersTotalCount));
    $infoDiv->addStyle('text-align: right; padding-right: 3px;');
    return new CDiv(array($table, $infoDiv, $script));
}
Beispiel #2
0
/**
 * Prepare data for trigger menu popup.
 *
 * @param array  $trigger						trigger data
 * @param string $trigger['triggerid']			trigger id
 * @param int    $trigger['flags']				trigger flags (TRIGGER_FLAG_DISCOVERY*)
 * @param array  $trigger['hosts']				hosts, used by trigger expression
 * @param string $trigger['hosts'][]['hostid']	host id
 * @param string $trigger['url']				url
 * @param array  $items							trigger items (optional)
 * @param string $items[]['name']				item name
 * @param array  $items[]['params']				item url parameters ("name" => "value")
 * @param array  $acknowledge					acknowledge link parameters (optional)
 * @param string $acknowledge['eventid']		event id
 * @param string $acknowledge['screenid']		screen id (optional)
 * @param string $acknowledge['backurl']		return url (optional)
 * @param string $eventTime						event navigation time parameter (optional)
 *
 * @return array
 */
function getMenuPopupTrigger(array $trigger, array $items = null, array $acknowledge = null, $eventTime = null)
{
    if ($items) {
        CArrayHelper::sort($items, array('name'));
    }
    $data = array('type' => 'trigger', 'triggerid' => $trigger['triggerid'], 'items' => $items, 'acknowledge' => $acknowledge, 'eventTime' => $eventTime, 'configuration' => null, 'url' => resolveTriggerUrl($trigger));
    if ((CWebUser::$data['type'] == USER_TYPE_ZABBIX_ADMIN || CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN) && $trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
        $host = reset($trigger['hosts']);
        $data['configuration'] = array('hostid' => $host['hostid'], 'switchNode' => id2nodeid($trigger['triggerid']));
    }
    return $data;
}
 /**
  * Prepare data for trigger menu popup.
  *
  * @param array  $trigger						trigger data
  * @param string $trigger['triggerid']			trigger id
  * @param int    $trigger['flags']				trigger flags (TRIGGER_FLAG_DISCOVERY*)
  * @param array  $trigger['hosts']				hosts, used by trigger expression
  * @param string $trigger['hosts'][]['hostid']	host id
  * @param string $trigger['url']				url
  * @param array  $items							trigger items (optional)
  * @param string $items[]['name']				item name
  * @param array  $items[]['params']				item url parameters ("name" => "value")
  * @param array  $acknowledge					acknowledge link parameters (optional)
  * @param string $acknowledge['eventid']		event id
  * @param string $acknowledge['screenid']		screen id (optional)
  * @param string $acknowledge['backurl']		return url (optional)
  * @param string $eventTime						event navigation time parameter (optional)
  *
  * @return array
  */
 public static function getTrigger(array $trigger, array $items = null, array $acknowledge = null, $eventTime = null)
 {
     if ($items) {
         CArrayHelper::sort($items, array('name'));
     }
     $data = array('type' => 'trigger', 'triggerid' => $trigger['triggerid'], 'items' => $items, 'acknowledge' => $acknowledge, 'eventTime' => $eventTime, 'configuration' => null, 'url' => resolveTriggerUrl($trigger));
     $host = reset($trigger['hosts']);
     if (in_array(CWebUser::$data['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN)) && $trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
         $data['configuration'] = array('hostid' => $host['hostid']);
     }
     $data['showEvents'] = $host['status'] == HOST_STATUS_MONITORED;
     return $data;
 }
 /**
  * Prepare data for trigger menu popup.
  *
  * @param array  $trigger							trigger data
  * @param string $trigger['triggerid']				trigger ID
  * @param int    $trigger['flags']					trigger flags (TRIGGER_FLAG_DISCOVERY*)
  * @param array  $trigger['hosts']					hosts, used by trigger expression
  * @param string $trigger['hosts'][]['hostid']		host ID
  * @param string $trigger['hosts'][]['name']		host name
  * @param string $trigger['hosts'][]['status']		host status
  * @param array  $trigger['items']					trigger items
  * @param string $trigger['items'][]['itemid']		item ID
  * @param string $trigger['items'][]['hostid']		host ID
  * @param string $trigger['items'][]['name']		item name
  * @param string $trigger['items'][]['key_']		item key
  * @param string $trigger['items'][]['value_type']	type of information of the item
  * @param string $trigger['url']					trigger URL
  * @param array  $acknowledge						acknowledge link parameters (optional)
  * @param string $acknowledge['eventid']			event ID
  * @param string $acknowledge['screenid']			screen ID (optional)
  * @param string $acknowledge['backurl']			return URL (optional)
  * @param string $eventTime							event navigation time parameter (optional)
  *
  * @return array
  */
 public static function getTrigger(array $trigger, array $acknowledge = null, $eventTime = null)
 {
     $hosts = array();
     $showEvents = true;
     foreach ($trigger['hosts'] as $host) {
         $hosts[$host['hostid']] = $host['name'];
         if ($host['status'] != HOST_STATUS_MONITORED) {
             $showEvents = false;
         }
     }
     $trigger['items'] = CMacrosResolverHelper::resolveItemNames($trigger['items']);
     foreach ($trigger['items'] as &$item) {
         $item['hostname'] = $hosts[$item['hostid']];
     }
     unset($item);
     CArrayHelper::sort($trigger['items'], array('name', 'hostname', 'itemid'));
     $hostCount = count($hosts);
     $items = array();
     foreach ($trigger['items'] as $item) {
         $items[] = array('name' => $hostCount > 1 ? $hosts[$item['hostid']] . NAME_DELIMITER . $item['name_expanded'] : $item['name_expanded'], 'params' => array('itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? HISTORY_GRAPH : HISTORY_VALUES));
     }
     $data = array('type' => 'trigger', 'groupid' => $trigger['groupid'], 'hostid' => $trigger['hostid'], 'triggerid' => $trigger['triggerid'], 'items' => $items, 'acknowledge' => $acknowledge, 'eventTime' => $eventTime, 'url' => resolveTriggerUrl($trigger));
     if ($showEvents) {
         $data['showEvents'] = true;
     }
     if (in_array(CWebUser::$data['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN)) && $trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
         $data['configuration'] = true;
     }
     return $data;
 }
     $items[$inum]['value_type'] = $item['value_type'];
     //ZBX-3059: So it would be possible to show different caption for history for chars and numbers (KB)
     $items[$inum]['action'] = str_in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues';
     $items[$inum]['name'] = htmlspecialchars($item_name);
 }
 $trigger['items'] = $items;
 // trigger js menu
 $menu_trigger_conf = 'null';
 if ($admin_links && $trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
     $configurationUrl = 'triggers.php?form=update&triggerid=' . $trigger['triggerid'] . '&hostid=' . $pageFilter->hostid . '&switch_node=' . id2nodeid($trigger['triggerid']);
     $menu_trigger_conf = "['" . _('Configuration of triggers') . "'," . CJs::encodeJson($configurationUrl) . ",\n\t\t\t\tnull, {'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}]";
 }
 $menu_trigger_url = 'null';
 if (!zbx_empty($trigger['url'])) {
     // double CHtml::encode is required to prevent XSS attacks
     $menu_trigger_url = "['" . _('URL') . "'," . CJs::encodeJson(CHtml::encode(CHtml::encode(resolveTriggerUrl($trigger)))) . ",\n\t\t\t\ttrue, {'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}]";
 }
 $description = new CSpan($trigger['description'], 'link_menu');
 $description->addAction('onclick', "javascript: create_mon_trigger_menu(event, [{'triggerid': '" . $trigger['triggerid'] . "', 'lastchange': '" . $trigger['lastchange'] . "'}, " . $menu_trigger_conf . ", " . $menu_trigger_url . "]," . zbx_jsvalue($items, true) . ");");
 if ($_REQUEST['show_details']) {
     $font = new CTag('font', 'yes');
     $font->setAttribute('color', '#000');
     $font->setAttribute('size', '-2');
     $font->addItem(explode_exp($trigger['expression'], true, true));
     $description = array($description, BR(), $font);
 }
 // DEPENDENCIES {{{
 if (!empty($trigger['dependencies'])) {
     $dep_table = new CTableInfo();
     $dep_table->setAttribute('style', 'width: 200px;');
     $dep_table->addRow(bold(_('Depends on') . ':'));