/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { // if screen is defined in template, then 'real_resourceid' is defined and should be used if (!empty($this->screenitem['real_resourceid'])) { $this->screenitem['resourceid'] = $this->screenitem['real_resourceid']; } if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && !empty($this->hostid)) { $newitemid = get_same_item_for_host($this->screenitem['resourceid'], $this->hostid); $this->screenitem['resourceid'] = !empty($newitemid) ? $newitemid : 0; } if ($this->screenitem['resourceid'] == 0) { $table = (new CTableInfo())->setHeader([_('Timestamp'), _('Item')]); return $this->getOutput($table); } $items = CMacrosResolverHelper::resolveItemNames([get_item_by_itemid($this->screenitem['resourceid'])]); $item = reset($items); switch ($item['value_type']) { case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_LOG: $orderField = 'id'; break; case ITEM_VALUE_TYPE_FLOAT: case ITEM_VALUE_TYPE_UINT64: default: $orderField = ['itemid', 'clock']; } $host = get_host_by_itemid($this->screenitem['resourceid']); $table = (new CTableInfo())->setHeader([_('Timestamp'), _('Value')]); $stime = zbxDateToTime($this->timeline['stime']); $histories = API::History()->get(['history' => $item['value_type'], 'itemids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN, 'sortfield' => $orderField, 'limit' => $this->screenitem['elements'], 'time_from' => $stime, 'time_till' => $stime + $this->timeline['period']]); foreach ($histories as $history) { switch ($item['value_type']) { case ITEM_VALUE_TYPE_FLOAT: sscanf($history['value'], '%f', $value); break; case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_STR: case ITEM_VALUE_TYPE_LOG: $value = $this->screenitem['style'] ? new CJsScript($history['value']) : $history['value']; break; default: $value = $history['value']; break; } if ($item['valuemapid'] > 0) { $value = applyValueMap($value, $item['valuemapid']); } if ($this->screenitem['style'] == 0) { $value = new CPre($value); } $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $history['clock']), $value]); } $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT); return $this->getOutput((new CUiWidget(uniqid(), [$table, $footer]))->setHeader($host['name'] . NAME_DELIMITER . $item['name_expanded'])); }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { // if screen is defined in template, then 'real_resourceid' is defined and should be used if (!empty($this->screenitem['real_resourceid'])) { $this->screenitem['resourceid'] = $this->screenitem['real_resourceid']; } if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && !empty($this->hostid)) { $newitemid = get_same_item_for_host($this->screenitem['resourceid'], $this->hostid); $this->screenitem['resourceid'] = !empty($newitemid) ? $newitemid : 0; } if ($this->screenitem['resourceid'] == 0) { $table = new CTableInfo(_('No values found.')); $table->setHeader(array(_('Timestamp'), _('Item'))); return $this->getOutput($table); } $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($this->screenitem['resourceid']))); $item = reset($items); switch ($item['value_type']) { case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_LOG: $orderField = 'id'; break; case ITEM_VALUE_TYPE_FLOAT: case ITEM_VALUE_TYPE_UINT64: default: $orderField = array('itemid', 'clock'); } $host = get_host_by_itemid($this->screenitem['resourceid']); $table = new CTableInfo(_('No values found.')); $table->setHeader(array(_('Timestamp'), $host['name'] . NAME_DELIMITER . $item['name_expanded'])); $stime = zbxDateToTime($this->timeline['stime']); $histories = API::History()->get(array('history' => $item['value_type'], 'itemids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN, 'sortfield' => $orderField, 'limit' => $this->screenitem['elements'], 'time_from' => $stime, 'time_till' => $stime + $this->timeline['period'])); foreach ($histories as $history) { switch ($item['value_type']) { case ITEM_VALUE_TYPE_FLOAT: sscanf($history['value'], '%f', $value); break; case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_STR: case ITEM_VALUE_TYPE_LOG: $value = $this->screenitem['style'] ? new CJsScript($history['value']) : $history['value']; break; default: $value = $history['value']; break; } if ($item['valuemapid'] > 0) { $value = applyValueMap($value, $item['valuemapid']); } $class = $this->screenitem['style'] ? null : 'pre'; $table->addRow(array(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $history['clock']), new CCol($value, $class))); } return $this->getOutput($table); }
function make_graph_submenu() { $graphids = array(); $fav_graphs = get_favorites('web.favorite.graphids'); foreach ($fav_graphs as $key => $favorite) { $source = $favorite['source']; $sourceid = $favorite['value']; if ('itemid' == $source) { if (!($item = get_item_by_itemid($sourceid))) { continue; } $item_added = true; $host = get_host_by_itemid($sourceid); $item["description"] = item_description($item); $graphids[] = array('name' => $host['host'] . ':' . $item['description'], 'favobj' => 'itemid', 'favid' => $sourceid, 'action' => 'remove'); } else { if (!($graph = get_graph_by_graphid($sourceid))) { continue; } $graph_added = true; $result = get_hosts_by_graphid($sourceid); $ghost = DBFetch($result); $graphids[] = array('name' => $ghost['host'] . ':' . $graph['name'], 'favobj' => 'graphid', 'favid' => $sourceid, 'action' => 'remove'); } } if (isset($graph_added)) { $graphids[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_GRAPHS, 'favobj' => 'graphid', 'favid' => 0, 'action' => 'remove'); } if (isset($item_added)) { $graphids[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_SIMPLE_GRAPHS, 'favobj' => 'itemid', 'favid' => 0, 'action' => 'remove'); } return $graphids; }
function construct_expression($itemid, $expressions) { $complite_expr = ''; $item = get_item_by_itemid($itemid); $host = get_host_by_itemid($itemid); $prefix = $host['host'] . ':' . $item['key_'] . '.'; if (empty($expressions)) { error(_('Expression cannot be empty')); return false; } $ZBX_PREG_EXPESSION_FUNC_FORMAT = '^([' . ZBX_PREG_PRINT . ']*)([&|]{1})[(]*(([a-zA-Z_.\\$]{6,7})(\\(([' . ZBX_PREG_PRINT . ']+?){0,1}\\)))([' . ZBX_PREG_PRINT . ']*)$'; $functions = array('regexp' => 1, 'iregexp' => 1); $expr_array = array(); $cexpor = 0; $startpos = -1; foreach ($expressions as $expression) { $expression['value'] = preg_replace('/\\s+(AND){1,2}\\s+/U', '&', $expression['value']); $expression['value'] = preg_replace('/\\s+(OR){1,2}\\s+/U', '|', $expression['value']); if ($expression['type'] == REGEXP_INCLUDE) { if (!empty($complite_expr)) { $complite_expr .= ' | '; } if ($cexpor == 0) { $startpos = zbx_strlen($complite_expr); } $cexpor++; $eq_global = '#0'; } else { if ($cexpor > 1 & $startpos >= 0) { $head = substr($complite_expr, 0, $startpos); $tail = substr($complite_expr, $startpos); $complite_expr = $head . '(' . $tail . ')'; } $cexpor = 0; $eq_global = '=0'; if (!empty($complite_expr)) { $complite_expr .= ' & '; } } $expr = '&' . $expression['value']; $expr = preg_replace('/\\s+(\\&|\\|){1,2}\\s+/U', '$1', $expr); $expr_array = array(); $sub_expr_count = 0; $sub_expr = ''; $multi = preg_match('/.+(&|\\|).+/', $expr); while (preg_match('/' . $ZBX_PREG_EXPESSION_FUNC_FORMAT . '/i', $expr, $arr)) { $arr[4] = zbx_strtolower($arr[4]); if (!isset($functions[$arr[4]])) { error(_('Incorrect function is used') . '. [' . $expression['value'] . ']'); return false; } $expr_array[$sub_expr_count]['eq'] = trim($arr[2]); $expr_array[$sub_expr_count]['regexp'] = zbx_strtolower($arr[4]) . $arr[5]; $sub_expr_count++; $expr = $arr[1]; } if (empty($expr_array)) { error(_('Incorrect trigger expression') . '. [' . $expression['value'] . ']'); return false; } $expr_array[$sub_expr_count - 1]['eq'] = ''; $sub_eq = ''; if ($multi > 0) { $sub_eq = $eq_global; } foreach ($expr_array as $id => $expr) { if ($multi > 0) { $sub_expr = $expr['eq'] . '({' . $prefix . $expr['regexp'] . '})' . $sub_eq . $sub_expr; } else { $sub_expr = $expr['eq'] . '{' . $prefix . $expr['regexp'] . '}' . $sub_eq . $sub_expr; } } if ($multi > 0) { $complite_expr .= '(' . $sub_expr . ')'; } else { $complite_expr .= '((' . $sub_expr . ')' . $eq_global . ')'; } } if ($cexpor > 1 & $startpos >= 0) { $head = substr($complite_expr, 0, $startpos); $tail = substr($complite_expr, $startpos); $complite_expr = $head . '(' . $tail . ')'; } return $complite_expr; }
function get_realhost_by_itemid($itemid) { $item = get_item_by_itemid($itemid); if ($item['templateid'] != 0) { return get_realhost_by_itemid($item['templateid']); // attention recursion! } return get_host_by_itemid($itemid); }
function bar_report_form2() { global $USER_DETAILS; $config = get_request('config', 1); $title = get_request('title', S_REPORT . ' 2'); $xlabel = get_request('xlabel', ''); $ylabel = get_request('ylabel', ''); $sorttype = get_request('sorttype', 0); $captions = get_request('captions', array()); $items = get_request('items', array()); $periods = get_request('periods', array()); $showlegend = get_request('showlegend', 0); $reportForm = new CFormTable(null, null, 'get'); //,'events.php?report_set=1','POST',null,'sform'); $reportForm->setAttribute('name', 'zbx_report'); $reportForm->setAttribute('id', 'zbx_report'); // $reportForm->setMethod('post'); if (isset($_REQUEST['report_show']) && !empty($items)) { $reportForm->addVar('report_show', 'show'); } $reportForm->addVar('config', $config); $reportForm->addVar('items', $items); // periods add later $reportForm->addRow(S_TITLE, new CTextBox('title', $title, 40)); $reportForm->addRow(S_X . SPACE . S_LABEL, new CTextBox('xlabel', $xlabel, 40)); $reportForm->addRow(S_Y . SPACE . S_LABEL, new CTextBox('ylabel', $ylabel, 40)); $reportForm->addRow(S_LEGEND, new CCheckBox('showlegend', $showlegend, null, 1)); if (count($periods) < 2) { $sortCmb = new CComboBox('sorttype', $sorttype); $sortCmb->addItem(0, S_NAME); $sortCmb->addItem(1, S_VALUE); $reportForm->addRow(S_SORT_BY, $sortCmb); } else { $reportForm->addVar('sortorder', 0); } //*/ // PERIODS if (count($periods)) { $periods_table = new CTableInfo(); foreach ($periods as $pid => $period) { $color = new CColorCell(null, $period['color']); $edit_link = 'popup_period.php?period_id=' . $pid . '&config=2' . '&dstfrm=' . $reportForm->getName() . '&caption=' . $period['caption'] . '&report_timesince=' . $period['report_timesince'] . '&report_timetill=' . $period['report_timetill'] . '&color=' . $period['color']; $caption = new CSpan($period['caption'], 'link'); $caption->addAction('onclick', "return PopUp('" . $edit_link . "',840,340,'period_form');"); $periods_table->addRow(array(new CCheckBox('group_pid[' . $pid . ']'), $caption, zbx_date2str(S_REPORTS_BAR_REPORT_DATE_FORMAT, $period['report_timesince']), zbx_date2str(S_REPORTS_BAR_REPORT_DATE_FORMAT, $period['report_timetill']), $color)); } $delete_button = new CButton('delete_period', S_DELETE_SELECTED); } else { $periods_table = $delete_button = null; } $reportForm->addVar('periods', $periods); $reportForm->addRow(S_PERIOD, array($periods_table, new CButton('add_period', S_ADD, "return PopUp('popup_period.php?config=2&dstfrm=" . $reportForm->getName() . "',840,340,'period_form');"), $delete_button)); unset($periods_table, $delete_button); //----------- // ITEMS if (count($items)) { $items_table = new CTableInfo(); foreach ($items as $gid => $gitem) { $host = get_host_by_itemid($gitem['itemid']); $item = get_item_by_itemid($gitem['itemid']); if ($host['status'] == HOST_STATUS_TEMPLATE) { $only_hostid = $host['hostid']; } else { $monitored_hosts = 1; } $caption = new CSpan($gitem['caption'], 'link'); $caption->onClick('return PopUp("popup_bitem.php?config=2&list_name=items&dstfrm=' . $reportForm->GetName() . url_param($gitem, false) . url_param($gid, false, 'gid') . '",550,400,"graph_item_form");'); $description = $host['host'] . ': ' . item_description($item); $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $caption, $description, graph_item_calc_fnc2str($gitem['calc_fnc'], 0))); } $delete_button = new CButton('delete_item', S_DELETE_SELECTED); } else { $items_table = $delete_button = null; } $reportForm->addRow(S_ITEMS, array($items_table, new CButton('add_item', S_ADD, "return PopUp('popup_bitem.php?config=2&dstfrm=" . $reportForm->getName() . "',550,400,'graph_item_form');"), $delete_button)); unset($items_table, $delete_button); //-------------- $reportForm->addItemToBottomRow(new CButton('report_show', S_SHOW)); $reset = new CButton('reset', S_RESET); $reset->setType('reset'); $reportForm->addItemToBottomRow($reset); return $reportForm; }
$period = SEC_PER_HOUR; break; case TIMEPERIOD_TYPE_DAILY: $period = SEC_PER_DAY; break; case TIMEPERIOD_TYPE_WEEKLY: $period = SEC_PER_WEEK; break; case TIMEPERIOD_TYPE_MONTHLY: $period = SEC_PER_MONTH; break; case TIMEPERIOD_TYPE_YEARLY: $period = SEC_PER_YEAR; break; } $hosts = get_host_by_itemid($itemids); $db_values = array(); foreach ($itemids as $itemid) { $count = 0; if (!isset($db_values[$count])) { $db_values[$count] = array(); } $graph_data['captions'][$itemid] = $hosts[$itemid]['host']; $start = 0; $end = $timesince; while ($end < $timetill) { switch ($scaletype) { case TIMEPERIOD_TYPE_HOURLY: case TIMEPERIOD_TYPE_DAILY: case TIMEPERIOD_TYPE_WEEKLY: $start = $end;
$graphForm->addVar('yaxismin', $this->data['yaxismin']); } $graphFormList->addRow(_('Y axis MIN value'), $yaxisMinData); $yaxisMaxData = array(); $yTypeComboBox = new CComboBox('ymax_type', $this->data['ymax_type']); $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_CALCULATED, _('Calculated')); $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_FIXED, _('Fixed')); $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, _('Item')); $yaxisMaxData[] = $yTypeComboBox; if ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_FIXED) { $yaxisMaxData[] = new CTextBox('yaxismax', $this->data['yaxismax'], 7); } elseif ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $graphForm->addVar('yaxismax', $this->data['yaxismax']); $ymax_name = ''; if (!empty($this->data['ymax_itemid'])) { $max_host = get_host_by_itemid($this->data['ymax_itemid']); $maxItems = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($this->data['ymax_itemid']))); $maxItem = reset($maxItems); $ymax_name = $max_host['name'] . NAME_DELIMITER . $maxItem['name_expanded']; } $yaxisMaxData[] = new CTextBox('ymax_name', $ymax_name, 36, true); $yaxisMaxData[] = new CButton('yaxis_max', _('Select'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=items' . '&srcfld1=itemid' . '&srcfld2=name' . '&numeric=1' . '&writeonly=1" + getOnlyHostParam(), 0, 0, "zbx_popup_item");', 'formlist'); // select prototype button if (!empty($this->data['parent_discoveryid'])) { $yaxisMaxData[] = new CButton('yaxis_max_prototype', _('Select prototype'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=item_prototypes' . '&srcfld1=itemid' . '&srcfld2=name' . '&numeric=1", 0, 0, "zbx_popup_item");', 'formlist'); } } else { $graphForm->addVar('yaxismax', $this->data['yaxismax']); } $graphFormList->addRow(_('Y axis MAX value'), $yaxisMaxData); } else {
function insert_graph_form() { $frmGraph = new CFormTable(S_GRAPH, null, 'post'); $frmGraph->SetName('frm_graph'); $frmGraph->SetHelp("web.graphs.graph.php"); $frmGraph->SetMethod('post'); $items = get_request('items', array()); if (isset($_REQUEST['graphid'])) { $frmGraph->addVar('graphid', $_REQUEST['graphid']); $result = DBselect('SELECT * FROM graphs WHERE graphid=' . $_REQUEST['graphid']); $row = DBfetch($result); $frmGraph->SetTitle(S_GRAPH . ' "' . $row['name'] . '"'); } if (isset($_REQUEST['graphid']) && !isset($_REQUEST['form_refresh'])) { $name = $row['name']; $width = $row['width']; $height = $row['height']; $ymin_type = $row["ymin_type"]; $ymax_type = $row["ymax_type"]; $yaxismin = $row['yaxismin']; $yaxismax = $row['yaxismax']; $ymin_itemid = $row["ymin_itemid"]; $ymax_itemid = $row["ymax_itemid"]; $showworkperiod = $row['show_work_period']; $showtriggers = $row['show_triggers']; $graphtype = $row['graphtype']; $legend = $row['show_legend']; $graph3d = $row['show_3d']; $percent_left = $row['percent_left']; $percent_right = $row['percent_right']; $db_items = DBselect('SELECT * FROM graphs_items WHERE graphid=' . $_REQUEST['graphid']); while ($item = DBfetch($db_items)) { array_push($items, array('itemid' => $item['itemid'], 'drawtype' => $item['drawtype'], 'sortorder' => $item['sortorder'], 'color' => $item['color'], 'yaxisside' => $item['yaxisside'], 'calc_fnc' => $item['calc_fnc'], 'type' => $item['type'], 'periods_cnt' => $item['periods_cnt'])); } } else { $name = get_request('name', ''); $graphtype = get_request('graphtype', GRAPH_TYPE_NORMAL); if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) { $width = get_request('width', 400); $height = get_request('height', 300); } else { $width = get_request('width', 900); $height = get_request('height', 200); } $ymin_type = get_request("ymin_type", GRAPH_YAXIS_TYPE_CALCULATED); $ymax_type = get_request("ymax_type", GRAPH_YAXIS_TYPE_CALCULATED); $yaxismin = get_request("yaxismin", 0.0); $yaxismax = get_request("yaxismax", 100.0); $ymin_itemid = get_request("ymin_itemid", 0); $ymax_itemid = get_request("ymax_itemid", 0); $showworkperiod = get_request('showworkperiod', 0); $showtriggers = get_request('showtriggers', 0); $legend = get_request('legend', 0); $graph3d = get_request('graph3d', 0); $visible = get_request('visible'); $percent_left = 0; $percent_right = 0; if (isset($visible['percent_left'])) { $percent_left = get_request('percent_left', 0); } if (isset($visible['percent_right'])) { $percent_right = get_request('percent_right', 0); } } /* reinit $_REQUEST */ $_REQUEST['items'] = $items; $_REQUEST['name'] = $name; $_REQUEST['width'] = $width; $_REQUEST['height'] = $height; $_REQUEST['ymin_type'] = $ymin_type; $_REQUEST['ymax_type'] = $ymax_type; $_REQUEST['yaxismin'] = $yaxismin; $_REQUEST['yaxismax'] = $yaxismax; $_REQUEST['ymin_itemid'] = $ymin_itemid; $_REQUEST['ymax_itemid'] = $ymax_itemid; $_REQUEST['showworkperiod'] = $showworkperiod; $_REQUEST['showtriggers'] = $showtriggers; $_REQUEST['graphtype'] = $graphtype; $_REQUEST['legend'] = $legend; $_REQUEST['graph3d'] = $graph3d; $_REQUEST['percent_left'] = $percent_left; $_REQUEST['percent_right'] = $percent_right; /********************/ if ($graphtype != GRAPH_TYPE_NORMAL) { foreach ($items as $gid => $gitem) { if ($gitem['type'] != GRAPH_ITEM_AGGREGATED) { continue; } unset($items[$gid]); } } asort_by_key($items, 'sortorder'); $group_gid = get_request('group_gid', array()); $frmGraph->addVar('ymin_itemid', $ymin_itemid); $frmGraph->addVar('ymax_itemid', $ymax_itemid); $frmGraph->addRow(S_NAME, new CTextBox('name', $name, 32)); $g_width = new CNumericBox('width', $width, 5); $g_width->addoption('onblur', 'javascript: submit();'); $frmGraph->addRow(S_WIDTH, $g_width); $g_height = new CNumericBox('height', $height, 5); $g_height->addoption('onblur', 'javascript: submit();'); $frmGraph->addRow(S_HEIGHT, $g_height); $cmbGType = new CComboBox('graphtype', $graphtype, 'graphs.submit(this)'); $cmbGType->addItem(GRAPH_TYPE_NORMAL, S_NORMAL); $cmbGType->addItem(GRAPH_TYPE_STACKED, S_STACKED); $cmbGType->addItem(GRAPH_TYPE_PIE, S_PIE); $cmbGType->addItem(GRAPH_TYPE_EXPLODED, S_EXPLODED); zbx_add_post_js('graphs.graphtype = ' . $graphtype . ";\n"); $frmGraph->addRow(S_GRAPH_TYPE, $cmbGType); if ($graphtype == GRAPH_TYPE_NORMAL || $graphtype == GRAPH_TYPE_STACKED) { $frmGraph->addRow(S_SHOW_WORKING_TIME, new CCheckBox('showworkperiod', $showworkperiod, null, 1)); $frmGraph->addRow(S_SHOW_TRIGGERS, new CCheckBox('showtriggers', $showtriggers, null, 1)); if ($graphtype == GRAPH_TYPE_NORMAL) { $percent_left = sprintf("%2.2f", $percent_left); $percent_right = sprintf("%2.2f", $percent_right); $pr_left_input = new CTextBox('percent_left', $percent_left, '5'); $pr_left_chkbx = new CCheckBox('visible[percent_left]', 1, "javascript: ShowHide('percent_left');", 1); if ($percent_left == 0) { $pr_left_input->addOption('style', 'display: none;'); $pr_left_chkbx->SetChecked(0); } $pr_right_input = new CTextBox('percent_right', $percent_right, '5'); $pr_right_chkbx = new CCheckBox('visible[percent_right]', 1, "javascript: ShowHide('percent_right');", 1); if ($percent_right == 0) { $pr_right_input->addOption('style', 'display: none;'); $pr_right_chkbx->SetChecked(0); } $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_LEFT . ')', array($pr_left_chkbx, $pr_left_input)); $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_RIGHT . ')', array($pr_right_chkbx, $pr_right_input)); } $yaxis_min = array(); $cmbYType = new CComboBox('ymin_type', $ymin_type, 'javascript: submit();'); $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM); $yaxis_min[] = $cmbYType; if ($ymin_type == GRAPH_YAXIS_TYPE_FIXED) { $yaxis_min[] = new CTextBox("yaxismin", $yaxismin, 9); } else { if ($ymin_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $frmGraph->addVar('yaxismin', $yaxismin); $ymin_name = ''; if ($ymin_itemid > 0) { $min_host = get_host_by_itemid($ymin_itemid); $min_item = get_item_by_itemid($ymin_itemid); $ymin_name = $min_host['host'] . ':' . item_description($min_item); } $yaxis_min[] = new CTextBox("ymin_name", $ymin_name, 80, 'yes'); $yaxis_min[] = new CButton('yaxis_min', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . "&dstfld1=ymin_itemid" . "&dstfld2=ymin_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');"); } else { $frmGraph->addVar('yaxismin', $yaxismin); } } $frmGraph->addRow(S_YAXIS_MIN_VALUE, $yaxis_min); $yaxis_max = array(); $cmbYType = new CComboBox("ymax_type", $ymax_type, "submit()"); $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM); $yaxis_max[] = $cmbYType; if ($ymax_type == GRAPH_YAXIS_TYPE_FIXED) { $yaxis_max[] = new CTextBox("yaxismax", $yaxismax, 9); } else { if ($ymax_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $frmGraph->addVar('yaxismax', $yaxismax); $ymax_name = ''; if ($ymax_itemid > 0) { $max_host = get_host_by_itemid($ymax_itemid); $max_item = get_item_by_itemid($ymax_itemid); $ymax_name = $max_host['host'] . ':' . item_description($max_item); } $yaxis_max[] = new CTextBox("ymax_name", $ymax_name, 80, 'yes'); $yaxis_max[] = new CButton('yaxis_max', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . "&dstfld1=ymax_itemid" . "&dstfld2=ymax_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');"); } else { $frmGraph->addVar('yaxismax', $yaxismax); } } $frmGraph->addRow(S_YAXIS_MAX_VALUE, $yaxis_max); } else { $frmGraph->addRow(S_3D_VIEW, new CCheckBox('graph3d', $graph3d, 'javascript: graphs.submit(this);', 1)); $frmGraph->addRow(S_LEGEND, new CCheckBox('legend', $legend, 'javascript: graphs.submit(this);', 1)); } $only_hostid = null; $monitored_hosts = null; if (count($items)) { $frmGraph->addVar('items', $items); $items_table = new CTableInfo(); foreach ($items as $gid => $gitem) { if ($graphtype == GRAPH_TYPE_STACKED && $gitem['type'] == GRAPH_ITEM_AGGREGATED) { continue; } $host = get_host_by_itemid($gitem['itemid']); $item = get_item_by_itemid($gitem['itemid']); if ($host['status'] == HOST_STATUS_TEMPLATE) { $only_hostid = $host['hostid']; } else { $monitored_hosts = 1; } if ($gitem['type'] == GRAPH_ITEM_AGGREGATED) { $color = '-'; } else { $color = new CColorCell(null, $gitem['color']); } $do_up = new CLink(S_UP, '#', 'action'); $do_up->OnClick("return create_var('" . $frmGraph->GetName() . "','move_up'," . $gid . ", true);"); $do_down = new CLink(S_DOWN, '#', 'action'); $do_down->OnClick("return create_var('" . $frmGraph->GetName() . "','move_down'," . $gid . ", true);"); $description = new CLink($host['host'] . ': ' . item_description($item), '#', 'action'); $description->OnClick('return PopUp("popup_gitem.php?list_name=items&dstfrm=' . $frmGraph->GetName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . url_param($gitem, false) . url_param($gid, false, 'gid') . url_param(get_request('graphid', 0), false, 'graphid') . '",550,400,"graph_item_form");'); if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) { $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $gitem['sortorder'], $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), $color, array($do_up, SPACE . "|" . SPACE, $do_down))); } else { $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $gitem['sortorder'], $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), graph_item_drawtype2str($gitem["drawtype"], $gitem["type"]), $color, array($do_up, SPACE . "|" . SPACE, $do_down))); } } $dedlete_button = new CButton('delete_item', S_DELETE_SELECTED); } else { $items_table = $dedlete_button = null; } $frmGraph->addRow(S_ITEMS, array($items_table, new CButton('add_item', S_ADD, "return PopUp('popup_gitem.php?dstfrm=" . $frmGraph->GetName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . "',550,400,'graph_item_form');"), $dedlete_button)); unset($items_table, $dedlete_button); $frmGraph->addItemToBottomRow(new CButton("save", S_SAVE)); if (isset($_REQUEST["graphid"])) { $frmGraph->addItemToBottomRow(SPACE); $frmGraph->addItemToBottomRow(new CButton("clone", S_CLONE)); $frmGraph->addItemToBottomRow(SPACE); $frmGraph->addItemToBottomRow(new CButtonDelete(S_DELETE_GRAPH_Q, url_param("graphid") . url_param('groupid') . url_param("hostid"))); } $frmGraph->addItemToBottomRow(SPACE); $frmGraph->addItemToBottomRow(new CButtonCancel(url_param('groupid') . url_param("hostid"))); $frmGraph->Show(); }
function get_screen_plaintext($itemid, $elements, $style = 0) { if ($itemid == 0) { $table = new CTableInfo(S_ITEM_DOES_NOT_EXIST); $table->setHeader(array(S_TIMESTAMP, S_ITEM)); return $table; } $item = get_item_by_itemid($itemid); switch ($item['value_type']) { case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_LOG: $order_field = 'id'; break; case ITEM_VALUE_TYPE_FLOAT: case ITEM_VALUE_TYPE_UINT64: default: $order_field = 'clock'; } $host = get_host_by_itemid($itemid); $table = new CTableInfo(); $table->setHeader(array(S_TIMESTAMP, $host['host'] . ': ' . item_description($item))); $options = array('history' => $item['value_type'], 'itemids' => $itemid, 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN, 'sortfield' => $order_field, 'limit' => $elements); $hData = CHistory::get($options); foreach ($hData as $hnum => $data) { switch ($item['value_type']) { case ITEM_VALUE_TYPE_TEXT: /* do not use break */ /* do not use break */ case ITEM_VALUE_TYPE_STR: if ($style) { $value = new CJSscript($data['value']); } else { $value = $data['value']; } break; case ITEM_VALUE_TYPE_LOG: if ($style) { $value = new CJSscript($data['value']); } else { $value = $data['value']; } break; default: $value = $data['value']; break; } if ($item['valuemapid'] > 0) { $value = replace_value_by_map($value, $item['valuemapid']); } $table->addRow(array(zbx_date2str(S_SCREENS_PLAIN_TEXT_DATE_FORMAT, $data['clock']), new CCol($value, 'pre'))); } return $table; }
function get_screen_plaintext($itemid, $elements, $style = 0) { if ($itemid == 0) { $table = new CTableInfo(S_ITEM_DOES_NOT_EXIST); $table->setHeader(array(S_TIMESTAMP, S_ITEM)); return $table; } global $DB; $item = get_item_by_itemid($itemid); switch ($item['value_type']) { case ITEM_VALUE_TYPE_FLOAT: $history_table = 'history'; $order_field = 'clock'; break; case ITEM_VALUE_TYPE_UINT64: $history_table = 'history_uint'; $order_field = 'clock'; break; case ITEM_VALUE_TYPE_TEXT: $history_table = 'history_text'; $order_field = 'id'; break; case ITEM_VALUE_TYPE_LOG: $history_table = 'history_log'; $order_field = 'id'; break; default: $history_table = 'history_str'; $order_field = 'clock'; break; } $sql = 'SELECT h.clock,h.value,i.valuemapid ' . ' FROM ' . $history_table . ' h, items i ' . ' WHERE h.itemid=i.itemid ' . ' AND i.itemid=' . $itemid . ' ORDER BY h.' . $order_field . ' DESC'; $result = DBselect($sql, $elements); $host = get_host_by_itemid($itemid); $table = new CTableInfo(); $table->setHeader(array(S_TIMESTAMP, $host['host'] . ': ' . item_description($item))); while ($row = DBfetch($result)) { switch ($item['value_type']) { case ITEM_VALUE_TYPE_TEXT: if ($DB['TYPE'] == 'ORACLE') { if (isset($row['value'])) { $row['value'] = $row['value']->load(); } else { $row['value'] = ''; } } /* do not use break */ /* do not use break */ case ITEM_VALUE_TYPE_STR: if ($style) { $value = new CScript($row['value']); } else { $value = nbsp(htmlspecialchars($row['value'])); $value = zbx_nl2br($value); } break; case ITEM_VALUE_TYPE_LOG: if ($style) { $value = new CScript($row['value']); } else { $value = nbsp(htmlspecialchars($row['value'])); $value = zbx_nl2br($value); } break; default: $value = $row['value']; break; } if ($row['valuemapid'] > 0) { $value = replace_value_by_map($value, $row['valuemapid']); } $table->AddRow(array(date(S_DATE_FORMAT_YMDHMS, $row['clock']), $value)); } return $table; }
function get_realhost_by_itemid($itemid) { $item = get_item_by_itemid($itemid); if ($item['templateid'] != 0) { return get_realhost_by_itemid($item['templateid']); } return get_host_by_itemid($itemid); }
function bar_report_form2() { $config = get_request('config', 1); $title = get_request('title', _('Report 2')); $xlabel = get_request('xlabel', ''); $ylabel = get_request('ylabel', ''); $sorttype = get_request('sorttype', 0); $items = get_request('items', array()); $periods = get_request('periods', array()); $showlegend = get_request('showlegend', 0); $reportForm = new CFormTable(null, null, 'get'); //,'events.php?report_set=1','POST',null,'sform'); $reportForm->setAttribute('name', 'zbx_report'); $reportForm->setAttribute('id', 'zbx_report'); // $reportForm->setMethod('post'); if (isset($_REQUEST['report_show']) && !empty($items)) { $reportForm->addVar('report_show', 'show'); } $reportForm->addVar('config', $config); $reportForm->addVar('items', $items); // periods add later $reportForm->addRow(_('Title'), new CTextBox('title', $title, 40)); $reportForm->addRow(_('X label'), new CTextBox('xlabel', $xlabel, 40)); $reportForm->addRow(_('Y label'), new CTextBox('ylabel', $ylabel, 40)); $reportForm->addRow(_('Legend'), new CCheckBox('showlegend', $showlegend, null, 1)); if (count($periods) < 2) { $sortCmb = new CComboBox('sorttype', $sorttype); $sortCmb->addItem(0, _('Name')); $sortCmb->addItem(1, _('Value')); $reportForm->addRow(_('Sort by'), $sortCmb); } else { $reportForm->addVar('sortorder', 0); } //*/ // PERIODS if (count($periods)) { $periods_table = new CTableInfo(); foreach ($periods as $pid => $period) { $color = new CColorCell(null, $period['color']); $edit_link = 'popup_period.php?period_id=' . $pid . '&config=2' . '&dstfrm=' . $reportForm->getName() . '&caption=' . $period['caption'] . '&report_timesince=' . $period['report_timesince'] . '&report_timetill=' . $period['report_timetill'] . '&color=' . $period['color']; $caption = new CSpan($period['caption'], 'link'); $caption->addAction('onclick', "return PopUp('" . $edit_link . "',840,340,'period_form');"); $periods_table->addRow(array(new CCheckBox('group_pid[' . $pid . ']'), $caption, zbx_date2str(REPORTS_BAR_REPORT_DATE_FORMAT, $period['report_timesince']), zbx_date2str(REPORTS_BAR_REPORT_DATE_FORMAT, $period['report_timetill']), $color)); } $delete_button = new CSubmit('delete_period', _('Delete selected')); } else { $periods_table = $delete_button = null; } $reportForm->addVar('periods', $periods); $reportForm->addRow(_('Period'), array($periods_table, new CButton('add_period', _('Add'), "return PopUp('popup_period.php?config=2&dstfrm=" . $reportForm->getName() . "',840,340,'period_form');"), $delete_button)); unset($periods_table, $delete_button); //----------- // ITEMS if (count($items)) { $items_table = new CTableInfo(); foreach ($items as $gid => $gitem) { $host = get_host_by_itemid($gitem['itemid']); $item = get_item_by_itemid($gitem['itemid']); $caption = new CSpan($gitem['caption'], 'link'); $caption->onClick('return PopUp("popup_bitem.php?config=2&list_name=items&dstfrm=' . $reportForm->GetName() . url_param($gitem, false) . url_param($gid, false, 'gid') . '",550,400,"graph_item_form");'); $description = $host['name'] . ': ' . itemName($item); $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $caption, $description, graph_item_calc_fnc2str($gitem['calc_fnc'], 0))); } $delete_button = new CSubmit('delete_item', _('Delete selected')); } else { $items_table = $delete_button = null; } $reportForm->addRow(_('Items'), array($items_table, new CButton('add_item', _('Add'), "return PopUp('popup_bitem.php?config=2&dstfrm=" . $reportForm->getName() . "',550,400,'graph_item_form');"), $delete_button)); unset($items_table, $delete_button); //-------------- $reportForm->addItemToBottomRow(new CSubmit('report_show', _('Show'))); $reset = new CButton('reset', _('Reset')); $reset->setType('reset'); $reportForm->addItemToBottomRow($reset); return $reportForm; }
function insert_graph_form() { $frmGraph = new CFormTable(S_GRAPH, null, 'post'); $frmGraph->setName('frm_graph'); //$frmGraph->setHelp("web.graphs.graph.php"); $items = get_request('items', array()); if (isset($_REQUEST['graphid'])) { $frmGraph->addVar('graphid', $_REQUEST['graphid']); $options = array('graphids' => $_REQUEST['graphid'], 'extendoutput' => 1); $graphs = CGraph::get($options); $row = reset($graphs); $frmGraph->setTitle(S_GRAPH . ' "' . $row['name'] . '"'); } if (isset($_REQUEST['graphid']) && !isset($_REQUEST['form_refresh'])) { $name = $row['name']; $width = $row['width']; $height = $row['height']; $ymin_type = $row['ymin_type']; $ymax_type = $row['ymax_type']; $yaxismin = $row['yaxismin']; $yaxismax = $row['yaxismax']; $ymin_itemid = $row['ymin_itemid']; $ymax_itemid = $row['ymax_itemid']; $showworkperiod = $row['show_work_period']; $showtriggers = $row['show_triggers']; $graphtype = $row['graphtype']; $legend = $row['show_legend']; $graph3d = $row['show_3d']; $percent_left = $row['percent_left']; $percent_right = $row['percent_right']; $options = array('graphids' => $_REQUEST['graphid'], 'sortfield' => 'sortorder', 'extendoutput' => 1); $items = CGraphItem::get($options); } else { $name = get_request('name', ''); $graphtype = get_request('graphtype', GRAPH_TYPE_NORMAL); if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) { $width = get_request('width', 400); $height = get_request('height', 300); } else { $width = get_request('width', 900); $height = get_request('height', 200); } $ymin_type = get_request('ymin_type', GRAPH_YAXIS_TYPE_CALCULATED); $ymax_type = get_request('ymax_type', GRAPH_YAXIS_TYPE_CALCULATED); $yaxismin = get_request('yaxismin', 0.0); $yaxismax = get_request('yaxismax', 100.0); $ymin_itemid = get_request('ymin_itemid', 0); $ymax_itemid = get_request('ymax_itemid', 0); $showworkperiod = get_request('showworkperiod', 0); $showtriggers = get_request('showtriggers', 0); $legend = get_request('legend', 0); $graph3d = get_request('graph3d', 0); $visible = get_request('visible'); $percent_left = 0; $percent_right = 0; if (isset($visible['percent_left'])) { $percent_left = get_request('percent_left', 0); } if (isset($visible['percent_right'])) { $percent_right = get_request('percent_right', 0); } } /* reinit $_REQUEST */ $_REQUEST['items'] = $items; $_REQUEST['name'] = $name; $_REQUEST['width'] = $width; $_REQUEST['height'] = $height; $_REQUEST['ymin_type'] = $ymin_type; $_REQUEST['ymax_type'] = $ymax_type; $_REQUEST['yaxismin'] = $yaxismin; $_REQUEST['yaxismax'] = $yaxismax; $_REQUEST['ymin_itemid'] = $ymin_itemid; $_REQUEST['ymax_itemid'] = $ymax_itemid; $_REQUEST['showworkperiod'] = $showworkperiod; $_REQUEST['showtriggers'] = $showtriggers; $_REQUEST['graphtype'] = $graphtype; $_REQUEST['legend'] = $legend; $_REQUEST['graph3d'] = $graph3d; $_REQUEST['percent_left'] = $percent_left; $_REQUEST['percent_right'] = $percent_right; /********************/ if ($graphtype != GRAPH_TYPE_NORMAL) { foreach ($items as $gid => $gitem) { if ($gitem['type'] == GRAPH_ITEM_AGGREGATED) { unset($items[$gid]); } } } $items = array_values($items); $icount = count($items); for ($i = 0; $i < $icount - 1;) { // check if we deletd an item $next = $i + 1; while (!isset($items[$next]) && $next < $icount - 1) { $next++; } if (isset($items[$next]) && $items[$i]['sortorder'] == $items[$next]['sortorder']) { for ($j = $next; $j < $icount; $j++) { if ($items[$j - 1]['sortorder'] >= $items[$j]['sortorder']) { $items[$j]['sortorder']++; } } } $i = $next; } asort_by_key($items, 'sortorder'); $items = array_values($items); $group_gid = get_request('group_gid', array()); $frmGraph->addVar('ymin_itemid', $ymin_itemid); $frmGraph->addVar('ymax_itemid', $ymax_itemid); $frmGraph->addRow(S_NAME, new CTextBox('name', $name, 32)); $frmGraph->addRow(S_WIDTH, new CNumericBox('width', $width, 5)); $frmGraph->addRow(S_HEIGHT, new CNumericBox('height', $height, 5)); $cmbGType = new CComboBox('graphtype', $graphtype, 'graphs.submit(this)'); $cmbGType->addItem(GRAPH_TYPE_NORMAL, S_NORMAL); $cmbGType->addItem(GRAPH_TYPE_STACKED, S_STACKED); $cmbGType->addItem(GRAPH_TYPE_PIE, S_PIE); $cmbGType->addItem(GRAPH_TYPE_EXPLODED, S_EXPLODED); zbx_add_post_js('graphs.graphtype = ' . $graphtype . ";\n"); $frmGraph->addRow(S_GRAPH_TYPE, $cmbGType); // items beforehead, to get only_hostid for miny maxy items $only_hostid = null; $monitored_hosts = null; if (count($items)) { $frmGraph->addVar('items', $items); $keys = array_keys($items); $first = reset($keys); $last = end($keys); $items_table = new CTableInfo(); foreach ($items as $gid => $gitem) { //if($graphtype == GRAPH_TYPE_STACKED && $gitem['type'] == GRAPH_ITEM_AGGREGATED) continue; $host = get_host_by_itemid($gitem['itemid']); $item = get_item_by_itemid($gitem['itemid']); if ($host['status'] == HOST_STATUS_TEMPLATE) { $only_hostid = $host['hostid']; } else { $monitored_hosts = 1; } if ($gitem['type'] == GRAPH_ITEM_AGGREGATED) { $color = '-'; } else { $color = new CColorCell(null, $gitem['color']); } if ($gid == $first) { $do_up = null; } else { $do_up = new CSpan(S_UP, 'link'); $do_up->onClick("return create_var('" . $frmGraph->getName() . "','move_up'," . $gid . ", true);"); } if ($gid == $last) { $do_down = null; } else { $do_down = new CSpan(S_DOWN, 'link'); $do_down->onClick("return create_var('" . $frmGraph->getName() . "','move_down'," . $gid . ", true);"); } $description = new CSpan($host['host'] . ': ' . item_description($item), 'link'); $description->onClick('return PopUp("popup_gitem.php?list_name=items&dstfrm=' . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . url_param($gitem, false) . url_param($gid, false, 'gid') . url_param(get_request('graphid', 0), false, 'graphid') . '",550,400,"graph_item_form");'); if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) { $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), $color, array($do_up, SPACE . "|" . SPACE, $do_down))); } else { $items_table->addRow(array(new CCheckBox('group_gid[' . $gid . ']', isset($group_gid[$gid])), $description, graph_item_calc_fnc2str($gitem["calc_fnc"], $gitem["type"]), graph_item_type2str($gitem['type'], $gitem["periods_cnt"]), $gitem['yaxisside'] == GRAPH_YAXIS_SIDE_LEFT ? S_LEFT : S_RIGHT, graph_item_drawtype2str($gitem["drawtype"], $gitem["type"]), $color, array($do_up, !is_null($do_up) && !is_null($do_down) ? SPACE . "|" . SPACE : '', $do_down))); } } $dedlete_button = new CButton('delete_item', S_DELETE_SELECTED); } else { $items_table = $dedlete_button = null; } // $frmGraph->addRow(S_SHOW_LEGEND, new CCheckBox('legend',$legend, null, 1)); if ($graphtype == GRAPH_TYPE_NORMAL || $graphtype == GRAPH_TYPE_STACKED) { $frmGraph->addRow(S_SHOW_WORKING_TIME, new CCheckBox('showworkperiod', $showworkperiod, null, 1)); $frmGraph->addRow(S_SHOW_TRIGGERS, new CCheckBox('showtriggers', $showtriggers, null, 1)); if ($graphtype == GRAPH_TYPE_NORMAL) { $percent_left = sprintf('%2.2f', $percent_left); $percent_right = sprintf('%2.2f', $percent_right); $pr_left_input = new CTextBox('percent_left', $percent_left, '5'); $pr_left_chkbx = new CCheckBox('visible[percent_left]', 1, "javascript: ShowHide('percent_left');", 1); if ($percent_left == 0) { $pr_left_input->setAttribute('style', 'display: none;'); $pr_left_chkbx->setChecked(0); } $pr_right_input = new CTextBox('percent_right', $percent_right, '5'); $pr_right_chkbx = new CCheckBox('visible[percent_right]', 1, "javascript: ShowHide('percent_right');", 1); if ($percent_right == 0) { $pr_right_input->setAttribute('style', 'display: none;'); $pr_right_chkbx->setChecked(0); } $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_LEFT . ')', array($pr_left_chkbx, $pr_left_input)); $frmGraph->addRow(S_PERCENTILE_LINE . ' (' . S_RIGHT . ')', array($pr_right_chkbx, $pr_right_input)); } $yaxis_min = array(); $cmbYType = new CComboBox('ymin_type', $ymin_type, 'javascript: submit();'); $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM); $yaxis_min[] = $cmbYType; if ($ymin_type == GRAPH_YAXIS_TYPE_FIXED) { $yaxis_min[] = new CTextBox("yaxismin", $yaxismin, 9); } else { if ($ymin_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $frmGraph->addVar('yaxismin', $yaxismin); $ymin_name = ''; if ($ymin_itemid > 0) { $min_host = get_host_by_itemid($ymin_itemid); $min_item = get_item_by_itemid($ymin_itemid); $ymin_name = $min_host['host'] . ':' . item_description($min_item); } if (count($items)) { $yaxis_min[] = new CTextBox("ymin_name", $ymin_name, 80, 'yes'); $yaxis_min[] = new CButton('yaxis_min', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . "&dstfld1=ymin_itemid" . "&dstfld2=ymin_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');"); } else { $yaxis_min[] = SPACE . S_ADD_GRAPH_ITEMS; } } else { $frmGraph->addVar('yaxismin', $yaxismin); } } $frmGraph->addRow(S_YAXIS_MIN_VALUE, $yaxis_min); $yaxis_max = array(); $cmbYType = new CComboBox("ymax_type", $ymax_type, "submit()"); $cmbYType->addItem(GRAPH_YAXIS_TYPE_CALCULATED, S_CALCULATED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_FIXED, S_FIXED); $cmbYType->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, S_ITEM); $yaxis_max[] = $cmbYType; if ($ymax_type == GRAPH_YAXIS_TYPE_FIXED) { $yaxis_max[] = new CTextBox('yaxismax', $yaxismax, 9); } else { if ($ymax_type == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $frmGraph->addVar('yaxismax', $yaxismax); $ymax_name = ''; if ($ymax_itemid > 0) { $max_host = get_host_by_itemid($ymax_itemid); $max_item = get_item_by_itemid($ymax_itemid); $ymax_name = $max_host['host'] . ':' . item_description($max_item); } if (count($items)) { $yaxis_max[] = new CTextBox("ymax_name", $ymax_name, 80, 'yes'); $yaxis_max[] = new CButton('yaxis_max', S_SELECT, 'javascript: ' . "return PopUp('popup.php?dstfrm=" . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . "&dstfld1=ymax_itemid" . "&dstfld2=ymax_name" . "&srctbl=items" . "&srcfld1=itemid" . "&srcfld2=description',0,0,'zbx_popup_item');"); } else { $yaxis_max[] = SPACE . S_ADD_GRAPH_ITEMS; } } else { $frmGraph->addVar('yaxismax', $yaxismax); } } $frmGraph->addRow(S_YAXIS_MAX_VALUE, $yaxis_max); } else { $frmGraph->addRow(S_SHOW_LEGEND, new CCheckBox('legend', $legend, null, 1)); $frmGraph->addRow(S_3D_VIEW, new CCheckBox('graph3d', $graph3d, null, 1)); } $frmGraph->addRow(S_ITEMS, array($items_table, new CButton('add_item', S_ADD, "return PopUp('popup_gitem.php?dstfrm=" . $frmGraph->getName() . url_param($only_hostid, false, 'only_hostid') . url_param($monitored_hosts, false, 'monitored_hosts') . url_param($graphtype, false, 'graphtype') . "',550,400,'graph_item_form');"), $dedlete_button)); unset($items_table, $dedlete_button); $preView = new CButton('preview', S_PREVIEW); //$preView->setAttribute('style', 'float: left;'); $frmGraph->addItemToBottomRow($preView); $frmGraph->addItemToBottomRow(SPACE); $frmGraph->addItemToBottomRow(new CButton('save', S_SAVE)); if (isset($_REQUEST['graphid'])) { $frmGraph->addItemToBottomRow(SPACE); $frmGraph->addItemToBottomRow(new CButton('clone', S_CLONE)); $frmGraph->addItemToBottomRow(SPACE); $frmGraph->addItemToBottomRow(new CButtonDelete(S_DELETE_GRAPH_Q, url_param('graphid') . url_param('groupid') . url_param('hostid'))); } $frmGraph->addItemToBottomRow(SPACE); $frmGraph->addItemToBottomRow(new CButtonCancel(url_param('groupid') . url_param('hostid'))); $frmGraph->show(); }
function construct_expression($itemid, $expressions) { $complite_expr = ''; $item = get_item_by_itemid($itemid); $host = get_host_by_itemid($itemid); $prefix = $host['host'] . ':' . $item['key_'] . '.'; if (empty($expressions)) { error(S_EXPRESSION_CANNOT_BE_EMPTY); return false; } $functions = array('regexp' => 1, 'iregexp' => 1); // $ZBX_EREG_EXPESSION_FUNC_FORMAT = '^([[:print:]]*)([&|]{1})(([a-zA-Z_.$]{6,7})(\\(([[:print:]]+){0,1}\\)))([[:print:]]*)$'; $ZBX_PREG_EXPESSION_FUNC_FORMAT = '^([' . ZBX_PREG_PRINT . ']*)([&|]{1})(([a-zA-Z_.\\$]{6,7})(\\(([' . ZBX_PREG_PRINT . ']+){0,1}\\)))([' . ZBX_PREG_PRINT . ']*)$'; $expr_array = array(); $cexpor = 0; $startpos = -1; foreach ($expressions as $id => $expression) { $expression['value'] = preg_replace('/\\s+(AND){1,2}\\s+/U', '&', $expression['value']); $expression['value'] = preg_replace('/\\s+(OR){1,2}\\s+/U', '|', $expression['value']); //sdi('<pre>'.print_r($expression['value'],true).'</pre>'); $pastcexpor = $cexpor; if ($expression['type'] == REGEXP_INCLUDE) { if (!empty($complite_expr)) { $complite_expr .= ' | '; } if ($cexpor == 0) { $startpos = zbx_strlen($complite_expr); } $cexpor++; $eq_global = '#0'; } else { if ($cexpor > 1 & $startpos >= 0) { $head = substr($complite_expr, 0, $startpos); $tail = substr($complite_expr, $startpos); $complite_expr = $head . '(' . $tail . ')'; } $cexpor = 0; $eq_global = '=0'; if (!empty($complite_expr)) { $complite_expr .= ' & '; } } $expr = '&' . $expression['value']; //$expr = '&'.$expression['view']; $expr = preg_replace('/\\s+(\\&|\\|){1,2}\\s+/U', '$1', $expr); $expr_array = array(); $sub_expr_count = 0; $sub_expr = ''; $multi = preg_match('/.+(&|\\|).+/', $expr); // while(mb_eregi($ZBX_EREG_EXPESSION_FUNC_FORMAT, $expr, $arr)){ while (preg_match('/' . $ZBX_PREG_EXPESSION_FUNC_FORMAT . '/i', $expr, $arr)) { $arr[4] = zbx_strtolower($arr[4]); if (!isset($functions[$arr[4]])) { error(S_INCORRECT_FUNCTION_IS_USED . '. [' . $expression['value'] . ']'); return false; } $expr_array[$sub_expr_count]['eq'] = trim($arr[2]); $expr_array[$sub_expr_count]['regexp'] = zbx_strtolower($arr[4]) . $arr[5]; $sub_expr_count++; $expr = $arr[1]; } if (empty($expr_array)) { error(S_INCORRECT_TRIGGER_EXPRESSION . '. [' . $expression['value'] . ']'); return false; } $expr_array[$sub_expr_count - 1]['eq'] = ''; $sub_eq = ''; if ($multi > 0) { $sub_eq = $eq_global; } foreach ($expr_array as $id => $expr) { if ($multi > 0) { $sub_expr = $expr['eq'] . '({' . $prefix . $expr['regexp'] . '})' . $sub_eq . $sub_expr; } else { $sub_expr = $expr['eq'] . '{' . $prefix . $expr['regexp'] . '}' . $sub_eq . $sub_expr; } } if ($multi > 0) { $complite_expr .= '(' . $sub_expr . ')'; } else { $complite_expr .= '((' . $sub_expr . ')' . $eq_global . ')'; } } if ($cexpor > 1 & $startpos >= 0) { $head = substr($complite_expr, 0, $startpos); $tail = substr($complite_expr, $startpos); $complite_expr = $head . '(' . $tail . ')'; } return $complite_expr; }