本文整理汇总了PHP中get_host_by_itemid函数的典型用法代码示例。如果您正苦于以下问题:PHP get_host_by_itemid函数的具体用法?PHP get_host_by_itemid怎么用?PHP get_host_by_itemid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_host_by_itemid函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* 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']));
}
示例2: get
/**
* 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);
}
示例3: make_graph_submenu
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;
}
示例4: construct_expression
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;
}
示例5: get_realhost_by_itemid
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);
}
示例6: bar_report_form2
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;
}
示例7: get_host_by_itemid
$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;
示例8: array
$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 {
示例9: insert_graph_form
//.........这里部分代码省略.........
$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);
}
示例10: get_screen_plaintext
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;
}
示例11: get_screen_plaintext
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;
}
示例12: bar_report_form2
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;
}
示例13: insert_graph_form
//.........这里部分代码省略.........
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);
示例14: construct_expression
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;
}