1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22require_once dirname(__FILE__).'/include/config.inc.php'; 23require_once dirname(__FILE__).'/include/items.inc.php'; 24require_once dirname(__FILE__).'/include/graphs.inc.php'; 25 26$page['file'] = 'history.php'; 27$page['title'] = _('History'); 28$page['scripts'] = ['class.calendar.js', 'gtlc.js', 'flickerfreescreen.js', 'multiselect.js', 'layout.mode.js']; 29$page['type'] = detect_page_type(PAGE_TYPE_HTML); 30 31CView::$has_web_layout_mode = true; 32$page['web_layout_mode'] = CView::getLayoutMode(); 33 34if (hasRequest('plaintext')) { 35 define('ZBX_PAGE_NO_MENU', true); 36} 37define('ZBX_PAGE_DO_JS_REFRESH', 1); 38 39require_once dirname(__FILE__).'/include/page_header.php'; 40 41// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION 42$fields = [ 43 'itemids' => [T_ZBX_INT, O_OPT, P_SYS, DB_ID, null], 44 'from' => [T_ZBX_RANGE_TIME, O_OPT, P_SYS, null, null], 45 'to' => [T_ZBX_RANGE_TIME, O_OPT, P_SYS, null, null], 46 'filter_task' => [T_ZBX_STR, O_OPT, null, IN(FILTER_TASK_SHOW.','.FILTER_TASK_HIDE.','.FILTER_TASK_MARK.','.FILTER_TASK_INVERT_MARK), null], 47 'filter' => [T_ZBX_STR, O_OPT, null, null, null], 48 'mark_color' => [T_ZBX_STR, O_OPT, null, IN(MARK_COLOR_RED.','.MARK_COLOR_GREEN.','.MARK_COLOR_BLUE), null], 49 'plaintext' => [T_ZBX_STR, O_OPT, null, null, null], 50 'action' => [T_ZBX_STR, O_OPT, P_SYS, IN('"'.HISTORY_GRAPH.'","'.HISTORY_VALUES.'","'.HISTORY_LATEST.'","'.HISTORY_BATCH_GRAPH.'"'), null], 51 'graphtype' => [T_ZBX_INT, O_OPT, null, IN([GRAPH_TYPE_NORMAL, GRAPH_TYPE_STACKED]), null], 52 // filter 53 'filter_rst' => [T_ZBX_STR, O_OPT, P_SYS, null, null] 54]; 55check_fields($fields); 56 57validateTimeSelectorPeriod(getRequest('from'), getRequest('to')); 58 59if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) { 60 require_once dirname(__FILE__).'/include/page_footer.php'; 61 exit; 62} 63 64/* 65 * Actions 66 */ 67$_REQUEST['action'] = getRequest('action', HISTORY_GRAPH); 68 69/* 70 * Display 71 */ 72$itemids = getRequest('filter_rst') ? [] : getRequest('itemids', []); 73$items = []; 74$value_type = ''; 75 76if ($itemids) { 77 $items = API::Item()->get([ 78 'output' => ['itemid', 'key_', 'name', 'value_type', 'hostid', 'valuemapid', 'history', 'trends'], 79 'selectHosts' => ['name'], 80 'itemids' => $itemids, 81 'preservekeys' => true, 82 'templated' => false, 83 'webitems' => true 84 ]); 85 86 foreach ($itemids as $itemid) { 87 if (!array_key_exists($itemid, $items)) { 88 access_deny(); 89 } 90 } 91 92 $items = CMacrosResolverHelper::resolveItemNames($items); 93 $item = reset($items); 94 $value_type = $item['value_type']; 95} 96 97$data = [ 98 'itemids' => $itemids, 99 'items' => $items, 100 'value_type' => $value_type, 101 'action' => getRequest('action'), 102 'from' => getRequest('from'), 103 'to' => getRequest('to'), 104 'plaintext' => hasRequest('plaintext'), 105 'graphtype' => getRequest('graphtype', GRAPH_TYPE_NORMAL), 106 'iv_string' => [ITEM_VALUE_TYPE_LOG => true, ITEM_VALUE_TYPE_TEXT => true], 107 'iv_numeric' => [ITEM_VALUE_TYPE_FLOAT => true, ITEM_VALUE_TYPE_UINT64 => true], 108 'profileIdx' => 'web.item.graph.filter', 109 'profileIdx2' => 0, 110 'filter_task' => getRequest('filter_rst') ? FILTER_TASK_SHOW : getRequest('filter_task', FILTER_TASK_SHOW), 111 'filter' => getRequest('filter_rst') ? '' : getRequest('filter', ''), 112 'active_tab' => CProfile::get('web.item.graph.filter.active', 1) 113]; 114 115if ($data['action'] != HISTORY_BATCH_GRAPH && $itemids) { 116 $data['profileIdx2'] = reset($itemids); 117} 118 119updateTimeSelectorPeriod([ 120 'profileIdx' => $data['profileIdx'], 121 'profileIdx2' => $data['profileIdx2'], 122 'from' => getRequest('from'), 123 'to' => getRequest('to') 124]); 125 126// render view 127$historyView = new CView('monitoring.history', $data); 128$historyView->render(); 129$historyView->show(); 130 131require_once dirname(__FILE__).'/include/page_footer.php'; 132