public function bodyToString() { $this->cleanItems(); $total = 0; // fetch accessible host ids $hosts = API::Host()->get(array('nodeids' => get_current_nodeid(true), 'output' => array('hostid'), 'preservekeys' => true)); $hostIds = array_keys($hosts); if (remove_nodes_from_id($this->groupid) > 0) { $cond_from = ',hosts_groups hg'; $cond_where = ' AND hg.hostid=h.hostid AND hg.groupid=' . zbx_dbstr($this->groupid); } else { $cond_from = ''; $cond_where = andDbNode('h.hostid', $this->nodeid); } $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $avail = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $notav = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) AS cnt' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')' . ' AND ' . dbConditionInt('h.hostid', $hostIds) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $uncn = $host_cnt['cnt']; $total += $host_cnt['cnt']; $node = get_node_by_nodeid($this->nodeid); $header_str = _('Hosts info') . SPACE; if ($node > 0) { $header_str .= '(' . $node['name'] . ')' . SPACE; } if (remove_nodes_from_id($this->groupid) > 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= _('Group') . SPACE . '"' . $group['name'] . '"'; } else { $header_str .= _('All groups'); } $header = new CCol($header_str, 'header'); if ($this->style == STYLE_HORISONTAL) { $header->setColspan(4); } $this->addRow($header); $avail = new CCol($avail . ' ' . _('Available'), 'avail'); $notav = new CCol($notav . ' ' . _('Not available'), 'notav'); $uncn = new CCol($uncn . ' ' . _('Unknown'), 'uncn'); $total = new CCol($total . ' ' . _('Total'), 'total'); if ($this->style == STYLE_HORISONTAL) { $this->addRow(array($avail, $notav, $uncn, $total)); } else { $this->addRow($avail); $this->addRow($notav); $this->addRow($uncn); $this->addRow($total); } return parent::bodyToString(); }
public function bodyToString() { global $USER_DETAILS; $this->cleanItems(); $status = get_status(); if ($status['zabbix_server'] == S_YES) { $server = new CSpan(S_RUNNING, 'off'); } else { $server = new CSpan(S_NOT_RUNNING, 'on'); } $header = new CCol('Zabbix ' . S_SERVER_INFO, 'header'); $this->addRow($header); $this->addRow('Updated: ' . date('r', time())); $this->addRow(new CCol(array('Refreshed every: ' . $USER_DETAILS['refresh'] . ' sec ', '(', new CLink('refresh now', 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']), ')'))); $this->addRow(S_NUMBER_OF_USERS_SHORT . ': ' . $status['users_count'] . '(' . $status['users_online'] . ')'); $this->addRow(new CCol(array('Logged in as ', new CLink($USER_DETAILS['alias'], 'profile.php')))); $this->addRow(new CCol(array(new CLink('Zabbix server', 'report1.php'), ' is ', $server)), 'status'); //$this->addRow(S_VALUES_STORED.': '.$status['history_count']); //$this->addRow(S_TRENDS_STORED.': '.$status['trends_count']); $this->addRow(new CCol(array(S_NUMBER_OF_HOSTS_SHORT . ': ' . $status['hosts_count'] . '(', new CSpan($status['hosts_count_monitored'], 'off'), '/', new CSpan($status['hosts_count_not_monitored'], 'on'), '/', new CSpan($status['hosts_count_template'], 'unknown'), ')'))); $this->addRow(new CCol(array(S_NUMBER_OF_ITEMS_SHORT . ': ' . $status['items_count'] . '(', new CSpan($status['items_count_monitored'], 'off'), '/', new CSpan($status['items_count_disabled'], 'on'), '/', new CSpan($status['items_count_not_supported'], 'unknown'), ')'))); $this->addRow(new CCol(array(S_NUMBER_OF_TRIGGERS_SHORT . ': ' . $status['triggers_count'] . '(' . $status['triggers_count_enabled'] . '/' . $status['triggers_count_disabled'] . ')' . '[', new CSpan($status['triggers_count_on'], 'on'), '/', new CSpan($status['triggers_count_unknown'], 'unknown'), '/', new CSpan($status['triggers_count_off'], 'off'), ']'))); // $this->addRow(S_NUMBER_OF_EVENTS.': '.$status['events_count']); // $this->addRow(S_NUMBER_OF_ALERTS.': '.$status['alerts_count']); return parent::bodyToString(); }
public function bodyToString() { $this->cleanItems(); $status = get_status(); $server = $status['zabbix_server'] == _('Yes') ? new CSpan(_('running'), 'off') : new CSpan(_('not running'), 'on'); $serverLink = CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN ? new CLink(_('Zabbix server'), 'report1.php') : _('Zabbix server'); $this->addRow(new CCol(_('Zabbix server info'), 'nowrap ui-corner-all ui-widget-header')); $this->addRow(_('Updated') . NAME_DELIMITER . zbx_date2str(SERVER_INFO_DATE_FORMAT, time())); $this->addRow(_('Users (online)') . NAME_DELIMITER . $status['users_count'] . '(' . $status['users_online'] . ')'); $this->addRow(new CCol(array(_('Logged in as') . SPACE, new CLink(CWebUser::$data['alias'], 'profile.php')))); $this->addRow(new CCol(array($serverLink, SPACE . _('is') . SPACE, $server)), 'status'); $this->addRow(new CCol(array(_('Hosts (m/n/t)') . NAME_DELIMITER . $status['hosts_count'] . '(', new CSpan($status['hosts_count_monitored'], 'off'), '/', new CSpan($status['hosts_count_not_monitored'], 'on'), '/', new CSpan($status['hosts_count_template'], 'unknown'), ')'))); $this->addRow(new CCol(array(_('Items (m/d/n)') . NAME_DELIMITER . $status['items_count'] . '(', new CSpan($status['items_count_monitored'], 'off'), '/', new CSpan($status['items_count_disabled'], 'on'), '/', new CSpan($status['items_count_not_supported'], 'unknown'), ')'))); $this->addRow(new CCol(array(_('Triggers (e/d)[p/o]') . NAME_DELIMITER . $status['triggers_count'] . '(' . $status['triggers_count_enabled'] . '/' . $status['triggers_count_disabled'] . ')[', new CSpan($status['triggers_count_on'], 'on'), '/', new CSpan($status['triggers_count_off'], 'off'), ']'))); return parent::bodyToString(); }
public function bodyToString() { $this->cleanItems(); $config = select_config(); // array of triggers (not classified, information, warning, average, high, disaster) in problem state $triggersProblemState = []; // number of triggers in OK state $triggersOkState = 0; $options = ['output' => ['triggerid', 'priority', 'value'], 'monitored' => true, 'skipDependent' => true]; if ($this->groupid != 0) { $options['groupids'] = $this->groupid; } $triggers = API::Trigger()->get($options); foreach ($triggers as $trigger) { switch ($trigger['value']) { case TRIGGER_VALUE_TRUE: if (!array_key_exists($trigger['priority'], $triggersProblemState)) { $triggersProblemState[$trigger['priority']] = 0; } $triggersProblemState[$trigger['priority']]++; break; case TRIGGER_VALUE_FALSE: $triggersOkState++; } } $severityCells = [getSeverityCell(null, $config, $triggersOkState . SPACE . _('Ok'), true)]; for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { $severityCount = isset($triggersProblemState[$severity]) ? $triggersProblemState[$severity] : 0; $severityCells[] = getSeverityCell($severity, $config, $severityCount . SPACE . getSeverityName($severity, $config), !$severityCount); } if ($this->style == STYLE_HORIZONTAL) { $this->addRow($severityCells); } else { foreach ($severityCells as $severityCell) { $this->addRow($severityCell); } } return parent::bodyToString(); }
public function bodyToString() { global $USER_DETAILS; $this->cleanItems(); $total = 0; $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true)); $cond_from = ''; if (remove_nodes_from_id($this->groupid) > 0) { $cond_from = ', hosts_groups hg '; $cond_where = 'AND hg.hostid=h.hostid AND hg.groupid=' . $this->groupid; } else { $cond_where = ' AND ' . DBin_node('h.hostid', $this->nodeid); } $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $avail = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $notav = $host_cnt['cnt']; $total += $host_cnt['cnt']; $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where); $host_cnt = DBfetch($db_host_cnt); $uncn = $host_cnt['cnt']; $total += $host_cnt['cnt']; $node = get_node_by_nodeid($this->nodeid); $header_str = S_HOSTS_INFO . SPACE; $header_str .= S_FOR_GROUP_SMALL . SPACE . '"'; if ($node > 0) { $header_str .= '(' . $node['name'] . ')' . SPACE; } if (remove_nodes_from_id($this->groupid) > 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= $group['name'] . '"'; } else { $header_str .= S_ALL_S . '"'; } $header = new CCol($header_str, "header"); if ($this->style == STYLE_HORISONTAL) { $header->SetColspan(4); } $this->addRow($header); $avail = new CCol($avail . ' ' . S_AVAILABLE, 'avail'); $notav = new CCol($notav . ' ' . S_NOT_AVAILABLE, 'notav'); $uncn = new CCol($uncn . ' ' . S_UNKNOWN, 'uncn'); $total = new CCol($total . ' ' . S_TOTAL, 'total'); if ($this->style == STYLE_HORISONTAL) { $this->addRow(array($avail, $notav, $uncn, $total)); } else { $this->addRow($avail); $this->addRow($notav); $this->addRow($uncn); $this->addRow($total); } return parent::bodyToString(); }
public function bodyToString() { $this->cleanItems(); $okCount = 0; $notClassifiedCount = 0; $informationCount = 0; $warningCount = 0; $averageCount = 0; $highCount = 0; $disasterCount = 0; $options = array('output' => array('triggerid', 'priority', 'value'), 'monitored' => true, 'skipDependent' => true); if ($this->hostid > 0) { $options['hostids'] = $this->hostid; } elseif ($this->groupid > 0) { $options['groupids'] = $this->groupid; } $triggers = API::Trigger()->get($options); foreach ($triggers as $trigger) { if ($trigger['value'] == TRIGGER_VALUE_TRUE) { switch ($trigger['priority']) { case TRIGGER_SEVERITY_NOT_CLASSIFIED: $notClassifiedCount++; break; case TRIGGER_SEVERITY_INFORMATION: $informationCount++; break; case TRIGGER_SEVERITY_WARNING: $warningCount++; break; case TRIGGER_SEVERITY_AVERAGE: $averageCount++; break; case TRIGGER_SEVERITY_HIGH: $highCount++; break; case TRIGGER_SEVERITY_DISASTER: $disasterCount++; break; } } elseif ($trigger['value'] == TRIGGER_VALUE_FALSE) { $okCount++; } } if ($this->show_header) { $header_str = _('Triggers info') . SPACE; if ($this->groupid != 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= _('Group') . SPACE . '"' . $group['name'] . '"'; } else { $header_str .= _('All groups'); } $header = new CCol($header_str, 'header'); if ($this->style == STYLE_HORIZONTAL) { $header->setColspan(8); } $this->addRow($header); } $okCount = getSeverityCell(null, $okCount . SPACE . _('Ok'), true); $notClassifiedCount = getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $notClassifiedCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), !$notClassifiedCount); $informationCount = getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $informationCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), !$informationCount); $warningCount = getSeverityCell(TRIGGER_SEVERITY_WARNING, $warningCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_WARNING), !$warningCount); $averageCount = getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $averageCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), !$averageCount); $highCount = getSeverityCell(TRIGGER_SEVERITY_HIGH, $highCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_HIGH), !$highCount); $disasterCount = getSeverityCell(TRIGGER_SEVERITY_DISASTER, $disasterCount . SPACE . getSeverityCaption(TRIGGER_SEVERITY_DISASTER), !$disasterCount); if (STYLE_HORIZONTAL == $this->style) { $this->addRow(array($okCount, $notClassifiedCount, $informationCount, $warningCount, $averageCount, $highCount, $disasterCount)); } else { $this->addRow($okCount); $this->addRow($notClassifiedCount); $this->addRow($informationCount); $this->addRow($warningCount); $this->addRow($averageCount); $this->addRow($highCount); $this->addRow($disasterCount); } return parent::bodyToString(); }
public function bodyToString() { $this->cleanItems(); $ok = $uncl = $info = $warn = $avg = $high = $dis = 0; $options = array('monitored' => true, 'skipDependent' => true, 'output' => API_OUTPUT_SHORTEN); if ($this->hostid > 0) { $options['hostids'] = $this->hostid; } elseif ($this->groupid > 0) { $options['groupids'] = $this->groupid; } $triggers = API::Trigger()->get($options); $triggers = zbx_objectValues($triggers, 'triggerid'); $db_priority = DBselect('SELECT t.priority,t.value,count(DISTINCT t.triggerid) AS cnt' . ' FROM triggers t' . ' WHERE ' . dbConditionInt('t.triggerid', $triggers) . ' GROUP BY t.priority,t.value'); while ($row = DBfetch($db_priority)) { switch ($row['value']) { case TRIGGER_VALUE_TRUE: switch ($row['priority']) { case TRIGGER_SEVERITY_NOT_CLASSIFIED: $uncl += $row['cnt']; break; case TRIGGER_SEVERITY_INFORMATION: $info += $row['cnt']; break; case TRIGGER_SEVERITY_WARNING: $warn += $row['cnt']; break; case TRIGGER_SEVERITY_AVERAGE: $avg += $row['cnt']; break; case TRIGGER_SEVERITY_HIGH: $high += $row['cnt']; break; case TRIGGER_SEVERITY_DISASTER: $dis += $row['cnt']; break; } break; case TRIGGER_VALUE_FALSE: $ok += $row['cnt']; break; } } if ($this->show_header) { $header_str = _('Triggers info') . SPACE; if (!is_null($this->nodeid)) { $node = get_node_by_nodeid($this->nodeid); if ($node > 0) { $header_str .= '(' . $node['name'] . ')' . SPACE; } } if (remove_nodes_from_id($this->groupid) > 0) { $group = get_hostgroup_by_groupid($this->groupid); $header_str .= _('Group') . SPACE . '"' . $group['name'] . '"'; } else { $header_str .= _('All groups'); } $header = new CCol($header_str, 'header'); if ($this->style == STYLE_HORISONTAL) { $header->setColspan(8); } $this->addRow($header); } $trok = getSeverityCell(null, $ok . SPACE . _('Ok'), true); $uncl = getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $uncl . SPACE . getSeverityCaption(TRIGGER_SEVERITY_NOT_CLASSIFIED), !$uncl); $info = getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $info . SPACE . getSeverityCaption(TRIGGER_SEVERITY_INFORMATION), !$info); $warn = getSeverityCell(TRIGGER_SEVERITY_WARNING, $warn . SPACE . getSeverityCaption(TRIGGER_SEVERITY_WARNING), !$warn); $avg = getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $avg . SPACE . getSeverityCaption(TRIGGER_SEVERITY_AVERAGE), !$avg); $high = getSeverityCell(TRIGGER_SEVERITY_HIGH, $high . SPACE . getSeverityCaption(TRIGGER_SEVERITY_HIGH), !$high); $dis = getSeverityCell(TRIGGER_SEVERITY_DISASTER, $dis . SPACE . getSeverityCaption(TRIGGER_SEVERITY_DISASTER), !$dis); if (STYLE_HORISONTAL == $this->style) { $this->addRow(array($trok, $uncl, $info, $warn, $avg, $high, $dis)); } else { $this->addRow($trok); $this->addRow($uncl); $this->addRow($info); $this->addRow($warn); $this->addRow($avg); $this->addRow($high); $this->addRow($dis); } return parent::bodyToString(); }