Exemplo n.º 1
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $output = [];
     $items = API::Item()->get(['output' => ['itemid', 'hostid', 'name', 'key_', 'value_type', 'valuemapid'], 'selectHosts' => ['name'], 'itemids' => $this->itemids, 'webitems' => true, 'preservekeys' => true]);
     $items = CMacrosResolverHelper::resolveItemNames($items);
     $stime = zbxDateToTime($this->timeline['stime']);
     $firstItem = reset($items);
     $iv_string = [ITEM_VALUE_TYPE_LOG => 1, ITEM_VALUE_TYPE_TEXT => 1];
     $iv_numeric = [ITEM_VALUE_TYPE_FLOAT => 1, ITEM_VALUE_TYPE_UINT64 => 1];
     if ($this->action == HISTORY_VALUES || $this->action == HISTORY_LATEST) {
         $options = ['history' => $firstItem['value_type'], 'itemids' => $this->itemids, 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN];
         if ($this->action == HISTORY_LATEST) {
             $options['limit'] = 500;
         } elseif ($this->action == HISTORY_VALUES) {
             $config = select_config();
             // interval start value is non-inclusive, hence the + 1 second
             $options['time_from'] = $stime + 1;
             $options['time_till'] = $stime + $this->timeline['period'];
             $options['limit'] = $config['search_limit'];
         }
         // text log
         if (isset($iv_string[$firstItem['value_type']])) {
             $isManyItems = count($items) > 1;
             $useLogItem = $firstItem['value_type'] == ITEM_VALUE_TYPE_LOG;
             $useEventLogItem = strpos($firstItem['key_'], 'eventlog[') === 0;
             if (empty($this->plaintext)) {
                 $historyTable = (new CTableInfo())->setHeader([(new CColHeader(_('Timestamp')))->addClass(ZBX_STYLE_CELL_WIDTH), $isManyItems ? _('Item') : null, $useLogItem ? (new CColHeader(_('Local time')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Source')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Severity')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Event ID')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, _('Value')]);
             }
             if ($this->filter !== '' && in_array($this->filterTask, [FILTER_TASK_SHOW, FILTER_TASK_HIDE])) {
                 $options['search'] = ['value' => $this->filter];
                 if ($this->filterTask == FILTER_TASK_HIDE) {
                     $options['excludeSearch'] = 1;
                 }
             }
             $options['sortfield'] = 'id';
             $historyData = API::History()->get($options);
             foreach ($historyData as $data) {
                 $data['value'] = rtrim($data['value'], " \t\r\n");
                 if (empty($this->plaintext)) {
                     $item = $items[$data['itemid']];
                     $host = reset($item['hosts']);
                     $color = null;
                     if ($this->filter !== '') {
                         $haystack = mb_strtolower($data['value']);
                         $needle = mb_strtolower($this->filter);
                         $pos = mb_strpos($haystack, $needle);
                         if ($pos !== false && $this->filterTask == FILTER_TASK_MARK) {
                             $color = $this->markColor;
                         } elseif ($pos === false && $this->filterTask == FILTER_TASK_INVERT_MARK) {
                             $color = $this->markColor;
                         }
                         switch ($color) {
                             case MARK_COLOR_RED:
                                 $color = ZBX_STYLE_RED;
                                 break;
                             case MARK_COLOR_GREEN:
                                 $color = ZBX_STYLE_GREEN;
                                 break;
                             case MARK_COLOR_BLUE:
                                 $color = ZBX_STYLE_BLUE;
                                 break;
                         }
                     }
                     $row = [];
                     $row[] = (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock'])))->addClass(ZBX_STYLE_NOWRAP)->addClass($color);
                     if ($isManyItems) {
                         $row[] = (new CCol($host['name'] . NAME_DELIMITER . $item['name_expanded']))->addClass($color);
                     }
                     if ($useLogItem) {
                         $row[] = $data['timestamp'] != 0 ? (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['timestamp'])))->addClass(ZBX_STYLE_NOWRAP)->addClass($color) : '';
                         // if this is a eventLog item, showing additional info
                         if ($useEventLogItem) {
                             $row[] = (new CCol($data['source']))->addClass(ZBX_STYLE_NOWRAP)->addClass($color);
                             $row[] = $data['severity'] != 0 ? (new CCol(get_item_logtype_description($data['severity'])))->addClass(ZBX_STYLE_NOWRAP)->addClass(get_item_logtype_style($data['severity'])) : '';
                             $row[] = $data['logeventid'] != 0 ? (new CCol($data['logeventid']))->addClass(ZBX_STYLE_NOWRAP)->addClass($color) : '';
                         }
                     }
                     $row[] = (new CCol(new CPre(zbx_nl2br($data['value']))))->addClass($color);
                     $historyTable->addRow($row);
                 } else {
                     $output[] = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock']) . ' ' . $data['clock'] . ' ' . htmlspecialchars($data['value']);
                 }
             }
             if (empty($this->plaintext)) {
                 $output[] = $historyTable;
             }
         } else {
             if (empty($this->plaintext)) {
                 $historyTable = (new CTableInfo())->setHeader([(new CColHeader(_('Timestamp')))->addClass(ZBX_STYLE_CELL_WIDTH), _('Value')]);
             }
             $options['sortfield'] = ['itemid', 'clock'];
             $historyData = API::History()->get($options);
             foreach ($historyData as $data) {
                 $item = $items[$data['itemid']];
                 $value = rtrim($data['value'], " \t\r\n");
                 // format the value as float
                 if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT) {
                     sscanf($data['value'], '%f', $value);
                 }
                 // html table
                 if (empty($this->plaintext)) {
                     if ($item['valuemapid']) {
                         $value = applyValueMap($value, $item['valuemapid']);
                     }
                     $historyTable->addRow([(new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock'])))->addClass(ZBX_STYLE_NOWRAP), new CPre(zbx_nl2br($value))]);
                 } else {
                     $output[] = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock']) . ' ' . $data['clock'] . ' ' . htmlspecialchars($value);
                 }
             }
             if (empty($this->plaintext)) {
                 $output[] = $historyTable;
             }
         }
     }
     // time control
     if (!$this->plaintext && str_in_array($this->action, [HISTORY_VALUES, HISTORY_GRAPH, HISTORY_BATCH_GRAPH])) {
         $graphDims = getGraphDims();
         $this->timeline['starttime'] = date(TIMESTAMP_FORMAT, get_min_itemclock_by_itemid($firstItem['itemid']));
         $this->dataId = 'historyGraph';
         $timeControlData = ['periodFixed' => CProfile::get('web.history.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD];
         if (($this->action == HISTORY_GRAPH || $this->action == HISTORY_BATCH_GRAPH) && !isset($iv_string[$firstItem['value_type']])) {
             $containerId = 'graph_cont1';
             $output[] = (new CDiv())->addClass('center')->setId($containerId);
             $timeControlData['id'] = $this->getDataId();
             $timeControlData['containerid'] = $containerId;
             $timeControlData['src'] = $this->getGraphUrl($this->itemids);
             $timeControlData['objDims'] = $graphDims;
             $timeControlData['loadSBox'] = 1;
             $timeControlData['loadImage'] = 1;
             $timeControlData['dynamic'] = 1;
         } else {
             $timeControlData['id'] = $this->getDataId();
             $timeControlData['mainObject'] = 1;
         }
         if ($this->mode == SCREEN_MODE_JS) {
             $timeControlData['dynamic'] = 0;
             return 'timeControl.addObject("' . $this->getDataId() . '", ' . CJs::encodeJson($this->timeline) . ', ' . CJs::encodeJson($timeControlData) . ');';
         } else {
             zbx_add_post_js('timeControl.addObject("' . $this->getDataId() . '", ' . CJs::encodeJson($this->timeline) . ', ' . CJs::encodeJson($timeControlData) . ');');
         }
     }
     if (!empty($this->plaintext)) {
         return $output;
     } else {
         if ($this->mode != SCREEN_MODE_JS) {
             $flickerfreeData = ['itemids' => $this->itemids, 'action' => $this->action == HISTORY_BATCH_GRAPH ? HISTORY_GRAPH : $this->action, 'filter' => $this->filter, 'filterTask' => $this->filterTask, 'markColor' => $this->markColor];
             return $this->getOutput($output, true, $flickerfreeData);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $output = array();
     $stime = zbxDateToTime($this->timeline['stime']);
     $iv_string = array(ITEM_VALUE_TYPE_LOG => 1, ITEM_VALUE_TYPE_TEXT => 1);
     $iv_numeric = array(ITEM_VALUE_TYPE_FLOAT => 1, ITEM_VALUE_TYPE_UINT64 => 1);
     if ($this->action == 'showvalues' || $this->action == 'showlatest') {
         $options = array('history' => $this->item['value_type'], 'itemids' => array_keys($this->items), 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN);
         if ($this->action == 'showlatest') {
             $options['limit'] = 500;
         } elseif ($this->action == 'showvalues') {
             $config = select_config();
             $options['time_from'] = $stime - 10;
             // some seconds to allow script to execute
             $options['time_till'] = $stime + $this->timeline['period'];
             $options['limit'] = $config['search_limit'];
         }
         // text log
         if (isset($iv_string[$this->item['value_type']])) {
             $isManyItems = count($this->items) > 1;
             $useLogItem = $this->item['value_type'] == ITEM_VALUE_TYPE_LOG;
             $useEventLogItem = strpos($this->item['key_'], 'eventlog[') === 0;
             if (empty($this->plaintext)) {
                 $historyTable = new CTableInfo(_('No values found.'));
                 $historyTable->setHeader(array(_('Timestamp'), $isManyItems ? _('Item') : null, $useLogItem ? _('Local time') : null, $useEventLogItem && $useLogItem ? _('Source') : null, $useEventLogItem && $useLogItem ? _('Severity') : null, $useEventLogItem && $useLogItem ? _('Event ID') : null, _('Value')), 'header');
             }
             if (!zbx_empty($this->filter) && in_array($this->filterTask, array(FILTER_TASK_SHOW, FILTER_TASK_HIDE))) {
                 $options['search'] = array('value' => $this->filter);
                 if ($this->filterTask == FILTER_TASK_HIDE) {
                     $options['excludeSearch'] = 1;
                 }
             }
             $options['sortfield'] = 'id';
             $historyData = API::History()->get($options);
             foreach ($historyData as $data) {
                 $data['value'] = encode_log(trim($data['value'], "\r\n"));
                 if (empty($this->plaintext)) {
                     $item = $this->items[$data['itemid']];
                     $host = reset($item['hosts']);
                     $color = null;
                     if (isset($this->filter) && !zbx_empty($this->filter)) {
                         $contain = zbx_stristr($data['value'], $this->filter);
                         if ($contain && $this->filterTask == FILTER_TASK_MARK) {
                             $color = $this->markColor;
                         }
                         if (!$contain && $this->filterTask == FILTER_TASK_INVERT_MARK) {
                             $color = $this->markColor;
                         }
                         switch ($color) {
                             case MARK_COLOR_RED:
                                 $color = 'red';
                                 break;
                             case MARK_COLOR_GREEN:
                                 $color = 'green';
                                 break;
                             case MARK_COLOR_BLUE:
                                 $color = 'blue';
                                 break;
                         }
                     }
                     $row = array(nbsp(zbx_date2str(_('Y.M.d H:i:s'), $data['clock'])));
                     if ($isManyItems) {
                         $row[] = $host['name'] . NAME_DELIMITER . $item['name_expanded'];
                     }
                     if ($useLogItem) {
                         $row[] = $data['timestamp'] == 0 ? '-' : zbx_date2str(HISTORY_LOG_LOCALTIME_DATE_FORMAT, $data['timestamp']);
                         // if this is a eventLog item, showing additional info
                         if ($useEventLogItem) {
                             $row[] = zbx_empty($data['source']) ? '-' : $data['source'];
                             $row[] = $data['severity'] == 0 ? '-' : new CCol(get_item_logtype_description($data['severity']), get_item_logtype_style($data['severity']));
                             $row[] = $data['logeventid'] == 0 ? '-' : $data['logeventid'];
                         }
                     }
                     $row[] = new CCol($data['value'], 'pre');
                     $newRow = new CRow($row);
                     if (!is_null($color)) {
                         $newRow->setAttribute('class', $color);
                     }
                     $historyTable->addRow($newRow);
                 } else {
                     $output[] = zbx_date2str(HISTORY_LOG_ITEM_PLAINTEXT, $data['clock']);
                     $output[] = "\t" . $data['clock'] . "\t" . htmlspecialchars($data['value']) . "\n";
                 }
             }
             if (empty($this->plaintext)) {
                 $output[] = $historyTable;
             }
         } else {
             if (empty($this->plaintext)) {
                 $historyTable = new CTableInfo(_('No values found.'));
                 $historyTable->setHeader(array(_('Timestamp'), _('Value')));
             }
             $options['sortfield'] = array('itemid', 'clock');
             $historyData = API::History()->get($options);
             foreach ($historyData as $data) {
                 $item = $this->items[$data['itemid']];
                 $value = $data['value'];
                 // format the value as float
                 if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT) {
                     sscanf($data['value'], '%f', $value);
                 }
                 // html table
                 if (empty($this->plaintext)) {
                     if ($item['valuemapid']) {
                         $value = applyValueMap($value, $item['valuemapid']);
                     }
                     $historyTable->addRow(array(zbx_date2str(HISTORY_ITEM_DATE_FORMAT, $data['clock']), zbx_nl2br($value)));
                 } else {
                     $output[] = zbx_date2str(HISTORY_PLAINTEXT_DATE_FORMAT, $data['clock']);
                     $output[] = "\t" . $data['clock'] . "\t" . htmlspecialchars($value) . "\n";
                 }
             }
             if (empty($this->plaintext)) {
                 $output[] = $historyTable;
             }
         }
     }
     if ($this->action == 'showgraph' && !isset($iv_string[$this->item['value_type']])) {
         $this->dataId = 'historyGraph';
         $containerId = 'graph_cont1';
         $src = 'chart.php?itemid=' . $this->item['itemid'] . '&period=' . $this->timeline['period'] . '&stime=' . $this->timeline['stime'] . $this->getProfileUrlParams();
         $output[] = new CDiv(null, 'center', $containerId);
     }
     // time control
     if (!$this->plaintext && str_in_array($this->action, array('showvalues', 'showgraph'))) {
         $graphDims = getGraphDims();
         $this->timeline['starttime'] = date(TIMESTAMP_FORMAT, get_min_itemclock_by_itemid($this->item['itemid']));
         $timeControlData = array('periodFixed' => CProfile::get('web.history.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD);
         if (!empty($this->dataId)) {
             $timeControlData['id'] = $this->getDataId();
             $timeControlData['containerid'] = $containerId;
             $timeControlData['src'] = $src;
             $timeControlData['objDims'] = $graphDims;
             $timeControlData['loadSBox'] = 1;
             $timeControlData['loadImage'] = 1;
             $timeControlData['dynamic'] = 1;
         } else {
             $this->dataId = 'historyGraph';
             $timeControlData['id'] = $this->getDataId();
             $timeControlData['mainObject'] = 1;
         }
         if ($this->mode == SCREEN_MODE_JS) {
             $timeControlData['dynamic'] = 0;
             return 'timeControl.addObject("' . $this->getDataId() . '", ' . zbx_jsvalue($this->timeline) . ', ' . zbx_jsvalue($timeControlData) . ');';
         } else {
             zbx_add_post_js('timeControl.addObject("' . $this->getDataId() . '", ' . zbx_jsvalue($this->timeline) . ', ' . zbx_jsvalue($timeControlData) . ');');
         }
     }
     if (!empty($this->plaintext)) {
         return $output;
     } else {
         if ($this->mode != SCREEN_MODE_JS) {
             $flickerfreeData = array('itemids' => $this->itemids, 'action' => $this->action, 'filter' => $this->filter, 'filterTask' => $this->filterTask, 'markColor' => $this->markColor);
             return $this->getOutput($output, true, $flickerfreeData);
         }
     }
 }
Exemplo n.º 3
0
             break;
         case MARK_COLOR_BLUE:
             $color_style = 'blue';
             break;
     }
 }
 $row = array(nbsp(zbx_date2str(S_HISTORY_LOG_ITEM_DATE_FORMAT, $data['clock'])));
 if ($fewItems) {
     $row[] = $host['host'] . ':' . item_description($item);
 }
 if ($logItem) {
     $row[] = $data['timestamp'] == 0 ? '-' : zbx_date2str(S_HISTORY_LOG_LOCALTIME_DATE_FORMAT, $data['timestamp']);
     // if this is a eventLog item, showing additional info
     if ($eventLogItem) {
         $row[] = zbx_empty($data['source']) ? '-' : $data['source'];
         $row[] = $data['severity'] == 0 ? '-' : new CCol(get_item_logtype_description($data['severity']), get_item_logtype_style($data['severity']));
         $row[] = $data['logeventid'] == 0 ? '-' : $data['logeventid'];
     }
 }
 $data['value'] = encode_log(trim($data['value'], "\r\n"));
 $row[] = new CCol($data['value'], 'pre');
 $crow = new CRow($row);
 if (is_null($color_style)) {
     $min_color = 0x98;
     $max_color = 0xf8;
     $int_color = ($max_color - $min_color) / count($_REQUEST['itemid']);
     $int_color *= array_search($data['itemid'], $_REQUEST['itemid']);
     $int_color += $min_color;
     $crow->setAttribute('style', 'background-color: ' . sprintf("#%X%X%X", $int_color, $int_color, $int_color));
 } else {
     if (!is_null($color_style)) {