Ejemplo n.º 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));
}
Ejemplo n.º 2
0
    $maintenanceView->show();
} else {
    $sortfield = getPageSortField('name');
    $sortorder = getPageSortOrder();
    // get only maintenance IDs for paging
    $options = array('output' => array('maintenanceid', $sortfield), 'editable' => true, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1);
    if ($pageFilter->groupsSelected && $pageFilter->groupid > 0) {
        $options['groupids'] = $pageFilter->groupid;
    } else {
        $options['groupids'] = $config['dropdown_first_entry'] ? null : array();
    }
    $data['maintenances'] = API::Maintenance()->get($options);
    order_result($data['maintenances'], $sortfield, $sortorder);
    $data['paging'] = getPagingLine($data['maintenances'], array('maintenanceid'));
    // get list of maintenances
    $data['maintenances'] = API::Maintenance()->get(array('maintenanceids' => zbx_objectValues($data['maintenances'], 'maintenanceid'), 'output' => API_OUTPUT_EXTEND));
    foreach ($data['maintenances'] as $number => $maintenance) {
        if ($maintenance['active_till'] < time()) {
            $data['maintenances'][$number]['status'] = MAINTENANCE_STATUS_EXPIRED;
        } elseif ($maintenance['active_since'] > time()) {
            $data['maintenances'][$number]['status'] = MAINTENANCE_STATUS_APPROACH;
        } else {
            $data['maintenances'][$number]['status'] = MAINTENANCE_STATUS_ACTIVE;
        }
    }
    order_result($data['maintenances'], $sortfield, $sortorder);
    $data['pageFilter'] = $pageFilter;
    // nodes
    if ($data['displayNodes']) {
        foreach ($data['maintenances'] as &$maintenance) {
            $maintenance['nodename'] = get_node_name_by_elid($maintenance['maintenanceid'], true);
Ejemplo n.º 3
0
if ($hostId > 0) {
    $data = [];
    // host scripts
    $data['hostScripts'] = API::Script()->getScriptsByHosts([$hostId]);
    // inventory info
    $data['tableTitles'] = getHostInventories();
    $data['tableTitles'] = zbx_toHash($data['tableTitles'], 'db_field');
    $inventoryFields = array_keys($data['tableTitles']);
    // overview tab
    $data['host'] = API::Host()->get(['output' => ['hostid', 'host', 'name', 'status', 'maintenance_status', 'maintenanceid', 'maintenance_type', 'description'], 'selectInterfaces' => API_OUTPUT_EXTEND, 'selectItems' => API_OUTPUT_COUNT, 'selectTriggers' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'selectInventory' => $inventoryFields, 'selectGraphs' => API_OUTPUT_COUNT, 'selectApplications' => API_OUTPUT_COUNT, 'selectDiscoveries' => API_OUTPUT_COUNT, 'selectHttpTests' => API_OUTPUT_COUNT, 'hostids' => $hostId, 'preservekeys' => true]);
    $data['host'] = reset($data['host']);
    unset($data['host']['inventory']['hostid']);
    // resolve macros
    $data['host']['interfaces'] = CMacrosResolverHelper::resolveHostInterfaces($data['host']['interfaces']);
    if ($data['host']['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
        $data['maintenances'] = API::Maintenance()->get(['maintenanceids' => [$data['host']['maintenanceid']], 'output' => ['name', 'description'], 'preservekeys' => true]);
    }
    // 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();
Ejemplo n.º 4
0
 /**
  * Update maintenances
  *
  * @param array $maintenances
  * @return boolean
  */
 public function update(array $maintenances)
 {
     $maintenances = zbx_toArray($maintenances);
     $maintenanceids = zbx_objectValues($maintenances, 'maintenanceid');
     // validate maintenance permissions
     if (self::$userData['type'] == USER_TYPE_ZABBIX_USER) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
     }
     $hostids = array();
     $groupids = array();
     $updMaintenances = $this->get(array('maintenanceids' => zbx_objectValues($maintenances, 'maintenanceid'), 'editable' => true, 'output' => API_OUTPUT_EXTEND, 'selectGroups' => API_OUTPUT_REFER, 'selectHosts' => API_OUTPUT_REFER, 'selectTimeperiods' => API_OUTPUT_EXTEND, 'preservekeys' => true));
     foreach ($maintenances as $maintenance) {
         if (!isset($updMaintenances[$maintenance['maintenanceid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
         // Checking whether a maintenance with this name already exists. First, getting all maintenances with the same name as this
         $receivedMaintenances = API::Maintenance()->get(array('filter' => array('name' => $maintenance['name'])));
         // validate if maintenance name already exists
         foreach ($receivedMaintenances as $rMaintenance) {
             if (bccomp($rMaintenance['maintenanceid'], $maintenance['maintenanceid']) != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Maintenance "%s" already exists.', $maintenance['name']));
             }
         }
         // validate maintenance active since
         if (!validateUnixTime($maintenance['active_since'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('"%s" must be between 1970.01.01 and 2038.01.18.', _('Active since')));
         }
         // validate maintenance active till
         if (!validateUnixTime($maintenance['active_till'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('"%s" must be between 1970.01.01 and 2038.01.18.', _('Active till')));
         }
         // validate maintenance active interval
         if ($maintenance['active_since'] > $maintenance['active_till']) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Maintenance "Active since" value cannot be bigger than "Active till".'));
         }
         // validate timeperiods
         if (empty($maintenance['timeperiods'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('At least one maintenance period must be created.'));
         }
         $hostids = array_merge($hostids, $maintenance['hostids']);
         $groupids = array_merge($groupids, $maintenance['groupids']);
     }
     // validate hosts & groups
     if (empty($hostids) && empty($groupids)) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('At least one host or group should be selected.'));
     }
     // validate hosts permissions
     $options = array('hostids' => $hostids, 'editable' => true, 'output' => array('hostid'), 'preservekeys' => true);
     $updHosts = API::Host()->get($options);
     foreach ($hostids as $hostid) {
         if (!isset($updHosts[$hostid])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('You do not have permission to perform this operation.'));
         }
     }
     // validate groups permissions
     $options = array('groupids' => $groupids, 'editable' => true, 'output' => array('groupid'), 'preservekeys' => true);
     $updGroups = API::HostGroup()->get($options);
     foreach ($groupids as $groupid) {
         if (!isset($updGroups[$groupid])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
     }
     $this->removeSecondsFromTimes($maintenances);
     $update = array();
     foreach ($maintenances as $mnum => $maintenance) {
         $dbFields = array('maintenanceid' => null);
         // validate fields
         if (!check_db_fields($dbFields, $maintenance)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect parameters for maintenance.'));
         }
         $update[$mnum] = array('values' => $maintenance, 'where' => array('maintenanceid' => $maintenance['maintenanceid']));
         // update time periods
         $this->replaceTimePeriods($updMaintenances[$maintenance['maintenanceid']], $maintenance);
     }
     DB::update('maintenances', $update);
     // some of the hosts and groups bound to maintenance must be deleted, other inserted and others left alone
     $insertHosts = array();
     $insertGroups = array();
     foreach ($maintenances as $maintenance) {
         // putting apart those host<->maintenance connections that should be inserted, deleted and not changed
         // $hostDiff['first'] - new hosts, that should be inserted
         // $hostDiff['second'] - hosts, that should be deleted
         // $hostDiff['both'] - hosts, that should not be touched
         $hostDiff = zbx_array_diff(zbx_toObject($maintenance['hostids'], 'hostid'), $updMaintenances[$maintenance['maintenanceid']]['hosts'], 'hostid');
         foreach ($hostDiff['first'] as $host) {
             $insertHosts[] = array('hostid' => $host['hostid'], 'maintenanceid' => $maintenance['maintenanceid']);
         }
         foreach ($hostDiff['second'] as $host) {
             $deleteHosts = array('hostid' => $host['hostid'], 'maintenanceid' => $maintenance['maintenanceid']);
             DB::delete('maintenances_hosts', $deleteHosts);
         }
         // now the same with the groups
         $groupDiff = zbx_array_diff(zbx_toObject($maintenance['groupids'], 'groupid'), $updMaintenances[$maintenance['maintenanceid']]['groups'], 'groupid');
         foreach ($groupDiff['first'] as $group) {
             $insertGroups[] = array('groupid' => $group['groupid'], 'maintenanceid' => $maintenance['maintenanceid']);
         }
         foreach ($groupDiff['second'] as $group) {
             $deleteGroups = array('groupid' => $group['groupid'], 'maintenanceid' => $maintenance['maintenanceid']);
             DB::delete('maintenances_groups', $deleteGroups);
         }
     }
     DB::insert('maintenances_hosts', $insertHosts);
     DB::insert('maintenances_groups', $insertGroups);
     return array('maintenanceids' => $maintenanceids);
 }
Ejemplo n.º 5
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['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];
}
Ejemplo n.º 6
0
 $hostList = array();
 foreach ($trigger['hosts'] as $triggerHost) {
     // fetch scripts for the host js menu
     $scripts = array();
     if (isset($scriptsByHosts[$triggerHost['hostid']])) {
         foreach ($scriptsByHosts[$triggerHost['hostid']] as $script) {
             $scripts[] = $script;
         }
     }
     $hostName = new CSpan($triggerHost['name'], 'link_menu');
     $hostName->setMenuPopup(getMenuPopupHost($hosts[$triggerHost['hostid']], $scripts));
     $hostDiv = new CDiv($hostName);
     // add maintenance icon with hint if host is in maintenance
     if ($triggerHost['maintenance_status']) {
         $maintenanceIcon = new CDiv(null, 'icon-maintenance-inline');
         $maintenances = API::Maintenance()->get(array('maintenanceids' => $triggerHost['maintenanceid'], 'output' => API_OUTPUT_EXTEND, 'limit' => 1));
         if ($maintenance = reset($maintenances)) {
             $hint = $maintenance['name'] . ' [' . ($triggerHost['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');
         }
         $hostDiv->addItem($maintenanceIcon);
     }
     // add comma after hosts, except last
     if (next($trigger['hosts'])) {
         $hostDiv->addItem(',' . SPACE);
     }
Ejemplo n.º 7
0
    $maintenanceView->show();
} else {
    // get maintenances
    $sortfield = getPageSortField('name');
    $sortorder = getPageSortOrder();
    $options = array('output' => API_OUTPUT_EXTEND, 'editable' => true, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'limit' => $config['search_limit'] + 1);
    if ($pageFilter->groupsSelected) {
        if ($pageFilter->groupid > 0) {
            $options['groupids'] = $pageFilter->groupid;
        } else {
            $options['groupids'] = array_keys($pageFilter->groups);
        }
    } else {
        $options['groupids'] = array();
    }
    $data['maintenances'] = API::Maintenance()->get($options);
    foreach ($data['maintenances'] as $number => $maintenance) {
        if ($maintenance['active_till'] < time()) {
            $data['maintenances'][$number]['status'] = MAINTENANCE_STATUS_EXPIRED;
        } elseif ($maintenance['active_since'] > time()) {
            $data['maintenances'][$number]['status'] = MAINTENANCE_STATUS_APPROACH;
        } else {
            $data['maintenances'][$number]['status'] = MAINTENANCE_STATUS_ACTIVE;
        }
    }
    order_result($data['maintenances'], $sortfield, $sortorder);
    $data['paging'] = getPagingLine($data['maintenances'], array('maintenanceid'));
    $data['pageFilter'] = $pageFilter;
    // nodes
    if ($data['displayNodes']) {
        foreach ($data['maintenances'] as &$maintenance) {
Ejemplo n.º 8
0
// get trigger dependencies
$dbTriggerDependencies = DBselect('SELECT triggerid_down,triggerid_up' . ' FROM trigger_depends' . ' WHERE ' . dbConditionInt('triggerid_up', $triggerIds));
$triggerIdsDown = [];
while ($row = DBfetch($dbTriggerDependencies)) {
    $triggerIdsDown[$row['triggerid_up']][] = intval($row['triggerid_down']);
}
$maintenanceids = [];
foreach ($triggers as $trigger) {
    foreach ($trigger['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]);
}
foreach ($triggers as $trigger) {
    /*
     * At this point "all" or one group is selected. And same goes for hosts. It is safe to pass 'groupid' and 'hostid'
     * to trigger menu pop-up, so it properly redirects to Events page. Mind that 'DDRemember' option will be ignored.
     */
    $trigger['groupid'] = $pageFilter->groupid;
    $trigger['hostid'] = $pageFilter->hostid;
    $description = [];
    if (!empty($trigger['dependencies'])) {
        $dependenciesTable = (new CTable())->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_STANDARD_WIDTH . 'px;')->addRow(_('Depends on') . ':');
        foreach ($trigger['dependencies'] as $dependency) {
            $dependenciesTable->addRow(' - ' . CMacrosResolverHelper::resolveTriggerNameById($dependency['triggerid']));
        }
        $description[] = (new CSpan())->addClass(ZBX_STYLE_ICON_DEPEND_DOWN)->addClass(ZBX_STYLE_CURSOR_POINTER)->setHint($dependenciesTable);