Beispiel #1
0
 /**
  * Set widget header.
  *
  * @param string|array|CTag $caption
  * @param string|array|CTag $icons
  */
 public function setHeader($caption = null, $icons = SPACE)
 {
     zbx_value2array($icons);
     if ($caption === null && $icons !== null) {
         $caption = SPACE;
     }
     $this->header = new CDiv(null, 'nowrap ui-corner-all ui-widget-header header');
     $this->header->addItem(array($icons, $caption));
 }
Beispiel #2
0
 /**
  * Set widget header.
  *
  * @param string	$caption
  * @param arrayi	$controls
  */
 public function setHeader($caption, array $controls = [], $cursor_move = false)
 {
     $this->header = (new CDiv())->addClass('dashbrd-widget-head')->addItem((new CTag('h4', true, $caption))->setId($this->id . '_header'));
     if ($cursor_move) {
         $this->header->addClass(ZBX_STYLE_CURSOR_MOVE);
     }
     if ($controls) {
         $this->header->addItem(new CList($controls));
     }
     return $this;
 }
Beispiel #3
0
 public function __construct($header, $messages = [], $buttons = [])
 {
     parent::__construct($header);
     $this->addClass(ZBX_STYLE_MSG_BAD);
     $this->addClass('msg-global');
     if ($messages) {
         parent::addItem((new CDiv((new CList($messages))->addClass(ZBX_STYLE_MSG_DETAILS_BORDER)))->addClass(ZBX_STYLE_MSG_DETAILS));
     }
     parent::addItem((new CDiv($buttons))->addClass('msg-buttons'));
 }
 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);
 }
 public function get()
 {
     $this->cleanItems();
     parent::addItem($this->_header);
     if (is_null($this->state)) {
         $this->state = true;
     }
     $div = new CDiv($this->_body, 'body');
     $div->setAttribute('id', $this->domid);
     if (!$this->state) {
         $div->setAttribute('style', 'display: none;');
         if ($this->_footer) {
             $this->_footer->setAttribute('style', 'display: none;');
         }
     }
     parent::addItem($div);
     parent::addItem($this->_footer);
     return $this;
 }
    $maintenancePeriodTable->addRow(array(new CCol(timeperiod_type2str($timeperiod['timeperiod_type']), 'nowrap'), new CCol(shedule2str($timeperiod), 'wraptext'), new CCol(zbx_date2age(0, $timeperiod['period']), 'nowrap'), new CCol(array(new CSubmit('edit_timeperiodid[' . $id . ']', _('Edit'), null, 'link_menu'), SPACE . SPACE, new CSubmit('del_timeperiodid[' . $id . ']', _('Remove'), null, 'link_menu')), 'nowrap')));
    if (isset($timeperiod['timeperiodid'])) {
        $maintenanceForm->addVar('timeperiods[' . $id . '][timeperiodid]', $timeperiod['timeperiodid']);
    }
    $maintenanceForm->addVar('timeperiods[' . $id . '][timeperiod_type]', $timeperiod['timeperiod_type']);
    $maintenanceForm->addVar('timeperiods[' . $id . '][every]', $timeperiod['every']);
    $maintenanceForm->addVar('timeperiods[' . $id . '][month]', $timeperiod['month']);
    $maintenanceForm->addVar('timeperiods[' . $id . '][dayofweek]', $timeperiod['dayofweek']);
    $maintenanceForm->addVar('timeperiods[' . $id . '][day]', $timeperiod['day']);
    $maintenanceForm->addVar('timeperiods[' . $id . '][start_time]', $timeperiod['start_time']);
    $maintenanceForm->addVar('timeperiods[' . $id . '][start_date]', $timeperiod['start_date']);
    $maintenanceForm->addVar('timeperiods[' . $id . '][period]', $timeperiod['period']);
}
$periodsDiv = new CDiv($maintenancePeriodTable, 'objectgroup inlineblock border_dotted');
if (!isset($_REQUEST['new_timeperiod'])) {
    $periodsDiv->addItem(new CSubmit('new_timeperiod', _('New'), null, 'link_menu'));
}
$maintenancePeriodFormList->addRow(_('Periods'), $periodsDiv);
if (isset($_REQUEST['new_timeperiod'])) {
    if (is_array($_REQUEST['new_timeperiod']) && isset($_REQUEST['new_timeperiod']['id'])) {
        $saveLabel = _('Save');
    } else {
        $saveLabel = _('Add');
    }
    $footer = array(new CSubmit('add_timeperiod', $saveLabel, null, 'link_menu'), SPACE . SPACE, new CSubmit('cancel_new_timeperiod', _('Cancel'), null, 'link_menu'));
    $maintenancePeriodFormList->addRow(_('Maintenance period'), new CDiv(array(get_timeperiod_form(), $footer), 'objectgroup inlineblock border_dotted'));
}
/*
 * Hosts & groups tab
 */
$hostsAndGroupsFormList = new CFormList('hostsAndGroupsFormList');
/**
 * Returns zbx, snmp, jmx, ipmi availability status icons.
 *
 * @param type $host
 *
 * @return CDiv
 */
function getAvailabilityTable($host)
{
    $arr = array('zbx', 'snmp', 'jmx', 'ipmi');
    // for consistency in foreach loop
    $host['zbx_available'] = $host['available'];
    $host['zbx_error'] = $host['error'];
    $ad = new CDiv(null, 'invisible');
    foreach ($arr as $val) {
        switch ($host[$val . '_available']) {
            case HOST_AVAILABLE_TRUE:
                $ai = new CDiv(SPACE, 'status_icon status_icon_extra icon' . $val . 'available');
                break;
            case HOST_AVAILABLE_FALSE:
                $ai = new CDiv(SPACE, 'status_icon status_icon_extra icon' . $val . 'unavailable');
                $ai->setHint($host[$val . '_error'], '', 'on');
                break;
            case HOST_AVAILABLE_UNKNOWN:
                $ai = new CDiv(SPACE, 'status_icon status_icon_extra icon' . $val . 'unknown');
                break;
        }
        $ad->addItem($ai);
    }
    return $ad;
}
Beispiel #8
0
/**
 * Returns zbx, snmp, jmx, ipmi availability status icons and the discovered host lifetime indicator.
 *
 * @param type $host
 *
 * @return CDiv
 */
function getAvailabilityTable($host)
{
    $arr = array('zbx', 'snmp', 'jmx', 'ipmi');
    // for consistency in foreach loop
    $host['zbx_available'] = $host['available'];
    $host['zbx_error'] = $host['error'];
    $ad = new CDiv(null, 'invisible');
    foreach ($arr as $val) {
        switch ($host[$val . '_available']) {
            case HOST_AVAILABLE_TRUE:
                $ai = new CDiv(SPACE, 'status_icon status_icon_extra icon' . $val . 'available');
                break;
            case HOST_AVAILABLE_FALSE:
                $ai = new CDiv(SPACE, 'status_icon status_icon_extra icon' . $val . 'unavailable');
                $ai->setHint($host[$val . '_error'], '', 'on');
                break;
            case HOST_AVAILABLE_UNKNOWN:
                $ai = new CDiv(SPACE, 'status_icon status_icon_extra icon' . $val . 'unknown');
                break;
        }
        $ad->addItem($ai);
    }
    // discovered host lifetime indicator
    if ($host['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $host['hostDiscovery']['ts_delete']) {
        $deleteError = new CDiv(SPACE, 'status_icon status_icon_extra iconwarning');
        $deleteError->setHint(_s('The host is not discovered anymore and will be deleted in %1$s (on %2$s at %3$s).', zbx_date2age($host['hostDiscovery']['ts_delete']), zbx_date2str(_('d M Y'), $host['hostDiscovery']['ts_delete']), zbx_date2str(_('H:i:s'), $host['hostDiscovery']['ts_delete'])));
        $ad->addItem($deleteError);
    }
    return $ad;
}
Beispiel #9
0
 /**
  * Output profiling data.
  */
 public function show()
 {
     global $DB;
     $debug_str = '<a name="debug"></a>';
     $debug_str .= '******************** ' . _('Script profiler') . ' ********************' . '<br>';
     $totalScriptTime = $this->stopTime - $this->startTime;
     $totalTimeStr = _s('Total time: %s', round($totalScriptTime, 6));
     if ($totalTimeStr > $this->slowScriptTime) {
         $totalTimeStr = '<b>' . $totalTimeStr . '</b>';
     }
     $debug_str .= $totalTimeStr . '<br>';
     $sqlTotalTimeStr = _s('Total SQL time: %s', $this->sqlTotalTime);
     if ($sqlTotalTimeStr > $this->slowTotalSqlTime) {
         $sqlTotalTimeStr = '<b>' . $sqlTotalTimeStr . '</b>';
     }
     $debug_str .= $sqlTotalTimeStr . '<br>';
     if (isset($DB) && isset($DB['SELECT_COUNT'])) {
         $debug_str .= _s('SQL count: %s (selects: %s | executes: %s)', count($this->sqlQueryLog), $DB['SELECT_COUNT'], $DB['EXECUTE_COUNT']) . '<br>';
     }
     $debug_str .= _s('Peak memory usage: %s', mem2str($this->getMemoryPeak())) . '<br>';
     $debug_str .= _s('Memory limit: %s', ini_get('memory_limit')) . '<br>';
     $debug_str .= '<br>';
     foreach ($this->apiLog as $i => $apiCall) {
         $debug_str .= '<div style="border-bottom: 1px dotted gray; margin-bottom: 20px;">';
         list($class, $method, $params, $result, $file, $line) = $apiCall;
         // api method
         $debug_str .= '<div style="padding-bottom: 10px;">';
         $debug_str .= $i + 1 . '. <b>' . $class . '->' . $method . '</b> [' . $file . ':' . $line . ']';
         $debug_str .= '</div>';
         // parameters
         $debug_str .= '<table><tr><td style="width: 300px" valign="top">Parameters:';
         foreach ($params as $p) {
             $debug_str .= '<pre>' . print_r(CHtml::encode($p), true) . '</pre>';
         }
         $debug_str .= '</td>';
         // result
         $debug_str .= '<td valign="top">Result:<pre>' . print_r(CHtml::encode($result), true) . '</pre></td>';
         $debug_str .= '</tr></table>';
         $debug_str .= '</div>';
     }
     $debug_str .= '<br>';
     foreach ($this->sqlQueryLog as $query) {
         $time = $query[0];
         $sql = htmlspecialchars($query[1], ENT_QUOTES, 'UTF-8');
         if (strpos($sql, 'SELECT ') !== false) {
             $sqlString = '<span style="color: green; font-size: 1.2em;">' . $sql . '</span>';
         } else {
             $sqlString = '<span style="color: blue; font-size: 1.2em;">' . $sql . '</span>';
         }
         $sqlString = 'SQL (' . $time . '): ' . $sqlString . '<br>';
         if ($time > $this->slowSqlQueryTime) {
             $sqlString = '<b>' . $sqlString . '</b>';
         }
         $debug_str .= $sqlString;
         $callStackString = '<span style="font-style: italic;">' . $this->formatCallStack($query[2]) . '</span>' . '<br>' . '<br>';
         $debug_str .= rtrim($callStackString, '-> ') . '</span>' . '<br>' . '<br>';
     }
     $debug = new CDiv(null, 'textcolorstyles');
     $debug->attr('name', 'zbx_debug_info');
     $debug->attr('style', 'display: none; overflow: auto; width: 95%; border: 1px #777777 solid; margin: 4px; padding: 4px;');
     $debug->addItem(array(BR(), new CJSscript($debug_str), BR()));
     $debug->show();
 }
Beispiel #10
0
 $graph_params_tbl = new CTable();
 $graph_params_tbl->attr('class', 'formtable');
 $graph_params_tbl->addStyle("width: 100%; align: left; border-width: 0 0 0 0;");
 $graph_params_tbl->setCellPadding(0);
 $graph_params_tbl->setCellSpacing(0);
 $graph_params_tbl1 = new CTable();
 $graph_params_tbl1->attr('class', 'formtable');
 $graph_params_tbl1->addStyle("width: 100%; align: left; border-width: 0 0 0 0;");
 $graph_params_tbl1->addRow(array(_('Create graph'), $graphCreate, _('Name') . ':', $graphName, _('Width') . ':', $graphWidth, _('Height') . ':', $graphHeight, _('Graph type') . ':', $cmbGraphType));
 $graph_params_tbl2 = new CTable();
 $graph_params_tbl2->attr('class', 'formtable');
 $graph_params_tbl2->addStyle("width: 100%; align: left; border-width: 0 0 0 0;");
 $graph_params_tbl2->addRow(array(_('Function') . ':', $cmbGraphFunc, _('Draw style') . ':', $cmbDrawType, _('Y axis side') . ':', $cmbYaxisside));
 $graph_params_tbl->addRow($graph_params_tbl1);
 $graph_params_tbl->addRow($graph_params_tbl2);
 $graph_params_div->addItem($graph_params_tbl);
 $graph_params_w->addItem($graph_params_div);
 $right_tab->addRow($empty_row);
 $right_tab->addRow($graph_params_w);
 //Mib selector
 $cmbMibs = new CComboBox('mib', $mib, 'javascript: submit();');
 //Action srow
 $action_w = new CWidget();
 $action_w->setClass('header');
 $action_w->addHeader(array(new CButton('save', _('Save'), 'onSaveItems()'), SPACE, new CButton('clear', _('Clear'), 'onClearItems()')));
 $right_tab->addRow($empty_row);
 $right_tab->addRow($action_w);
 // Left panel
 $td_l = new CCol($left_tab);
 $td_l->setAttribute('valign', 'top');
 $td_l->setAttribute('width', $left_widget_width);
 $tr_desc = new CSpan($description);
 // host JS menu {{{
 $hosts_list = array();
 foreach ($trigger['hosts'] as $trigger_host) {
     $host = $hosts[$trigger_host['hostid']];
     $hosts_span = new CDiv(null, 'floatleft');
     // fetch scripts for the host JS menu
     $menuScripts = array();
     if (isset($scripts_by_hosts[$trigger_host['hostid']])) {
         foreach ($scripts_by_hosts[$trigger_host['hostid']] as $script) {
             $menuScripts[] = array('scriptid' => $script['scriptid'], 'confirmation' => $script['confirmation'], 'name' => $script['name']);
         }
     }
     $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);
     }
Beispiel #12
0
function make_sorting_header($obj, $tabfield, $url = '')
{
    global $page;
    $sortorder = $_REQUEST['sort'] == $tabfield && $_REQUEST['sortorder'] == ZBX_SORT_UP ? ZBX_SORT_DOWN : ZBX_SORT_UP;
    $link = new Curl($url);
    if (empty($url)) {
        $link->formatGetArguments();
    }
    $link->setArgument('sort', $tabfield);
    $link->setArgument('sortorder', $sortorder);
    $url = $link->getUrl();
    if ($page['type'] != PAGE_TYPE_HTML && defined('ZBX_PAGE_MAIN_HAT')) {
        $script = "javascript: return updater.onetime_update('" . ZBX_PAGE_MAIN_HAT . "','" . $url . "');";
    } else {
        $script = "javascript: redirect('" . $url . "');";
    }
    zbx_value2array($obj);
    $div = new CDiv();
    $div->setAttribute('style', 'float:left;');
    foreach ($obj as $enum => $el) {
        if (is_object($el) || $el === SPACE) {
            $div->addItem($el);
        } else {
            $div->addItem(new CSpan($el, 'underline'));
        }
    }
    $div->addItem(SPACE);
    $img = null;
    if (isset($_REQUEST['sort']) && $tabfield == $_REQUEST['sort']) {
        if ($sortorder == ZBX_SORT_UP) {
            $img = new CDiv(SPACE, 'icon_sortdown');
        } else {
            $img = new CDiv(SPACE, 'icon_sortup');
        }
        $img->setAttribute('style', 'float: left;');
    }
    $col = new CCol(array($div, $img), 'nowrap hover_grey');
    $col->setAttribute('onclick', $script);
    return $col;
}
Beispiel #13
0
/**
 * Create table with trigger description and events.
 *
 * @param array  $trigger							An array of trigger data.
 * @param string $trigger['triggerid']				Trigger ID to select events.
 * @param string $trigger['description']			Trigger description.
 * @param string $trigger['url']					Trigger URL.
 * @param string $trigger['lastEvent']['eventid']	Last event ID
 * @param string $backurl							URL to return to.
 *
 * @return CDiv
 */
function make_popup_eventlist($trigger, $backurl)
{
    // Show trigger description and URL.
    $div = new CDiv();
    if ($trigger['comments'] !== '') {
        $div->addItem((new CDiv())->addItem(zbx_str2links($trigger['comments']))->addClass(ZBX_STYLE_OVERLAY_DESCR));
    }
    if ($trigger['url'] !== '') {
        $div->addItem((new CDiv())->addItem(new CLink($trigger['url'], $trigger['url']))->addClass(ZBX_STYLE_OVERLAY_DESCR_URL));
    }
    // Select and show events.
    $config = select_config();
    $table = new CTableInfo();
    // If acknowledges are turned on, we show 'ack' column.
    if ($config['event_ack_enable']) {
        $table->setHeader([_('Time'), _('Status'), _('Duration'), _('Age'), _('Ack')]);
    } else {
        $table->setHeader([_('Time'), _('Status'), _('Duration'), _('Age')]);
    }
    if ($trigger['lastEvent']) {
        $events = API::Event()->get(['source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'output' => API_OUTPUT_EXTEND, 'objectids' => [$trigger['triggerid']], 'eventid_till' => $trigger['lastEvent']['eventid'], 'select_acknowledges' => API_OUTPUT_COUNT, 'sortfield' => ['clock', 'eventid'], 'sortorder' => ZBX_SORT_DOWN, 'limit' => ZBX_WIDGET_ROWS]);
        $lclock = time();
        foreach ($events as $event) {
            $duration = zbx_date2age($lclock, $event['clock']);
            $lclock = $event['clock'];
            $eventStatusSpan = new CSpan(trigger_value2str($event['value']));
            // add colors and blinking to span depending on configuration and trigger parameters
            addTriggerValueStyle($eventStatusSpan, $event['value'], $event['clock'], $event['acknowledged']);
            $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), $eventStatusSpan, $duration, zbx_date2age($event['clock']), $config['event_ack_enable'] ? getEventAckState($event, $backurl) : null]);
        }
    }
    $div->addItem($table);
    return $div;
}
 function bodyToString($destroy = true)
 {
     $left = new CDiv(null, 'left');
     $left->addItem(new CDiv(null, 'setup_logo'));
     $left->addItem(new CDiv(ZABBIX_VERSION, 'setup_version'));
     $left->addItem(new CDiv($this->getList(), 'left_menu'));
     $link1 = new CLink('www.zabbix.com', 'http://www.zabbix.com/', null, null, true);
     $link1->setAttribute('target', '_blank');
     $link2 = new CLink('GPL v2', 'http://www.zabbix.com/license.php', null, null, true);
     $link2->setAttribute('target', '_blank');
     $licence = new CDiv(array($link1, BR(), ' Licensed under ', $link2), 'setup_wizard_licence');
     $left->addItem($licence);
     $right = new CDiv(null, 'right');
     if ($this->getStep() == 0) {
         $right->addItem(new CDiv(null, 'blank_title'));
         $right->addItem(new CDiv($this->getState(), 'blank_under_title'));
         $container = new CDiv(array($left, $right), 'setup_wizard setup_wizard_welcome');
     } else {
         $right->addItem(new CDiv($this->stage[$this->getStep()]['title'], 'setup_title'));
         $right->addItem(new CDiv($this->getState(), 'under_title'));
         $container = new CDiv(array($left, $right), 'setup_wizard');
     }
     if (isset($this->stage[$this->getStep() + 1])) {
         $next = new CSubmit('next[' . $this->getStep() . ']', _('Next') . ' >>');
     } else {
         $next = new CSubmit('finish', _('Finish'));
     }
     if (isset($this->HIDE_CANCEL_BUTTON) && $this->HIDE_CANCEL_BUTTON) {
         $cancel = null;
     } else {
         $cancel = new CDiv(new CSubmit('cancel', _('Cancel')), 'footer_left');
     }
     if ($this->DISABLE_NEXT_BUTTON) {
         $next->setEnabled(false);
     }
     $footer = new CDiv(array($cancel, new CDiv(array($this->getStep() != 0 ? new CSubmit('back[' . $this->getStep() . ']', '<< ' . _('Previous')) : null, $next), 'footer_right')), 'footer');
     $container->addItem($footer);
     return parent::bodyToString($destroy) . $container->ToString();
 }
Beispiel #15
0
 function bodyToString($destroy = true)
 {
     $left = new CDiv(null, 'left');
     $left->addItem(new CDiv($this->getList(), 'left_menu'));
     $link1 = new CLink('www.zabbix.com', 'http://www.zabbix.com/', null, null, true);
     $link1->setAttribute('target', '_blank');
     $link2 = new CLink('GPL v2', 'http://www.zabbix.com/license.php', null, null, true);
     $link2->setAttribute('target', '_blank');
     $licence = new CDiv(array($link1, BR(), ' Licensed under ', $link2), 'setup_wizard_licence');
     $left->addItem($licence);
     $right = new CDiv(null, 'right');
     if ($this->getStep() == 0) {
         $right->addItem(new CDiv(null, 'blank_title'));
         $right->addItem(new CDiv($this->getState(), 'blank_under_title'));
         $container = new CDiv(array($left, $right), 'setup_wizard setup_wizard_welcome');
     } else {
         $right->addItem(new CDiv($this->stage[$this->getStep()]['title'], 'setup_title'));
         $right->addItem(new CDiv($this->getState(), 'under_title'));
         $container = new CDiv(array($left, $right), 'setup_wizard');
     }
     if (isset($this->stage[$this->getStep() + 1])) {
         $next = new CSubmit('next[' . $this->getStep() . ']', _('Next') . SPACE . '&raquo;');
     } else {
         $next = new CSubmit('finish', _('Finish'));
     }
     if (isset($this->HIDE_CANCEL_BUTTON) && $this->HIDE_CANCEL_BUTTON) {
         $cancel = null;
     } else {
         $cancel = new CDiv(new CSubmit('cancel', _('Cancel')), 'footer_left');
     }
     if ($this->DISABLE_NEXT_BUTTON) {
         $next->setEnabled(false);
     }
     // if the user is not logged in (first setup run) hide the "previous" button on the final step
     if ($this->getStep() && (CWebUser::$data && CWebUser::getType() == USER_TYPE_SUPER_ADMIN || $this->getStep() < 5)) {
         $back = new CSubmit('back[' . $this->getStep() . ']', '&laquo;' . SPACE . _('Previous'));
     } else {
         $back = null;
     }
     $footer = new CDiv(array($cancel, new CDiv(array($back, $next), 'footer_right')), 'footer');
     $container->addItem($footer);
     return parent::bodyToString($destroy) . $container->ToString();
 }
Beispiel #16
0
     $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
 addTriggerValueStyle($statusSpan, $trigger['value'], $trigger['lastchange'], $config['event_ack_enable'] ? $trigger['event_count'] == 0 : false);
 $lastChangeDate = zbx_date2str(_('d M Y H:i:s'), $trigger['lastchange']);
Beispiel #17
0
         $node_form->addItem($div_node_tree);
         unset($combo_node_list);
     }
 }
 // 1st level menu
 $table = new CTable();
 $table->setCellSpacing(0);
 $table->setCellPadding(0);
 $table->setAttribute('style', 'width: 100%;');
 $r_col = new CCol($node_form);
 $r_col->setAttribute('align', 'right');
 //		$r_col->setAttribute('style','text-align: right;');
 $table->addRow(array($menu_table, $r_col));
 $page_menu = new CDiv();
 $page_menu->setAttribute('id', 'mmenu');
 $page_menu->addItem($table);
 //----
 // 2nd level menu
 $sub_menu_table = new CTable(NULL, 'sub_menu');
 $sub_menu_table->setCellSpacing(0);
 $sub_menu_table->setCellPadding(5);
 $menu_divs = array();
 $menu_selected = false;
 foreach ($sub_menus as $label => $sub_menu) {
     $sub_menu_row = array();
     foreach ($sub_menu as $id => $sub_page) {
         if (empty($sub_page['menu_text'])) {
             $sub_page['menu_text'] = SPACE;
         }
         $sub_menu_item = new CLink($sub_page['menu_text'], $sub_page['menu_url'], $sub_page['class'] . ' nowrap');
         if ($sub_page['selected']) {
/**
 * Create and return a DIV with latest problem triggers.
 *
 * @param array $filter
 *
 * @return CDiv
 */
function make_latest_issues(array $filter = array())
{
    if (!isset($filter['sortfield'])) {
        $filter['sortfield'] = 'lastchange';
    }
    if (!isset($filter['sortorder'])) {
        $filter['sortorder'] = ZBX_SORT_DOWN;
    }
    // get triggers
    $options = array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored' => true, 'maintenance' => $filter['maintenance'], 'withLastEventUnacknowledged' => !empty($filter['extAck']) && $filter['extAck'] == EXTACK_OPTION_UNACK ? true : null, 'skipDependent' => true, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'selectHosts' => array('hostid', 'name'), 'output' => array('triggerid', 'value_flags', 'error', 'url', 'expression', 'description', 'priority', 'type'), 'sortfield' => $filter['sortfield'], 'sortorder' => $filter['sortorder'], 'limit' => isset($filter['limit']) ? $filter['limit'] : DEFAULT_LATEST_ISSUES_CNT);
    $triggers = API::Trigger()->get($options);
    // total trigger count
    $options['countOutput'] = true;
    // we unset withLastEventUnacknowledged and skipDependent because of performance issues
    unset($options['limit'], $options['withLastEventUnacknowledged'], $options['skipDependent']);
    $triggersTotalCount = API::Trigger()->get($options);
    // get events
    $events = API::Trigger()->get(array('triggerids' => zbx_objectValues($triggers, 'triggerid'), 'selectLastEvent' => API_OUTPUT_EXTEND, 'preservekeys' => true));
    // get acknowledges
    $eventIds = array();
    foreach ($events as $event) {
        if ($event['lastEvent']) {
            $eventIds[$event['lastEvent']['eventid']] = $event['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'];
        // set events
        if (isset($events[$trigger['triggerid']])) {
            $trigger['event'] = $events[$trigger['triggerid']]['lastEvent'];
        }
        if (!empty($trigger['event'])) {
            $trigger['event']['acknowledges'] = isset($eventAcknowledges[$trigger['event']['eventid']]) ? $eventAcknowledges[$trigger['event']['eventid']]['acknowledges'] : null;
        }
        $triggers[$tnum] = $trigger;
    }
    $hostIds = zbx_objectValues($triggers, 'hostid');
    // get hosts
    $hosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid', 'name', 'maintenance_status', 'maintenance_type', 'maintenanceid'), 'selectInventory' => array('hostid'), 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true));
    // get scripts
    $scripts_by_hosts = API::Script()->getScriptsByHosts($hostIds);
    // actions
    $actions = getEventActionsStatHints($eventIds);
    // ack params
    $ackParams = isset($filter['screenid']) ? array('screenid' => $filter['screenid']) : array();
    $config = select_config();
    // indicator of sort field
    $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(_('Last change'), SPACE));
    $lastChangeHeaderDiv->addStyle('float: left');
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? _('Node') : null, $filter['sortfield'] === 'hostname' ? array($hostHeaderDiv, $sortDiv) : _('Host'), $filter['sortfield'] === 'priority' ? array($issueHeaderDiv, $sortDiv) : _('Issue'), $filter['sortfield'] === 'lastchange' ? array($lastChangeHeaderDiv, $sortDiv) : _('Last change'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions')));
    // triggers
    foreach ($triggers as $trigger) {
        // check for dependencies
        $host = $hosts[$trigger['hostid']];
        $hostSpan = new CDiv(null, 'maintenance-abs-cont');
        $hostName = new CSpan($host['name'], 'link_menu menu-host');
        $hostName->setAttribute('data-menu', hostMenuData($host, $scripts_by_hosts[$host['hostid']]));
        // add maintenance icon with hint if host is in maintenance
        if ($host['maintenance_status']) {
            $mntIco = 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'];
                }
                $mntIco->setHint($hint);
                $mntIco->addClass('pointer');
            }
            $hostName->addClass('left-to-icon-maintenance-abs');
            $hostSpan->addItem($mntIco);
        }
        $hostSpan->addItem($hostName);
        // unknown triggers
        $unknown = SPACE;
        if ($trigger['value_flags'] == TRIGGER_VALUE_FLAG_UNKNOWN) {
            $unknown = new CDiv(SPACE, 'status_icon iconunknown');
            $unknown->setHint($trigger['error'], '', 'on');
        }
        if (!empty($trigger['event'])) {
            $ack = getEventAckState($trigger['event'], empty($filter['backUrl']) ? true : $filter['backUrl'], true, $ackParams);
            $clock = new CLink(zbx_date2str(_('d M Y H:i:s'), $trigger['event']['clock']), 'events.php?triggerid=' . $trigger['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $trigger['event']['clock']);
            $description = CEventHelper::expandDescription(zbx_array_merge($trigger, array('clock' => $trigger['event']['clock'], 'ns' => $trigger['event']['ns'])));
            $description = $trigger['url'] ? new CLink($description, resolveTriggerUrl($trigger), null, null, true) : new CSpan($description, 'pointer');
            $description = new CCol($description, getSeverityStyle($trigger['priority']));
            $description->setHint(make_popup_eventlist($trigger['triggerid'], $trigger['event']['eventid']), '', '', false);
            $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $hostSpan, $description, $clock, zbx_date2age($trigger['event']['clock']), $unknown, $ack, isset($actions[$trigger['event']['eventid']]) ? $actions[$trigger['event']['eventid']] : SPACE));
        }
    }
    // 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('%2$d of %1$d issue is shown', '%2$d of %1$d issues are shown', $triggersTotalCount, count($triggers)));
    $infoDiv->addStyle('text-align: right; padding-right: 3px;');
    return new CDiv(array($table, $infoDiv, $script));
}