public function toString($destroy = true)
 {
     if (count($this->tabs) == 1) {
         $this->setAttribute('class', 'min-width ui-tabs ui-widget ui-widget-content ui-corner-all widget');
         $header = reset($this->headers);
         $header = new CDiv($header);
         $header->addClass('ui-corner-all ui-widget-header header');
         $header->setAttribute('id', 'tab_' . key($this->headers));
         $this->addItem($header);
         $tab = reset($this->tabs);
         $tab->addClass('ui-tabs ui-tabs-panel ui-widget ui-widget-content ui-corner-all widget');
         $this->addItem($tab);
     } else {
         $headersList = new CList();
         foreach ($this->headers as $id => $header) {
             $tabLink = new CLink($header, '#' . $id, null, null, false);
             $tabLink->setAttribute('id', 'tab_' . $id);
             $headersList->addItem($tabLink);
         }
         $this->addItem($headersList);
         $this->addItem($this->tabs);
         $options = array();
         if (!is_null($this->selectedTab)) {
             $options['selected'] = $this->selectedTab;
         }
         if ($this->rememberTab) {
             $options['cookie'] = array();
         }
         zbx_add_post_js('jQuery("#' . $this->id . '").tabs(' . zbx_jsvalue($options, true) . ').show();');
     }
     return parent::toString($destroy);
 }
 public function addValue($name, $value, $checked = null)
 {
     $this->count++;
     $id = str_replace(array('[', ']'), array('_'), $this->name) . '_' . $this->count;
     $radio = new CInput('radio', $this->name, $value);
     $radio->attr('id', zbx_formatDomId($id));
     if (strcmp($value, $this->value) == 0 || !is_null($checked) || $checked) {
         $radio->attr('checked', 'checked');
     }
     $label = new CLabel($name, $id);
     $outerDiv = new CDiv(array($radio, $label));
     if ($this->orientation == self::ORIENTATION_HORIZONTAL) {
         $outerDiv->addClass('inlineblock');
     }
     parent::addItem($outerDiv);
 }
Пример #3
0
    public function toString($destroy = true)
    {
        if (count($this->tabs) == 1) {
            $this->setAttribute('class', 'min-width ui-tabs ui-widget ui-widget-content ui-corner-all widget');
            $header = reset($this->headers);
            $header = new CDiv($header);
            $header->addClass('ui-corner-all ui-widget-header header');
            $header->setAttribute('id', 'tab_' . key($this->headers));
            $this->addItem($header);
            $tab = reset($this->tabs);
            $tab->addClass('ui-tabs ui-tabs-panel ui-widget ui-widget-content ui-corner-all widget');
            $this->addItem($tab);
        } else {
            $headersList = new CList();
            foreach ($this->headers as $id => $header) {
                $tabLink = new CLink($header, '#' . $id, null, null, false);
                $tabLink->setAttribute('id', 'tab_' . $id);
                $headersList->addItem($tabLink);
            }
            $this->addItem($headersList);
            $this->addItem($this->tabs);
            if ($this->selectedTab === null) {
                $activeTab = get_cookie('tab', 0);
                $createEvent = '';
            } else {
                $activeTab = $this->selectedTab;
                $createEvent = 'create: function() { jQuery.cookie("tab", ' . $this->selectedTab . '); },';
            }
            $disabledTabs = $this->disabledTabs === null ? '' : 'disabled: ' . CJs::encodeJson($this->disabledTabs) . ',';
            zbx_add_post_js('
				jQuery("#' . $this->id . '").tabs({
					' . $createEvent . '
					' . $disabledTabs . '
					active: ' . $activeTab . ',
					activate: function(event, ui) {
						jQuery.cookie("tab", ui.newTab.index().toString());
					}
				})
				.css("visibility", "visible");');
        }
        return parent::toString($destroy);
    }
Пример #4
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));
}
Пример #5
0
    } else {
        $row = new CRow(array('', $checkbox, $hostColumn, new CCol(new CSpan($item['name_expanded'], $stateCss . ' item')), new CCol(new CSpan($lastClock, $stateCss)), new CCol(new CSpan($lastValue, $stateCss)), new CCol(new CSpan($change, $stateCss)), new CCol($actions, $stateCss)));
    }
    $hosts[$item['hostid']]['item_cnt']++;
    $tab_rows[$item['hostid']][] = $row;
}
foreach ($hosts as $hostId => $dbHost) {
    $host = $hosts[$dbHost['hostid']];
    if (!isset($tab_rows[$hostId])) {
        continue;
    }
    $appRows = $tab_rows[$hostId];
    $openState = CProfile::get('web.latest.toggle_other', null, $host['hostid']);
    $toggle = new CDiv(null, 'app-list-toggle icon-plus-9x9');
    if ($openState) {
        $toggle->addClass('icon-minus-9x9');
    }
    $toggle->setAttribute('data-app-id', '0_' . $host['hostid']);
    $toggle->setAttribute('data-open-state', $openState);
    $hostName = null;
    if (!$singleHostSelected) {
        $hostName = new CSpan($host['name'], 'link_menu menu-host' . ($host['status'] == HOST_STATUS_NOT_MONITORED ? ' not-monitored' : ''));
        $hostName->setMenuPopup(CMenuPopupHelper::getHost($host, $hostScripts[$host['hostid']]));
    }
    // add toggle row
    $table->addRow(array($toggle, '', $hostName, new CCol(array(bold('- ' . 'other' . ' -'), ' (' . _n('%1$s Item', '%1$s Items', $dbHost['item_cnt']) . ')'), null, $filter['showDetails'] ? 10 : 5)), 'odd_row');
    // add toggle sub rows
    foreach ($appRows as $row) {
        $row->setAttribute('parent_app_id', '0_' . $host['hostid']);
        $row->addClass('odd_row');
        if (!$openState) {
Пример #6
0
 /**
  * Set widget footer.
  *
  * @param string|array|CTag $footer
  * @param bool				$right
  */
 public function setFooter($list)
 {
     $this->footer = $list;
     $this->footer->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT);
     return $this;
 }
Пример #7
0
     }
     $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);
     }
     $hostList[] = $hostDiv;
 }
 // host
 $hostColumn = new CCol($hostList);
 $hostColumn->addStyle('white-space: normal;');
 // status
 $statusSpan = new CSpan(trigger_value2str($trigger['value']));
 // add colors and blinking to span depending on configuration and trigger parameters
     }
     $hosts_name = new CSpan($trigger_host['name'], 'link_menu menu-host');
     $hosts_name->setAttribute('data-menu', array('scripts' => $menuScripts, 'hostid' => $trigger_host['hostid'], 'hasScreens' => (bool) $host['screens'], 'hasInventory' => (bool) $host['inventory']));
     $hosts_span->addItem($hosts_name);
     // add maintenance icon with hint if host is in maintenance
     if ($trigger_host['maintenance_status']) {
         $mntIco = new CDiv(null, 'icon-maintenance-inline');
         $maintenances = API::Maintenance()->get(array('maintenanceids' => $trigger_host['maintenanceid'], 'output' => API_OUTPUT_EXTEND, 'limit' => 1));
         if ($maintenance = reset($maintenances)) {
             $hint = $maintenance['name'] . ' [' . ($trigger_host['maintenance_type'] ? _('Maintenance without data collection') : _('Maintenance with data collection')) . ']';
             if (isset($maintenance['description'])) {
                 // double quotes mandatory
                 $hint .= "\n" . $maintenance['description'];
             }
             $mntIco->setHint($hint);
             $mntIco->addClass('pointer');
         }
         $hosts_span->addItem($mntIco);
     }
     // add comma after hosts, except last
     if (next($trigger['hosts'])) {
         $hosts_span->addItem(',' . SPACE);
     }
     $hosts_list[] = $hosts_span;
 }
 $host = new CCol($hosts_list);
 $host->addStyle('white-space: normal;');
 // }}} host JS menu
 $statusSpan = new CSpan(trigger_value2str($trigger['value']));
 // add colors and blinking to span depending on configuration and trigger parameters
 addTriggerValueStyle($statusSpan, $trigger['value'], $trigger['lastchange'], $config['event_ack_enable'] ? $trigger['event_count'] == 0 : false);