$table->setHeader(array(_('Next check'), _('Delayed by'), is_show_all_nodes() ? _('Node') : null, _('Host'), _('Name'))); while ($row = DBfetch($result)) { $res = calculateItemNextcheck($row['interfaceid'], $row['itemid'], $row['type'], $row['delay'], $row['delay_flex'], $row['lastclock']); if (0 != $row['proxy_hostid'] && 0 != $res['delay']) { $res['nextcheck'] = $row['lastclock'] + $res['delay']; } $diff = $now - $res['nextcheck']; if ($diff <= 5) { continue; } $arr[] = array($res['nextcheck'], $row['hostid'], $row['hostname'], itemName($row)); } $rows = 0; sort($arr); foreach ($arr as $r) { $rows++; if ($rows > 500) { $truncated = true; break; } $table->addRow(array(zbx_date2str(QUEUE_NODES_DATE_FORMAT, $r[0]), zbx_date2age($r[0]), get_node_name_by_elid($r[1]), $r[2], $r[3])); } } } } $queue_wdgt->addItem($table); $queue_wdgt->Show(); if ($_REQUEST['config'] != 0) { show_table_header(_('Total') . ": " . $table->GetNumRows() . ($truncated ? ' (' . _('Truncated') . ')' : '')); } require_once dirname(__FILE__) . '/include/page_footer.php';
} else { $ack = SPACE; } } if ($row_event['acknowledged'] == 0 && $row_event['value'] == TRIGGER_VALUE_TRUE) { $ack_cb = new CCheckBox('events[' . $row_event['eventid'] . ']', 'no', NULL, $row_event['eventid']); } else { $ack_cb = SPACE; } $clock = new CLink(zbx_date2str(S_DATE_FORMAT_YMDHMS, $row_event['clock']), 'tr_events.php?triggerid=' . $trigger['triggerid'] . '&eventid=' . $row_event['eventid']); $next_clock = isset($trigger['events'][$enum - 1]) ? $trigger['events'][$enum - 1]['clock'] : time(); $empty_col = new CCol(SPACE); $empty_col->setColSpan(3); $ack_cb_col = new CCol($ack_cb); $ack_cb_col->setColSpan(2); $row = new CRow(array(SPACE, $config['event_ack_enable'] ? $ack_cb_col : null, $status, $clock, zbx_date2age($row_event['clock']), zbx_date2age($next_clock, $row_event['clock']), $config['event_ack_enable'] ? $ack : NULL, is_show_all_nodes() ? SPACE : null, $empty_col), 'odd_row'); $row->setAttribute('data-parentid', $trigger['triggerid']); $row->addStyle('display: none;'); $table->addRow($row); if ($i > $config['event_show_max']) { break; } } } } //----- GO ------ $footer = null; if ($config['event_ack_enable']) { $goBox = new CComboBox('go'); $goBox->addItem('bulkacknowledge', S_BULK_ACKNOWLEDGE); // goButton name is necessary!!!
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $this->dataId = 'discovery'; $sort_field = $this->data['sort']; $sort_order = $this->data['sortorder']; $druleid = $this->data['druleid']; // discovery rules $options = ['output' => ['druleid', 'name'], 'selectDHosts' => ['dhostid', 'status', 'lastup', 'lastdown'], 'filter' => ['status' => DRULE_STATUS_ACTIVE]]; if ($druleid > 0) { $options['druleids'] = $druleid; // set selected discovery rule id } $drules = API::DRule()->get($options); if ($drules) { order_result($drules, 'name'); } // discovery services $options = ['selectHosts' => ['hostid', 'name', 'status'], 'output' => ['dserviceid', 'type', 'key_', 'port', 'status', 'lastup', 'lastdown', 'ip', 'dns'], 'sortfield' => $sort_field, 'sortorder' => $sort_order, 'limitSelects' => 1]; if ($druleid > 0) { $options['druleids'] = $druleid; } else { $options['druleids'] = zbx_objectValues($drules, 'druleid'); } $dservices = API::DService()->get($options); // user macros $macros = API::UserMacro()->get(['output' => ['macro', 'value'], 'globalmacro' => true]); $macros = zbx_toHash($macros, 'macro'); // services $services = []; foreach ($dservices as $dservice) { $key_ = $dservice['key_']; if ($key_ !== '') { if (array_key_exists($key_, $macros)) { $key_ = $macros[$key_]['value']; } $key_ = ': ' . $key_; } $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_; $services[$service_name] = 1; } ksort($services); // discovery services to hash $dservices = zbx_toHash($dservices, 'dserviceid'); // discovery hosts $dhosts = API::DHost()->get(['druleids' => zbx_objectValues($drules, 'druleid'), 'selectDServices' => ['dserviceid', 'ip', 'dns', 'type', 'status', 'key_'], 'output' => ['dhostid', 'lastdown', 'lastup', 'druleid']]); $dhosts = zbx_toHash($dhosts, 'dhostid'); $header = [make_sorting_header(_('Discovered device'), 'ip', $sort_field, $sort_order, 'zabbix.php?action=discovery.view'), _('Monitored host'), _('Uptime') . '/' . _('Downtime')]; foreach ($services as $name => $foo) { $header[] = (new CColHeader($name))->addClass('vertical_rotation'); } // create table $table = (new CTableInfo())->makeVerticalRotation()->setHeader($header); foreach ($drules as $drule) { $discovery_info = []; foreach ($drule['dhosts'] as $dhost) { if ($dhost['status'] == DHOST_STATUS_DISABLED) { $hclass = 'disabled'; $htime = $dhost['lastdown']; } else { $hclass = 'enabled'; $htime = $dhost['lastup']; } // $primary_ip stores the primary host ip of the dhost $primary_ip = ''; foreach ($dhosts[$dhost['dhostid']]['dservices'] as $dservice) { $dservice = $dservices[$dservice['dserviceid']]; $hostName = ''; $host = reset($dservices[$dservice['dserviceid']]['hosts']); if (!is_null($host)) { $hostName = $host['name']; } if ($primary_ip !== '') { if ($primary_ip === $dservice['ip']) { $htype = 'primary'; } else { $htype = 'slave'; } } else { $primary_ip = $dservice['ip']; $htype = 'primary'; } if (!array_key_exists($dservice['ip'], $discovery_info)) { $discovery_info[$dservice['ip']] = ['ip' => $dservice['ip'], 'dns' => $dservice['dns'], 'type' => $htype, 'class' => $hclass, 'host' => $hostName, 'time' => $htime]; } if ($dservice['status'] == DSVC_STATUS_DISABLED) { $class = ZBX_STYLE_INACTIVE_BG; $time = 'lastdown'; } else { $class = ZBX_STYLE_ACTIVE_BG; $time = 'lastup'; } $key_ = $dservice['key_']; if ($key_ !== '') { if (array_key_exists($key_, $macros)) { $key_ = $macros[$key_]['value']; } $key_ = NAME_DELIMITER . $key_; } $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_; $discovery_info[$dservice['ip']]['services'][$service_name] = ['class' => $class, 'time' => $dservice[$time]]; } } if ($druleid == 0 && $discovery_info) { $col = new CCol([bold($drule['name']), SPACE . '(' . _n('%d device', '%d devices', count($discovery_info)) . ')']); $col->setColSpan(count($services) + 3); $table->addRow($col); } order_result($discovery_info, $sort_field, $sort_order); foreach ($discovery_info as $ip => $h_data) { $dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')'; $row = [$h_data['type'] == 'primary' ? (new CSpan($ip . $dns))->addClass($h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(array_key_exists('host', $h_data) ? $h_data['host'] : ''), (new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(['value' => time() - $h_data['time'], 'units' => 'uptime'])))->addClass($h_data['class'])]; foreach ($services as $name => $foo) { $class = null; $time = SPACE; $hint = (new CDiv(SPACE))->addClass($class); $hint_table = null; if (array_key_exists($name, $h_data['services'])) { $class = $h_data['services'][$name]['class']; $time = $h_data['services'][$name]['time']; $hint_table = (new CTableInfo())->setAttribute('style', 'width: auto;'); if ($class == ZBX_STYLE_ACTIVE_BG) { $hint_table->setHeader(_('Uptime')); } else { $hint_table->setHeader(_('Downtime')); } $hint_table->addRow((new CCol(zbx_date2age($h_data['services'][$name]['time'])))->addClass($class)); } $column = (new CCol($hint))->addClass($class); if (!is_null($hint_table)) { $column->setHint($hint_table); } $row[] = $column; } $table->addRow($row); } } return $this->getOutput($table, true, $this->data); }
$dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')'; $row = array($h_data['type'] == 'primary' ? new CSpan($ip . $dns, $h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(empty($h_data['host']) ? '-' : $h_data['host']), new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(array('value' => time() - $h_data['time'], 'units' => 'uptime')), $h_data['class'])); foreach ($this->data['services'] as $name => $foo) { $class = null; $time = SPACE; $hint = new CDiv(SPACE, $class); $hintTable = null; if (isset($h_data['services'][$name])) { $class = $h_data['services'][$name]['class']; $time = $h_data['services'][$name]['time']; $hintTable = new CTableInfo(); $hintTable->setAttribute('style', 'width: auto;'); if ($class == 'active') { $hintTable->setHeader(_('Uptime')); } elseif ($class == 'inactive') { $hintTable->setHeader(_('Downtime')); } $timeColumn = new CCol(zbx_date2age($h_data['services'][$name]['time']), $class); $hintTable->addRow($timeColumn); } $column = new CCol($hint, $class); if (!is_null($hintTable)) { $column->setHint($hintTable); } $row[] = $column; } $discoveryTable->addRow($row); } } $discoveryWidget->addItem($discoveryTable); return $discoveryWidget;
if ($host['status'] == HOST_STATUS_MONITORED) { $style = 'off'; } elseif ($host['status'] == HOST_STATUS_TEMPLATE) { $style = 'unknown'; } else { $style = 'on'; } if ($hosts) { $hosts[] = ', '; } $hosts[] = new CLink($host['name'], 'hosts.php?form=update&hostid=' . $host['hostid'], $style); } } $lastAccess = '-'; if (isset($proxy['lastaccess'])) { $lastAccess = $proxy['lastaccess'] == 0 ? '-' : zbx_date2age($proxy['lastaccess']); } $proxyTable->addRow(array(new CCheckBox('hosts[' . $proxy['proxyid'] . ']', null, null, $proxy['proxyid']), isset($proxy['host']) ? new CLink($proxy['host'], 'proxies.php?form=update&proxyid=' . $proxy['proxyid']) : '', isset($proxy['status']) && $proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? _('Active') : _('Passive'), $lastAccess, isset($proxy['host']) ? count($proxy['hosts']) : '', isset($proxy['item_count']) ? $proxy['item_count'] : 0, isset($proxy['perf']) ? $proxy['perf'] : '-', new CCol(empty($hosts) ? '-' : $hosts, 'wraptext'))); } // create go buttons $goComboBox = new CComboBox('action'); $goOption = new CComboItem('proxy.massenable', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable hosts monitored by selected proxies?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('proxy.massdisable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable hosts monitored by selected proxies?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('proxy.massdelete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected proxies?')); $goComboBox->addItem($goOption); $goButton = new CSubmit('goButton', _('Go') . ' (0)');
function make_popup_eventlist($triggerId, $eventId) { $config = select_config(); $table = new CTableInfo(); $table->setAttribute('style', 'width: 400px;'); // if acknowledges are turned on, we show 'ack' column if ($config['event_ack_enable']) { $table->setHeader(array(_('Time'), _('Status'), _('Duration'), _('Age'), _('Ack'))); } else { $table->setHeader(array(_('Time'), _('Status'), _('Duration'), _('Age'))); } $events = API::Event()->get(array('source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'output' => API_OUTPUT_EXTEND, 'objectids' => $triggerId, 'eventid_till' => $eventId, 'select_acknowledges' => API_OUTPUT_COUNT, 'sortfield' => array('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(array(zbx_date2str(_('d M Y H:i:s'), $event['clock']), $eventStatusSpan, $duration, zbx_date2age($event['clock']), getEventAckState($event, false, false))); } return $table; }
$form->addVar('config', get_request('config', 0)); $table = new CTableInfo(S_NO_PROXIES_DEFINED); $table->setHeader(array(array(new CCheckBox('all_hosts', NULL, "CheckAll('" . $form->GetName() . "','all_hosts');"), SPACE, make_sorting_link(S_NAME, 'g.name')), S_LASTSEEN_AGE, ' # ', S_MEMBERS)); $db_proxies = DBselect('SELECT hostid,host,lastaccess ' . ' FROM hosts' . ' WHERE status IN (' . HOST_STATUS_PROXY . ') ' . ' AND ' . DBin_node('hostid') . order_by('host')); while ($db_proxy = DBfetch($db_proxies)) { $count = 0; $hosts = array(); $sql = 'SELECT DISTINCT host,status ' . ' FROM hosts' . ' WHERE proxy_hostid=' . $db_proxy['hostid'] . ' AND ' . DBcondition('hostid', $available_hosts) . ' AND status in (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' ORDER BY host'; $db_hosts = DBselect($sql); while ($db_host = DBfetch($db_hosts)) { $style = $db_host['status'] == HOST_STATUS_MONITORED ? NULL : ($db_host['status'] == HOST_STATUS_TEMPLATE ? 'unknown' : 'on'); array_push($hosts, empty($hosts) ? '' : ', ', new CSpan($db_host['host'], $style)); $count++; } if ($db_proxy['lastaccess'] != 0) { $lastclock = zbx_date2age($db_proxy['lastaccess']); } else { $lastclock = '-'; } $table->addRow(array(array(new CCheckBox('hosts[' . $db_proxy['hostid'] . ']', NULL, NULL, $db_proxy['hostid']), SPACE, new CLink($db_proxy['host'], 'hosts.php?form=update&hostid=' . $db_proxy['hostid'] . url_param('config'), 'action')), $lastclock, $count, new CCol(empty($hosts) ? '-' : $hosts, 'wraptext'))); $row_count++; } $table->setFooter(new CCol(array(new CButtonQMessage('activate', S_ACTIVATE_SELECTED, S_ACTIVATE_SELECTED_HOSTS_Q), SPACE, new CButtonQMessage('disable', S_DISABLE_SELECTED, S_DISABLE_SELECTED_HOSTS_Q), SPACE, new CButtonQMessage('delete', S_DELETE_SELECTED, S_DELETE_SELECTED_GROUPS_Q)))); $form->addItem($table); $form->show(); } } else { if ($_REQUEST['config'] == 6) { if (isset($_REQUEST["form"])) { $frmMaintenance = new CForm('hosts.php', 'post'); $frmMaintenance->setName(S_MAINTENANCE);
foreach ($trigger['events'] as $enum => $event) { $i++; $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']); $statusSpan = new CCol($eventStatusSpan); $statusSpan->setColSpan(2); $ack = getEventAckState($event, true); $ackCheckBox = $event['acknowledged'] == 0 && $event['value'] == TRIGGER_VALUE_TRUE ? new CCheckBox('events[' . $event['eventid'] . ']', 'no', null, $event['eventid']) : SPACE; $clock = new CLink(zbx_date2str(_('d M Y H:i:s'), $event['clock']), 'tr_events.php?triggerid=' . $trigger['triggerid'] . '&eventid=' . $event['eventid']); $nextClock = isset($trigger['events'][$enum - 1]) ? $trigger['events'][$enum - 1]['clock'] : time(); $emptyColumn = new CCol(SPACE); $emptyColumn->setColSpan(3); $ackCheckBoxColumn = new CCol($ackCheckBox); $ackCheckBoxColumn->setColSpan(2); $row = new CRow(array(SPACE, $config['event_ack_enable'] ? $ackCheckBoxColumn : null, $statusSpan, $clock, zbx_date2age($event['clock']), zbx_date2age($nextClock, $event['clock']), $config['event_ack_enable'] ? $ack : null, $displayNodes ? SPACE : null, $emptyColumn), 'odd_row'); $row->setAttribute('data-parentid', $trigger['triggerid']); $row->addStyle('display: none;'); $triggerTable->addRow($row); if ($i > $config['event_show_max']) { break; } } } } /* * Go buttons */ $footer = null; if ($config['event_ack_enable']) { $goComboBox = new CComboBox('go');
foreach ($proxy_items as $pitems) { if (!isset($proxies[$pitems['proxy_hostid']]['item_count'])) { $proxies[$pitems['proxy_hostid']]['item_count'] = 0; } $proxies[$pitems['proxy_hostid']]['item_count'] += $pitems['rowscount']; } // }}} CALCULATE ITEMS foreach ($proxies as $pnum => $proxy) { $hosts = array(); foreach ($proxy['hosts'] as $host) { $style = $host['status'] == HOST_STATUS_MONITORED ? 'off' : ($host['status'] == HOST_STATUS_TEMPLATE ? 'unknown' : 'on'); $hosts[] = new CLink($host['host'], 'hosts.php?form=update&hostid=' . $host['hostid'], $style); $hosts[] = ', '; } array_pop($hosts); $table->addRow(array(new CCheckBox('hosts[' . $proxy['proxyid'] . ']', NULL, NULL, $proxy['proxyid']), new CLink($proxy['host'], 'proxies.php?form=update&hostid=' . $proxy['proxyid']), $proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? S_PROXY_ACTIVE : S_PROXY_PASSIVE, $proxy['lastaccess'] == 0 ? '-' : zbx_date2age($proxy['lastaccess']), count($proxy['hosts']), isset($proxy['item_count']) ? $proxy['item_count'] : 0, isset($proxy['perf']) ? $proxy['perf'] : '-', new CCol(empty($hosts) ? '-' : $hosts, 'wraptext'))); } //----- GO ------ $goBox = new CComboBox('go'); $goOption = new CComboItem('activate', S_ACTIVATE_SELECTED); $goOption->setAttribute('confirm', S_ENABLE_SELECTED_PROXIES); $goBox->addItem($goOption); $goOption = new CComboItem('disable', S_DISABLE_SELECTED); $goOption->setAttribute('confirm', S_DISABLE_SELECTED_PROXIES); $goBox->addItem($goOption); $goOption = new CComboItem('delete', S_DELETE_SELECTED); $goOption->setAttribute('confirm', S_DELETE_SELECTED_PROXIES); $goBox->addItem($goOption); // goButton name is necessary!!! $goButton = new CButton('goButton', S_GO . ' (0)'); $goButton->setAttribute('id', 'goButton');
// }}} MAINTENANCE FORM // MAINTENANCE PERIODS {{{ $tblPeriod = new CTableInfo(); if (isset($_REQUEST['maintenanceid']) && !isset($_REQUEST['form_refresh'])) { $timeperiods = array(); $sql = 'SELECT DISTINCT mw.maintenanceid, tp.* ' . ' FROM timeperiods tp, maintenances_windows mw ' . ' WHERE mw.maintenanceid=' . $_REQUEST['maintenanceid'] . ' AND tp.timeperiodid=mw.timeperiodid ' . ' ORDER BY tp.timeperiod_type ASC'; $db_timeperiods = DBselect($sql); while ($timeperiod = DBfetch($db_timeperiods)) { $timeperiods[] = $timeperiod; } } else { $timeperiods = get_request('timeperiods', array()); } $tblPeriod->setHeader(array(new CCheckBox('all_periods', null, 'checkAll("' . S_PERIOD . '","all_periods","g_timeperiodid");'), S_PERIOD_TYPE, S_SCHEDULE, S_PERIOD, S_ACTION)); foreach ($timeperiods as $id => $timeperiod) { $tblPeriod->addRow(array(new CCheckBox('g_timeperiodid[]', 'no', null, $id), timeperiod_type2str($timeperiod['timeperiod_type']), new CCol(shedule2str($timeperiod), 'wraptext'), zbx_date2age(0, $timeperiod['period']), new CButton('edit_timeperiodid[' . $id . ']', S_EDIT))); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][timeperiod_type]', $timeperiod['timeperiod_type'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][every]', $timeperiod['every'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][month]', $timeperiod['month'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][dayofweek]', $timeperiod['dayofweek'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][day]', $timeperiod['day'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][start_time]', $timeperiod['start_time'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][start_date]', $timeperiod['start_date'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][period]', $timeperiod['period'])); } $footer = array(); if (!isset($_REQUEST['new_timeperiod'])) { $footer[] = new CButton('new_timeperiod', S_NEW); } if ($tblPeriod->ItemsCount() > 0) { $footer[] = new CButton('del_timeperiod', S_DELETE_SELECTED);
$hostCount = $this->data['groupCounts'][$group['groupid']]['hosts']; $templateCount = $this->data['groupCounts'][$group['groupid']]['templates']; // name $name = array(); if ($group['discoveryRule']) { $name[] = new CLink($group['discoveryRule']['name'], 'host_prototypes.php?parent_discoveryid=' . $group['discoveryRule']['itemid'], 'parent-discovery'); $name[] = NAME_DELIMITER; } $name[] = new CLink($group['name'], 'hostgroups.php?form=update&groupid=' . $group['groupid']); // status if ($showStatus) { $status = array(); // discovered item lifetime indicator if ($group['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $group['groupDiscovery']['ts_delete']) { $deleteError = new CDiv(SPACE, 'status_icon iconwarning'); $deleteError->setHint(_s('The host group is not discovered anymore and will be deleted in %1$s (on %2$s at %3$s).', zbx_date2age($group['groupDiscovery']['ts_delete']), zbx_date2str(_('d M Y'), $group['groupDiscovery']['ts_delete']), zbx_date2str(_('H:i:s'), $group['groupDiscovery']['ts_delete']))); $status[] = $deleteError; } } $hostGroupTable->addRow(array(new CCheckBox('groups[' . $group['groupid'] . ']', null, null, $group['groupid']), $this->data['displayNodes'] ? $group['nodename'] : null, $name, array(array(new CLink(_('Templates'), 'templates.php?groupid=' . $group['groupid'], 'unknown'), ' (' . $templateCount . ')'), BR(), array(new CLink(_('Hosts'), 'hosts.php?groupid=' . $group['groupid']), ' (' . $hostCount . ')')), new CCol(empty($hostsOutput) ? '-' : $hostsOutput, 'wraptext'), $showStatus ? $status : null)); } // create go button $goComboBox = new CComboBox('go'); $goOption = new CComboItem('activate', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected hosts?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('disable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable hosts in the selected host groups?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('delete', _('Delete selected')); $goOption->setAttribute('confirm', _('Delete selected host groups?'));
$status = new CCol(new CLink(itemIndicator($item['status'], $item['state']), '?group_itemid=' . $item['itemid'] . '&hostid=' . $item['hostid'] . '&go=' . ($item['status'] ? 'activate' : 'disable'), itemIndicatorStyle($item['status'], $item['state']))); if ($data['showErrorColumn']) { $statusIcons = array(); if ($item['status'] == ITEM_STATUS_ACTIVE) { if (zbx_empty($item['error'])) { $error = new CDiv(SPACE, 'status_icon iconok'); } else { $error = new CDiv(SPACE, 'status_icon iconerror'); $error->setHint($item['error'], '', 'on'); } $statusIcons[] = $error; } // discovered item lifetime indicator if ($item['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $item['itemDiscovery']['ts_delete']) { $deleteError = new CDiv(SPACE, 'status_icon iconwarning'); $deleteError->setHint(_s('The item is not discovered anymore and will be deleted in %1$s (on %2$s at %3$s).', zbx_date2age($item['itemDiscovery']['ts_delete']), zbx_date2str(_('d M Y'), $item['itemDiscovery']['ts_delete']), zbx_date2str(_('H:i:s'), $item['itemDiscovery']['ts_delete']))); $statusIcons[] = $deleteError; } } $triggerHintTable = new CTableInfo(); $triggerHintTable->setHeader(array(_('Severity'), _('Name'), _('Expression'), _('Status'))); // triggers info foreach ($item['triggers'] as $num => &$trigger) { $trigger = $this->data['itemTriggers'][$trigger['triggerid']]; $triggerDescription = array(); if ($trigger['templateid'] > 0) { if (!isset($this->data['triggerRealHosts'][$trigger['triggerid']])) { $triggerDescription[] = new CSpan('HOST', 'unknown'); $triggerDescription[] = ':'; } else { $realHost = reset($this->data['triggerRealHosts'][$trigger['triggerid']]);
$in_encryption = ''; $out_encryption = ''; if ($proxy['status'] == HOST_STATUS_PROXY_PASSIVE) { // input encryption if ($proxy['tls_connect'] == HOST_ENCRYPTION_NONE) { $in_encryption = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN); } elseif ($proxy['tls_connect'] == HOST_ENCRYPTION_PSK) { $in_encryption = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN); } else { $in_encryption = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN); } } else { // output encryption $out_encryption_array = []; if (($proxy['tls_accept'] & HOST_ENCRYPTION_NONE) == HOST_ENCRYPTION_NONE) { $out_encryption_array[] = (new CSpan(_('None')))->addClass(ZBX_STYLE_STATUS_GREEN); } if (($proxy['tls_accept'] & HOST_ENCRYPTION_PSK) == HOST_ENCRYPTION_PSK) { $out_encryption_array[] = (new CSpan(_('PSK')))->addClass(ZBX_STYLE_STATUS_GREEN); } if (($proxy['tls_accept'] & HOST_ENCRYPTION_CERTIFICATE) == HOST_ENCRYPTION_CERTIFICATE) { $out_encryption_array[] = (new CSpan(_('CERT')))->addClass(ZBX_STYLE_STATUS_GREEN); } $out_encryption = (new CDiv($out_encryption_array))->addClass(ZBX_STYLE_STATUS_CONTAINER); } $proxyTable->addRow([new CCheckBox('proxyids[' . $proxy['proxyid'] . ']', $proxy['proxyid']), (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), $proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? _('Active') : _('Passive'), $proxy['status'] == HOST_STATUS_PROXY_ACTIVE ? $out_encryption : $in_encryption, $proxy['lastaccess'] == 0 ? (new CSpan(_('Never')))->addClass(ZBX_STYLE_RED) : zbx_date2age($proxy['lastaccess']), count($proxy['hosts']), array_key_exists('item_count', $proxy) ? $proxy['item_count'] : 0, array_key_exists('perf', $proxy) ? $proxy['perf'] : '', $hosts ? $hosts : '']); } // append table to form $proxyForm->addItem([$proxyTable, $data['paging'], new CActionButtonList('action', 'proxyids', ['proxy.hostenable' => ['name' => _('Enable hosts'), 'confirm' => _('Enable hosts monitored by selected proxies?')], 'proxy.hostdisable' => ['name' => _('Disable hosts'), 'confirm' => _('Disable hosts monitored by selected proxies?')], 'proxy.delete' => ['name' => _('Delete'), 'confirm' => _('Delete selected proxies?')]])]); // append form to widget $widget->addItem($proxyForm)->show();
function make_latest_issues($filter = array()) { global $page; $config = select_config(); $limit = isset($filter['limit']) ? $filter['limit'] : 20; $options = array('groupids' => $filter['groupids'], 'monitored' => 1, 'maintenance' => $filter['maintenance'], 'skipDependent' => 1, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'select_groups' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'sortfield' => 'lastchange', 'sortorder' => ZBX_SORT_DOWN, 'limit' => $limit); if (isset($filter['hostids'])) { $options['hostids'] = $filter['hostids']; } $triggers = CTrigger::get($options); // GATHER HOSTS FOR SELECTED TRIGGERS {{{ $triggers_hosts = array(); foreach ($triggers as $tnum => $trigger) { // if trigger is lost(broken expression) we skip it if (empty($trigger['hosts'])) { unset($triggers[$tnum]); continue; } $triggers_hosts = array_merge($triggers_hosts, $trigger['hosts']); } $triggers_hosts = zbx_toHash($triggers_hosts, 'hostid'); $triggers_hostids = array_keys($triggers_hosts); // }}} GATHER HOSTS FOR SELECTED TRIGGERS $scripts_by_hosts = CScript::getScriptsByHosts($triggers_hostids); $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS)); $thosts_cache = array(); foreach ($triggers as $tnum => $trigger) { // Check for dependencies $group = reset($trigger['groups']); $host = reset($trigger['hosts']); $trigger['hostid'] = $host['hostid']; $trigger['host'] = $host['host']; $host = null; $menus = ''; $host_nodeid = id2nodeid($trigger['hostid']); foreach ($scripts_by_hosts[$trigger['hostid']] as $id => $script) { $script_nodeid = id2nodeid($script['scriptid']); if (bccomp($host_nodeid, $script_nodeid) == 0) { $menus .= "[" . zbx_jsvalue($script['name']) . ",\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $trigger['hostid'] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } if (!empty($scripts_by_hosts)) { $menus = "['" . S_TOOLS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus; } if (isset($thosts_cache[$trigger['hostid']])) { $hprofile = $thosts_cache[$trigger['hostid']]; } else { $hprofile = CHost::get(array('hostids' => $trigger['hostid'], 'output' => API_OUTPUT_SHORTEN, 'select_profile' => API_OUTPUT_EXTEND)); $hprofile = reset($hprofile); $thosts_cache[$hprofile['hostid']] = $hprofile; } $menus .= "['" . S_LINKS . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=" . $group['groupid'] . '&hostid=' . $trigger['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; if (!empty($hprofile['profile'])) { $menus .= "['" . S_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=0')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } if (!empty($hprofile['profile_ext'])) { $menus .= "['" . S_EXTENDED_PROFILE . "',\"javascript: redirect('hostprofiles.php?hostid=" . $trigger['hostid'] . "&prof_type=1')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } $menus = rtrim($menus, ','); $menus = 'show_popup_menu(event,[' . $menus . '],180);'; $host = new CSpan($trigger['host'], 'link_menu pointer'); $host->setAttribute('onclick', 'javascript: ' . $menus); //$host = new CSpan($trigger['host'],'link_menu pointer'); //$host->setAttribute('onclick','javascript: '.$menus); // Maintenance {{{ $trigger_host = $triggers_hosts[$trigger['hostid']]; $text = null; $style = 'link_menu'; if ($trigger_host['maintenance_status']) { $style .= ' orange'; $options = array('maintenanceids' => $trigger_host['maintenanceid'], 'output' => API_OUTPUT_EXTEND); $maintenances = CMaintenance::get($options); $maintenance = reset($maintenances); $text = $maintenance['name']; $text .= ' [' . ($trigger_host['maintenance_type'] ? S_NO_DATA_MAINTENANCE : S_NORMAL_MAINTENANCE) . ']'; } $host = new CSpan($trigger['host'], $style . ' pointer'); $host->setAttribute('onclick', 'javascript: ' . $menus); if (!is_null($text)) { $host->setHint($text, '', '', false); } // }}} Maintenance $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged' . ' FROM events e' . ' WHERE e.object=' . EVENT_OBJECT_TRIGGER . ' AND e.objectid=' . $trigger['triggerid'] . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC'; $res_events = DBSelect($event_sql, 1); while ($row_event = DBfetch($res_events)) { $ack = NULL; if ($config['event_ack_enable']) { if ($row_event['acknowledged'] == 1) { $ack_info = make_acktab_by_eventid($row_event['eventid']); $ack_info->setAttribute('style', 'width: auto;'); $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'off'); $ack->setHint($ack_info, '', '', false); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'] . '&backurl=' . $page['file'], 'on'); } } // $description = expand_trigger_description($row['triggerid']); $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT); //actions $actions = get_event_actions_stat_hints($row_event['eventid']); $clock = new CLink(zbx_date2str(S_BLOCKS_LATEST_ISSUES_DATE_FORMAT, $row_event['clock']), 'events.php?triggerid=' . $trigger['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock']); if ($trigger['url']) { $description = new CLink($description, $trigger['url'], null, null, true); } else { $description = new CSpan($description, 'pointer'); } $description = new CCol($description, get_severity_style($trigger['priority'])); $description->setHint(make_popup_eventlist($row_event['eventid'], $trigger['type'], $trigger['triggerid']), '', '', false); $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions)); } unset($trigger, $description, $actions); } $table->setFooter(new CCol(S_UPDATED . ': ' . zbx_date2str(S_BLOCKS_LATEST_ISSUES_TIME_FORMAT))); return $table; }
// info if ($data['showInfoColumn']) { $infoIcons = array(); if ($item['status'] == ITEM_STATUS_ACTIVE && !zbx_empty($item['error'])) { $info = new CDiv(SPACE, 'status_icon iconerror'); $info->setHint($item['error'], 'on'); $infoIcons[] = $info; } // discovered item lifetime indicator if ($item['flags'] == ZBX_FLAG_DISCOVERY_CREATED && $item['itemDiscovery']['ts_delete']) { $deleteError = new CDiv(SPACE, 'status_icon iconwarning'); // Check if item should've been deleted in the past. if ($currentTime > $item['itemDiscovery']['ts_delete']) { $deleteError->setHint(_s('The item is not discovered anymore and will be deleted the next time discovery rule is processed.')); } else { $deleteError->setHint(_s('The item is not discovered anymore and will be deleted in %1$s (on %2$s at %3$s).', zbx_date2age($item['itemDiscovery']['ts_delete']), zbx_date2str(DATE_FORMAT, $item['itemDiscovery']['ts_delete']), zbx_date2str(TIME_FORMAT, $item['itemDiscovery']['ts_delete']))); } $infoIcons[] = $deleteError; } if (!$infoIcons) { $infoIcons[] = ''; } } else { $infoIcons = null; } // triggers info $triggerHintTable = new CTableInfo(); $triggerHintTable->setHeader(array(_('Severity'), _('Name'), _('Expression'), _('Status'))); foreach ($item['triggers'] as $num => &$trigger) { $trigger = $this->data['itemTriggers'][$trigger['triggerid']]; $triggerDescription = array();
function make_trigger_table($triggers, $host_name) { $table = new CTableInfo(); $table->setHeader(array(_('Host'), _('Problem'), _('Age'))); foreach ($triggers as $trigger) { $description = $trigger["description"]; $r = new CRow(); $r->addItem($host_name); $r->addItem(new CCol($description, getSeverityStyle($trigger['priority']))); $r->addItem(zbx_date2age($trigger['lastchange'])); $table->addRow($r); } return $table; }
/** * Generate table for dashboard triggers popup. * * @see make_system_status * * @param array $triggers * @param string $backurl * @param array $actions * @param array $config * * @return CTableInfo */ function makeTriggersPopup(array $triggers, $backurl, array $actions, array $config) { $popupTable = (new CTableInfo())->setHeader([_('Host'), _('Issue'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions')]); CArrayHelper::sort($triggers, [['field' => 'lastchange', 'order' => ZBX_SORT_DOWN]]); foreach ($triggers as $trigger) { $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, array('clock' => $trigger['event']['clock'], 'ns' => $trigger['event']['ns']))); // unknown triggers $unknown = ''; if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) { $unknown = makeUnknownIcon($trigger['error']); } // ack if ($config['event_ack_enable']) { $ack = isset($trigger['event']['eventid']) ? getEventAckState($trigger['event'], $backurl) : (new CSpan(_('No events')))->addClass(ZBX_STYLE_GREY); } else { $ack = null; } // action $action = isset($trigger['event']['eventid']) && isset($actions[$trigger['event']['eventid']]) ? $actions[$trigger['event']['eventid']] : ''; $popupTable->addRow([$trigger['hosts'][0]['name'], getSeverityCell($trigger['priority'], $config, $description), zbx_date2age($trigger['lastchange']), $unknown, $ack, (new CCol($action))->addClass(ZBX_STYLE_NOWRAP)]); } return $popupTable; }
$table = new CTableInfo(S_NO_EVENTS_FOUND); $table->setHeader(array(make_sorting_link(S_TIME, 'clock'), is_show_all_nodes() ? S_NODE : null, $_REQUEST['hostid'] == 0 ? S_HOST : null, make_sorting_link(S_DESCRIPTION, 'desc'), make_sorting_link(S_STATUS, 'status'), make_sorting_link(S_SEVERITY, 'priority'), S_DURATION, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS)); if (!empty($triggers)) { $clock = array(); $events = array(); $sql = 'SELECT e.eventid, e.objectid as triggerid, e.clock, e.value, e.acknowledged ' . ' FROM events e ' . ' WHERE ' . DBcondition('e.objectid', $triggerids) . ' AND (e.object+0)=' . EVENT_OBJECT_TRIGGER . $sql_cond . ' ORDER BY e.clock DESC'; $result = DBselect($sql, 0 == $show_unknown ? $limit * 50 : $limit); while (($row = DBfetch($result)) && $col < $limit) { $row = array_merge($triggers[$row['triggerid']], $row); if (0 == $show_unknown && !event_initial_time($row, $show_unknown)) { continue; } $row['desc'] = expand_trigger_description_by_data($row, ZBX_FLAG_EVENT); $row['duration'] = zbx_date2age($row['clock']); if ($next_event = get_next_event($row, $show_unknown)) { $row['duration'] = zbx_date2age($row['clock'], $next_event['clock']); } $row['value'] = new CCol(trigger_value2str($row['value']), get_trigger_value_style($row['value'])); $col++; $clock[] = $row['clock']; $events[] = $row; } $last_clock = !empty($clock) ? min($clock) : null; order_page_result($events, 'clock', ZBX_SORT_DOWN); foreach ($events as $num => $row) { // Actions $actions = get_event_actions_status($row['eventid']); //-------- if ($config['event_ack_enable']) { if ($row['acknowledged'] == 1) { $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row['eventid'], 'action');
public function period2str($period) { return ' (' . zbx_date2age(0, $period) . ')'; }
/** * Easy way to view time data. * * @static * * @param array $options * @param int $options['period'] * @param string $options['stime'] * @param string $options['stimeNow'] * @param string $options['starttime'] * @param string $options['usertime'] * @param int $options['isNow'] */ public static function debugTime(array $time = array()) { return 'period=' . zbx_date2age(0, $time['period']) . ', (' . $time['period'] . ')<br/>' . 'starttime=' . date('F j, Y, g:i a', zbxDateToTime($time['starttime'])) . ', (' . $time['starttime'] . ')<br/>' . 'stime=' . date('F j, Y, g:i a', zbxDateToTime($time['stime'])) . ', (' . $time['stime'] . ')<br/>' . 'stimeNow=' . date('F j, Y, g:i a', zbxDateToTime($time['stimeNow'])) . ', (' . $time['stimeNow'] . ')<br/>' . 'usertime=' . date('F j, Y, g:i a', zbxDateToTime($time['usertime'])) . ', (' . $time['usertime'] . ')<br/>' . 'isnow=' . $time['isNow'] . '<br/>'; }
} else { $toDate = zbxDateToTime($this->data['active_till']); $activeTill = $this->data['active_till']; } $maintenanceForm->addVar('active_till', $activeTill); $maintenanceFormList->addRow(_('Active since'), createDateSelector('active_since', $fromDate, 'active_till')); $maintenanceFormList->addRow(_('Active till'), createDateSelector('active_till', $toDate, 'active_since')); $maintenanceFormList->addRow(_('Description'), new CTextArea('description', $this->data['description'])); /* * Maintenance period tab */ $maintenancePeriodFormList = new CFormList('maintenancePeriodFormList'); $maintenancePeriodTable = new CTable(_('No maintenance periods defined.'), 'formElementTable'); $maintenancePeriodTable->setHeader(array(_('Period type'), _('Schedule'), _('Period'), _('Action'))); foreach ($this->data['timeperiods'] as $id => $timeperiod) { $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'));
$hostids = zbx_objectValues($hosts, 'hostid'); $hosts = API::Host()->get(['output' => ['name', 'hostid', 'status'], 'hostids' => $hostids, 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true]); // fetch scripts for the host JS menu if (!$csvExport && $pageFilter->hostid == 0) { $scripts = API::Script()->getScriptsByHosts($hostids); } // actions $actions = makeEventsActions(zbx_objectValues($events, 'eventid')); // events foreach ($events as $event) { $trigger = $triggers[$event['objectid']]; $host = reset($trigger['hosts']); $host = $hosts[$host['hostid']]; $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $event['clock'], 'ns' => $event['ns']])); // duration $event['duration'] = ($nextEvent = get_next_event($event, $events)) ? zbx_date2age($event['clock'], $nextEvent['clock']) : zbx_date2age($event['clock']); // action $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : ''; if ($csvExport) { $csvRows[] = [zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), $pageFilter->hostid == 0 ? $host['name'] : null, $description, trigger_value2str($event['value']), getSeverityName($trigger['priority'], $config), $event['duration'], $config['event_ack_enable'] ? $event['acknowledges'] ? _('Yes') : _('No') : null, strip_tags((string) $action)]; } else { $triggerDescription = (new CSpan($description))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getTrigger($trigger, null, $event['clock'])); // add colors and blinking to span depending on configuration and trigger parameters $statusSpan = new CSpan(trigger_value2str($event['value'])); addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); // host JS menu link $hostName = null; if ($pageFilter->hostid == 0) { $hostName = (new CSpan($host['name']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); } $table->addRow([(new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']))->addClass('action'), $hostName, $triggerDescription, $statusSpan, getSeverityCell($trigger['priority'], $config, null, !$event['value']), $event['duration'], $config['event_ack_enable'] ? getEventAckState($event, $page['file']) : null, (new CCol($action))->addClass(ZBX_STYLE_NOWRAP)]);
if ($config['event_ack_enable']) { if ($event['acknowledged'] == 1) { $ack = new CLink(S_YES, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $page['file']); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $page['file'], 'on'); } } $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $event['clock'])), ZBX_FLAG_EVENT); $tr_desc = new CSpan($description, 'pointer'); $tr_desc->addAction('onclick', "create_mon_trigger_menu(event, " . " new Array({'triggerid': '" . $trigger['triggerid'] . "', 'lastchange': '" . $event['clock'] . "'})," . zbx_jsvalue($items, true) . ");"); // Duration $tr_event = $event + $trigger; if ($next_event = get_next_event($tr_event, $events, $_REQUEST['hide_unknown'])) { $event['duration'] = zbx_date2age($tr_event['clock'], $next_event['clock']); } else { $event['duration'] = zbx_date2age($tr_event['clock']); } $table->addRow(array(new CLink(zbx_date2str(S_EVENTS_ACTION_TIME_FORMAT, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid'], 'action'), is_show_all_nodes() ? get_node_name_by_elid($event['objectid']) : null, $_REQUEST['hostid'] == 0 ? $host['host'] : null, new CSpan($tr_desc, 'link_menu'), new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value'])), new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority'], $event['value'])), $event['duration'], $config['event_ack_enable'] ? $ack : NULL, $actions)); } } $table = array($paging, $table, $paging); $jsmenu = new CPUMenu(null, 170); $jsmenu->InsertJavaScript(); } $events_wdgt->addItem($table); // NAV BAR $timeline = array('period' => $effectiveperiod, 'starttime' => date('YmdHis', $starttime), 'usertime' => date('YmdHis', $till)); $dom_graph_id = 'scroll_events_id'; $objData = array('id' => 'timeline_1', 'loadSBox' => 0, 'loadImage' => 0, 'loadScroll' => 1, 'dynamic' => 0, 'mainObject' => 1); zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); zbx_add_post_js('timeControl.processObjects();');
function get_maintenance_periods() { $tblPeriod = new CTableInfo(); $tblPeriod->addOption('style', 'background-color: #CCC;'); if (isset($_REQUEST['maintenanceid']) && !isset($_REQUEST["form_refresh"])) { $timeperiods = array(); $sql = 'SELECT DISTINCT mw.maintenanceid, tp.* ' . ' FROM timeperiods tp, maintenances_windows mw ' . ' WHERE mw.maintenanceid=' . $_REQUEST['maintenanceid'] . ' AND tp.timeperiodid=mw.timeperiodid ' . ' ORDER BY tp.timeperiod_type ASC'; $db_timeperiods = DBselect($sql); while ($timeperiod = DBfetch($db_timeperiods)) { $timeperiods[] = $timeperiod; } } else { $timeperiods = get_request('timeperiods', array()); } $tblPeriod->SetHeader(array(new CCheckBox('all_periods', null, 'CheckAll("' . S_PERIOD . '","all_periods","g_timeperiodid");'), S_PERIOD_TYPE, S_SHEDULE, S_PERIOD, S_ACTION)); // zbx_rksort($timeperiods); foreach ($timeperiods as $id => $timeperiod) { $period_type = timeperiod_type2str($timeperiod['timeperiod_type']); $shedule_str = shedule2str($timeperiod); $tblPeriod->addRow(array(new CCheckBox('g_timeperiodid[]', 'no', null, $id), $period_type, new CCol($shedule_str, 'wraptext'), zbx_date2age(0, $timeperiod['period']), new CButton('edit_timeperiodid[' . $id . ']', S_EDIT))); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][timeperiod_type]', $timeperiod['timeperiod_type'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][every]', $timeperiod['every'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][month]', $timeperiod['month'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][dayofweek]', $timeperiod['dayofweek'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][day]', $timeperiod['day'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][start_time]', $timeperiod['start_time'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][date]', $timeperiod['date'])); $tblPeriod->addItem(new Cvar('timeperiods[' . $id . '][period]', $timeperiod['period'])); } unset($timeperiods); $tblPeriodFooter = new CTableInfo(null); $oper_buttons = array(); if (!isset($_REQUEST['new_timeperiod'])) { $oper_buttons[] = new CButton('new_timeperiod', S_NEW); } if ($tblPeriod->ItemsCount() > 0) { $oper_buttons[] = new CButton('del_timeperiod', S_DELETE_SELECTED); } $td = new CCol($oper_buttons); $td->addOption('colspan', 7); $td->addOption('style', 'text-align: right;'); $tblPeriodFooter->SetFooter($td); // end of condition list preparation return array($tblPeriod, $tblPeriodFooter); }
if ($host['proxy_hostid']) { $proxyHostIds[$host['proxy_hostid']] = $host['proxy_hostid']; } } if ($proxyHostIds) { $proxies = API::Proxy()->get(['proxyids' => $proxyHostIds, 'output' => ['proxyid', 'host'], 'preservekeys' => true]); } $table->setHeader([_('Scheduled check'), _('Delayed by'), _('Host'), _('Name')]); $i = 0; foreach ($queueData as $itemData) { if (!isset($items[$itemData['itemid']])) { continue; } // display only the first 500 items $i++; if ($i > QUEUE_DETAIL_ITEM_COUNT) { break; } $item = $items[$itemData['itemid']]; $host = reset($item['hosts']); $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $itemData['nextcheck']), zbx_date2age($itemData['nextcheck']), isset($proxies[$hosts[$item['hostid']]['proxy_hostid']]) ? $proxies[$hosts[$item['hostid']]['proxy_hostid']]['host'] . NAME_DELIMITER . $host['name'] : $host['name'], $item['name_expanded']]); } } // display the table footer if ($config == QUEUE_OVERVIEW_BY_PROXY) { $table->setFooter(new CCol(_('Total') . ': ' . $table->getNumRows())); } elseif ($config == QUEUE_DETAILS) { $table->setFooter(new CCol(_('Total') . ': ' . $table->getNumRows() . (count($queueData) > QUEUE_DETAIL_ITEM_COUNT ? ' (' . _('Truncated') . ')' : ''))); } $widget->addItem($table)->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
function convert_units($value, $units) { // Special processing for unix timestamps if ($units == 'unixtime') { $ret = date('Y.m.d H:i:s', $value); return $ret; } //Special processing of uptime if ($units == 'uptime') { $ret = ''; $days = floor($value / (24 * 3600)); if ($days > 0) { $value = $value - $days * (24 * 3600); } $hours = floor($value / 3600); if ($hours > 0) { $value = $value - $hours * 3600; } $min = floor($value / 60); if ($min > 0) { $value = $value - $min * 60; } if ($days == 0) { $ret = sprintf("%02d:%02d:%02d", $hours, $min, $value); } else { $ret = sprintf("%d days, %02d:%02d:%02d", $days, $hours, $min, $value); } return $ret; } // Special processing for seconds if ($units == 's') { return zbx_date2age(0, $value, true); } $u = ''; // Special processing for bits (kilo=1000, not 1024 for bits) if ($units == 'b' || $units == 'bps') { $abs = abs($value); if ($abs < 1000) { $u = ""; } else { if ($abs < 1000 * 1000) { $u = 'K'; $value = $value / 1000; } else { if ($abs < 1000 * 1000 * 1000) { $u = 'M'; $value = $value / (1000 * 1000); } else { $u = 'G'; $value = $value / (1000 * 1000 * 1000); } } } if (round($value) == round($value, 2)) { $s = sprintf('%.0f', $value); } else { $s = sprintf('%.2f', $value); } return "{$s} {$u}{$units}"; } if ($units == '') { if (round($value) == round($value, 2)) { return sprintf('%.0f', $value); } else { return sprintf('%.2f', $value); } } $abs = abs($value); if ($abs < 1024) { $u = ''; } else { if ($abs < 1024 * 1024) { $u = 'K'; $value = $value / 1024; } else { if ($abs < 1024 * 1024 * 1024) { $u = 'M'; $value = $value / (1024 * 1024); } else { if ($abs < 1024 * 1024 * 1024 * 1024) { $u = 'G'; $value = $value / (1024 * 1024 * 1024); } else { $u = 'T'; $value = $value / (1024 * 1024 * 1024 * 1024); } } } } if (round($value) == round($value, 2)) { $s = sprintf('%.0f', $value); } else { $s = sprintf('%.2f', $value); } return "{$s} {$u}{$units}"; }
function make_latest_issues($params = array()) { global $USER_DETAILS; $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY); $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array()); $scripts_by_hosts = get_accessible_scripts_by_hosts($available_hosts); $config = select_config(); $sql_select = ''; $sql_from = ''; $sql_where = ''; $limit = 20; if (!empty($params)) { if (isset($params['limit'])) { $limit = $params['limit']; } if (isset($params['groupid']) && $params['groupid'] > 0) { $sql_select .= ',g.name '; $sql_from .= ',groups g '; $sql_where .= ' AND g.groupid=hg.groupid ' . ' AND hg.groupid=' . $params['groupid']; } if (isset($params['hostid']) && $params['hostid'] > 0) { $sql_where .= ' AND h.hostid=' . $params['hostid']; } } $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, isset($params['groupid']) && $params['groupid'] > 0 ? S_GROUP : null, S_HOST, S_ISSUE, S_LAST_CHANGE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS)); $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description,t.expression,t.priority,t.lastchange,t.value,h.host,h.hostid ' . $sql_select . ' FROM triggers t,hosts h,items i,functions f,hosts_groups hg ' . $sql_from . ' WHERE f.itemid=i.itemid ' . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.value=' . TRIGGER_VALUE_TRUE . $sql_where . ' ORDER BY t.lastchange DESC'; $result = DBselect($sql, $limit); while ($row = DBfetch($result)) { // Check for dependencies if (trigger_dependent($row["triggerid"])) { continue; } $host = null; $menus = ''; $host_nodeid = id2nodeid($row['hostid']); foreach ($scripts_by_hosts[$row['hostid']] as $id => $script) { $script_nodeid = id2nodeid($script['scriptid']); if (bccomp($host_nodeid, $script_nodeid) == 0) { $menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $row['hostid'] . "&scriptid=" . $script['scriptid'] . "','" . S_TOOLS . "',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; } } $menus .= "[" . zbx_jsvalue(S_LINKS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],"; $menus .= "['" . S_LATEST_DATA . "',\"javascript: redirect('latest.php?groupid=0&hostid=" . $row['hostid'] . "')\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],"; $menus = rtrim($menus, ','); $menus = "show_popup_menu(event,[[" . zbx_jsvalue(S_TOOLS) . ",null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}]," . $menus . "],180);"; $host = new CSpan($row['host'], 'link'); $host->setAttribute('onclick', 'javascript: ' . $menus); $host->setAttribute('onmouseover', "javascript: this.style.cursor = 'pointer';"); $event_sql = 'SELECT DISTINCT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type, t.url ' . ' FROM events e, triggers t ' . ' WHERE e.object=' . EVENT_SOURCE_TRIGGERS . ' AND e.objectid=' . $row['triggerid'] . ' AND t.triggerid=e.objectid ' . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC'; $res_events = DBSelect($event_sql, 1); while ($row_event = DBfetch($res_events)) { $ack = NULL; if ($config['event_ack_enable']) { if ($row_event['acknowledged'] == 1) { $ack_info = make_acktab_by_eventid($row_event['eventid']); $ack_info->setAttribute('style', 'width: auto;'); $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_event['eventid'], 'action'); $ack->setHint($ack_info); } else { $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_event['eventid'], 'on'); } } // $description = expand_trigger_description($row['triggerid']); $description = expand_trigger_description_by_data(array_merge($row, array('clock' => $row_event['clock'])), ZBX_FLAG_EVENT); //actions $actions = get_event_actions_stat_hints($row_event['eventid']); $clock = new CLink(zbx_date2str(S_DATE_FORMAT_YMDHMS, $row_event['clock']), 'events.php?triggerid=' . $row['triggerid'] . '&source=0&show_unknown=1&nav_time=' . $row_event['clock'], 'action'); if ($row_event['url']) { $description = new CLink($description, $row_event['url'], 'action', null, true); } else { $description = new CSpan($description, 'pointer'); } $description = new CCol($description, get_severity_style($row["priority"])); $description->setHint(make_popup_eventlist($row_event['eventid'], $row['type'])); $table->addRow(array(get_node_name_by_elid($row['triggerid']), $host, $description, $clock, zbx_date2age($row_event['clock']), $ack, $actions)); } unset($row, $description, $actions, $alerts, $hint); } $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time()))); return $table; }
/** * 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; }
/** * Generate table for dashboard triggers popup. * * @see make_system_status * * @param array $triggers * @param array $ackParams * @param array $actions * * @return CTableInfo */ function makeTriggersPopup(array $triggers, array $ackParams, array $actions) { $config = select_config(); $popupTable = new CTableInfo(); $popupTable->setAttribute('style', 'width: 400px;'); $popupTable->setHeader(array(is_show_all_nodes() ? _('Node') : null, _('Host'), _('Issue'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions'))); CArrayHelper::sort($triggers, array(array('field' => 'lastchange', 'order' => ZBX_SORT_DOWN))); foreach ($triggers as $trigger) { // unknown triggers $unknown = SPACE; if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) { $unknown = new CDiv(SPACE, 'status_icon iconunknown'); $unknown->setHint($trigger['error'], '', 'on'); } // ack if ($config['event_ack_enable']) { $ack = isset($trigger['event']['eventid']) ? getEventAckState($trigger['event'], true, true, $ackParams) : _('No events'); } else { $ack = null; } // action $action = isset($trigger['event']['eventid']) && isset($actions[$trigger['event']['eventid']]) ? $actions[$trigger['event']['eventid']] : _('-'); $popupTable->addRow(array(get_node_name_by_elid($trigger['triggerid']), $trigger['hosts'][0]['name'], getSeverityCell($trigger['priority'], $trigger['description']), zbx_date2age($trigger['lastchange']), $unknown, $ack, $action)); } return $popupTable; }
$arr = array(); $table->SetHeader(array(S_NEXT_CHECK, S_DELAYED_BY, is_show_all_nodes() ? S_NODE : null, S_HOST, S_DESCRIPTION)); while ($row = DBfetch($result)) { $res = calculate_item_nextcheck($row['itemid'], $row['type'], $row['delay'], $row['delay_flex'], $row['lastclock']); if (0 != $row['proxy_hostid']) { $res['nextcheck'] = $row['lastclock'] + $res['delay']; } $diff = $now - $res['nextcheck']; if ($diff <= 5) { continue; } array_push($arr, array($res['nextcheck'], $row['hostid'], $row['host'], item_description($row))); } $rows = 0; sort($arr); foreach ($arr as $r) { $rows++; if ($rows > 500) { $truncated = 1; break; } $table->AddRow(array(date(S_DATE_FORMAT_YMDHMS, $r[0]), zbx_date2age($r[0]), get_node_name_by_elid($r[1]), $r[2], $r[3])); } } } } $table->Show(); if ($_REQUEST["config"] != 0) { show_table_header(S_TOTAL . ": " . $table->GetNumRows() . ($truncated ? ' (' . S_TRUNCATED . ')' : '')); } include_once "include/page_footer.php";