protected function inherit($graph, $hostids = null) { $graphTemplates = API::Template()->get(array('itemids' => zbx_objectValues($graph['gitems'], 'itemid'), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => true)); if (empty($graphTemplates)) { return true; } $graphTemplate = reset($graphTemplates); $chdHosts = API::Host()->get(array('templateids' => $graphTemplate['templateid'], 'output' => array('hostid', 'host'), 'preservekeys' => true, 'hostids' => $hostids, 'nopermissions' => true, 'templated_hosts' => true)); $graph = $this->get(array('graphids' => $graph['graphid'], 'nopermissions' => true, 'filter' => array('flags' => null), 'selectItems' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND)); $graph = reset($graph); foreach ($chdHosts as $chdHost) { $tmpGraph = $graph; $tmpGraph['templateid'] = $graph['graphid']; if (!($tmpGraph['gitems'] = get_same_graphitems_for_host($tmpGraph['gitems'], $chdHost['hostid']))) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s".', $tmpGraph['name'], $chdHost['host'])); } if ($tmpGraph['ymax_itemid'] > 0) { $ymaxItemid = get_same_graphitems_for_host(array(array('itemid' => $tmpGraph['ymax_itemid'])), $chdHost['hostid']); if (!$ymaxItemid) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s" (Ymax value item).', $tmpGraph['name'], $chdHost['host'])); } $ymaxItemid = reset($ymaxItemid); $tmpGraph['ymax_itemid'] = $ymaxItemid['itemid']; } if ($tmpGraph['ymin_itemid'] > 0) { $yminItemid = get_same_graphitems_for_host(array(array('itemid' => $tmpGraph['ymin_itemid'])), $chdHost['hostid']); if (!$yminItemid) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s" (Ymin value item).', $tmpGraph['name'], $chdHost['host'])); } $yminItemid = reset($yminItemid); $tmpGraph['ymin_itemid'] = $yminItemid['itemid']; } // check if templated graph exists $chdGraphs = $this->get(array('filter' => array('templateid' => $tmpGraph['graphid'], 'flags' => array(ZBX_FLAG_DISCOVERY_CHILD, ZBX_FLAG_DISCOVERY_NORMAL)), 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'hostids' => $chdHost['hostid'])); if ($chdGraph = reset($chdGraphs)) { if (zbx_strtolower($tmpGraph['name']) != zbx_strtolower($chdGraph['name']) && $this->exists(array('name' => $tmpGraph['name'], 'hostids' => $chdHost['hostid']))) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s".', $tmpGraph['name'], $chdHost['host'])); } elseif ($chdGraph['flags'] != $tmpGraph['flags']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Graph with same name but other type exist.')); } $tmpGraph['graphid'] = $chdGraph['graphid']; $this->updateReal($tmpGraph, $chdGraph); } else { $chdGraph = $this->get(array('filter' => array('name' => $tmpGraph['name'], 'flags' => null), 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'nopermissions' => true, 'hostids' => $chdHost['hostid'])); if ($chdGraph = reset($chdGraph)) { if ($chdGraph['templateid'] != 0) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (inherited from another template).', $tmpGraph['name'], $chdHost['host'])); } elseif ($chdGraph['flags'] != $tmpGraph['flags']) { self::exception(ZBX_API_ERROR_PARAMETERS, _('Graph with same name but other type exist.')); } $chdGraphItems = API::GraphItem()->get(array('graphids' => $chdGraph['graphid'], 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'expandData' => true, 'nopermissions' => true)); if (count($chdGraphItems) == count($tmpGraph['gitems'])) { foreach ($tmpGraph['gitems'] as $gitem) { foreach ($chdGraphItems as $chdItem) { if ($gitem['key_'] == $chdItem['key_'] && bccomp($chdHost['hostid'], $chdItem['hostid']) == 0) { continue 2; } } self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (items are not identical).', $tmpGraph['name'], $chdHost['host'])); } $tmpGraph['graphid'] = $chdGraph['graphid']; $this->updateReal($tmpGraph, $chdGraph); } else { self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (items are not identical).', $tmpGraph['name'], $chdHost['host'])); } } else { $graphid = $this->createReal($tmpGraph); $tmpGraph['graphid'] = $graphid; } } $this->inherit($tmpGraph); } }
/** * Copy specified graph to specified host. * * @param $graphid * @param $hostid * @return array|bool */ function copy_graph_to_host($graphid, $hostid) { $graphs = API::Graph()->get(array('graphids' => $graphid, 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND)); $graph = reset($graphs); $new_gitems = get_same_graphitems_for_host($graph['gitems'], $hostid); if (!$new_gitems) { $host = get_host_by_hostid($hostid); info(_s('Skipped copying of graph "%1$s" to host "%2$s".', $graph['name'], $host['host'])); return false; } // retrieve actual ymax_itemid and ymin_itemid if ($graph['ymax_itemid']) { if ($itemid = get_same_item_for_host($graph['ymax_itemid'], $hostid)) { $graph['ymax_itemid'] = $itemid; } } if ($graph['ymin_itemid']) { if ($itemid = get_same_item_for_host($graph['ymin_itemid'], $hostid)) { $graph['ymin_itemid'] = $itemid; } } $graph['gitems'] = $new_gitems; unset($graph['templateid']); $result = API::Graph()->create($graph); return $result; }
protected static function addItems_rec($graphid, $items, $tpl_graph = false) { if ($tpl_graph) { $chd_graphs = get_graphs_by_templateid($graphid); while ($chd_graph = DBfetch($chd_graphs)) { $result = self::addItems_rec($chd_graph['graphid'], $items, $tpl_graph); if (!$result) { return false; } } $tmp_hosts = get_hosts_by_graphid($graphid); $graph_host = DBfetch($tmp_hosts); if (!($items = get_same_graphitems_for_host($items, $graph_host['hostid']))) { self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Can not update graph "' . $chd_graph['name'] . '" for host "' . $graph_host['host'] . '"'); return false; } } foreach ($items as $item) { $result = add_item_to_graph($graphid, $item['itemid'], $item['color'], $item['drawtype'], $item['sortorder'], $item['yaxisside'], $item['calc_fnc'], $item['type'], $item['periods_cnt']); if (!$result) { return false; } } return true; }
function copy_graph_to_host($graphid, $hostid, $copy_mode = false) { $result = false; $gitems = array(); $db_graph_items = get_graphitems_by_graphid($graphid); while ($db_gitem = DBfetch($db_graph_items)) { $gitems[] = array('itemid' => $db_gitem['itemid'], 'color' => $db_gitem['color'], 'drawtype' => $db_gitem['drawtype'], 'sortorder' => $db_gitem['sortorder'], 'yaxisside' => $db_gitem['yaxisside'], 'calc_fnc' => $db_gitem['calc_fnc'], 'type' => $db_gitem['type'], 'periods_cnt' => $db_gitem['periods_cnt']); } $db_graph = get_graph_by_graphid($graphid); if ($new_gitems = get_same_graphitems_for_host($gitems, $hostid)) { unset($chd_graphid); $chd_graphs = get_graphs_by_hostid($hostid); while (!isset($chd_graphid) && ($chd_graph = DBfetch($chd_graphs))) { /* compare graphs */ if ($chd_graph['templateid'] != 0) { continue; } unset($equal); $chd_gitems = get_graphitems_by_graphid($chd_graph["graphid"]); while ($chd_gitem = DBfetch($chd_gitems)) { unset($gitem_equal); foreach ($new_gitems as $new_gitem) { if (cmp_graphitems($new_gitem, $chd_gitem)) { continue; } $gitem_equal = true; break; } if (!isset($gitem_equal)) { unset($equal); break; } /* founded equal graph item */ if (!isset($equal)) { $equal = 0; } $equal++; } if (isset($equal) && count($new_gitems) == $equal) { /* founded equal graph */ $chd_graphid = $chd_graph['graphid']; break; } } if (isset($chd_graphid)) { $result = update_graph_with_items($chd_graphid, $db_graph['name'], $db_graph['width'], $db_graph['height'], $db_graph['ymin_type'], $db_graph['ymax_type'], $db_graph['yaxismin'], $db_graph['yaxismax'], $db_graph['ymin_itemid'], $db_graph['ymax_itemid'], $db_graph['show_work_period'], $db_graph['show_triggers'], $db_graph['graphtype'], $db_graph['show_legend'], $db_graph['show_3d'], $db_graph['percent_left'], $db_graph['percent_right'], $new_gitems, $copy_mode ? 0 : $db_graph['graphid']); } else { $result = add_graph_with_items($db_graph['name'], $db_graph['width'], $db_graph['height'], $db_graph['ymin_type'], $db_graph['ymax_type'], $db_graph['yaxismin'], $db_graph['yaxismax'], $db_graph['ymin_itemid'], $db_graph['ymax_itemid'], $db_graph['show_work_period'], $db_graph['show_triggers'], $db_graph['graphtype'], $db_graph['show_legend'], $db_graph['show_3d'], $db_graph['percent_left'], $db_graph['percent_right'], $new_gitems, $copy_mode ? 0 : $db_graph['graphid']); } } else { $host = get_host_by_hostid($hostid); info('Skipped coping of graph "' . $db_graph["name"] . '" to host "' . $host['host'] . '"'); } return $result; }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $this->dataId = 'graph_' . $this->screenitem['screenitemid'] . '_' . $this->screenitem['screenid']; $resourceid = !empty($this->screenitem['real_resourceid']) ? $this->screenitem['real_resourceid'] : $this->screenitem['resourceid']; $containerid = 'graph_container_' . $this->screenitem['screenitemid'] . '_' . $this->screenitem['screenid']; $graphDims = getGraphDims($resourceid); $graphDims['graphHeight'] = $this->screenitem['height']; $graphDims['width'] = $this->screenitem['width']; $graph = get_graph_by_graphid($resourceid); $graphid = $graph['graphid']; $legend = $graph['show_legend']; $graph3d = $graph['show_3d']; if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && !empty($this->hostid)) { // get host $hosts = API::Host()->get(array('hostids' => $this->hostid, 'output' => array('hostid', 'name'))); $host = reset($hosts); // get graph $graph = API::Graph()->get(array('graphids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'selectHosts' => API_OUTPUT_REFER, 'selectGraphItems' => API_OUTPUT_EXTEND)); $graph = reset($graph); // if items from one host we change them, or set calculated if not exist on that host if (count($graph['hosts']) == 1) { if ($graph['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymax_itemid']) { $newDinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymax_itemid'])), $this->hostid, false); $newDinamic = reset($newDinamic); if (isset($newDinamic['itemid']) && $newDinamic['itemid'] > 0) { $graph['ymax_itemid'] = $newDinamic['itemid']; } else { $graph['ymax_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } if ($graph['ymin_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymin_itemid']) { $newDinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymin_itemid'])), $this->hostid, false); $newDinamic = reset($newDinamic); if (isset($newDinamic['itemid']) && $newDinamic['itemid'] > 0) { $graph['ymin_itemid'] = $newDinamic['itemid']; } else { $graph['ymin_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } } // get url $this->screenitem['url'] = $graph['graphtype'] == GRAPH_TYPE_PIE || $graph['graphtype'] == GRAPH_TYPE_EXPLODED ? 'chart7.php' : 'chart3.php'; $this->screenitem['url'] = new CUrl($this->screenitem['url']); foreach ($graph as $name => $value) { if ($name == 'width' || $name == 'height') { continue; } $this->screenitem['url']->setArgument($name, $value); } $newGraphItems = get_same_graphitems_for_host($graph['gitems'], $this->hostid, false); foreach ($newGraphItems as $newGraphItem) { unset($newGraphItem['gitemid'], $newGraphItem['graphid']); foreach ($newGraphItem as $name => $value) { $this->screenitem['url']->setArgument('items[' . $newGraphItem['itemid'] . '][' . $name . ']', $value); } } $this->screenitem['url']->setArgument('name', $host['name'] . ': ' . $graph['name']); $this->screenitem['url'] = $this->screenitem['url']->getUrl(); } // get time control $timeControlData = array('id' => $this->getDataId(), 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'periodFixed' => CProfile::get('web.screens.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD); $isDefault = false; if ($graphDims['graphtype'] == GRAPH_TYPE_PIE || $graphDims['graphtype'] == GRAPH_TYPE_EXPLODED) { if ($this->screenitem['dynamic'] == SCREEN_SIMPLE_ITEM || empty($this->screenitem['url'])) { $this->screenitem['url'] = 'chart6.php?graphid=' . $resourceid . '&screenid=' . $this->screenitem['screenid']; $isDefault = true; } $this->timeline['starttime'] = date('YmdHis', get_min_itemclock_by_graphid($resourceid)); $timeControlData['src'] = $this->screenitem['url'] . '&width=' . $this->screenitem['width'] . '&height=' . $this->screenitem['height'] . '&legend=' . $legend . '&graph3d=' . $graph3d . $this->getProfileUrlParams(); $timeControlData['src'] .= $this->mode == SCREEN_MODE_EDIT ? '&period=3600&stime=' . date('YmdHis', time()) : '&period=' . $this->timeline['period'] . '&stime=' . $this->timeline['stimeNow']; } else { if ($this->screenitem['dynamic'] == SCREEN_SIMPLE_ITEM || empty($this->screenitem['url'])) { $this->screenitem['url'] = 'chart2.php?graphid=' . $resourceid . '&screenid=' . $this->screenitem['screenid']; $isDefault = true; } if ($this->mode != SCREEN_MODE_EDIT && !empty($graphid)) { if ($this->mode == SCREEN_MODE_PREVIEW) { $timeControlData['loadSBox'] = 1; } } $timeControlData['src'] = $this->screenitem['url'] . '&width=' . $this->screenitem['width'] . '&height=' . $this->screenitem['height'] . $this->getProfileUrlParams(); $timeControlData['src'] .= $this->mode == SCREEN_MODE_EDIT ? '&period=3600&stime=' . date('YmdHis', time()) : '&period=' . $this->timeline['period'] . '&stime=' . $this->timeline['stimeNow']; } // output if ($this->mode == SCREEN_MODE_JS) { return 'timeControl.addObject("' . $this->getDataId() . '", ' . zbx_jsvalue($this->timeline) . ', ' . zbx_jsvalue($timeControlData) . ')'; } else { if ($this->mode == SCREEN_MODE_SLIDESHOW) { insert_js('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 ($this->mode == SCREEN_MODE_EDIT || $this->mode == SCREEN_MODE_SLIDESHOW || !$isDefault) { $item = new CDiv(); } elseif ($this->mode == SCREEN_MODE_PREVIEW) { $item = new CLink(null, 'charts.php?graphid=' . $resourceid . '&period=' . $this->timeline['period'] . '&stime=' . $this->timeline['stimeNow']); } $item->setAttribute('id', $containerid); return $this->getOutput($item); } }
function get_screen($screenid, $editmode, $effectiveperiod = NULL) { global $USER_DETAILS; if ($screenid == 0) { return new CTableInfo(S_NO_SCREENS_DEFINED); } $r = CScreen::get(array('screenids' => $screenid, 'editable' => $editmode == 1 ? 1 : null, 'output' => API_OUTPUT_SHORTEN)); if (empty($r)) { access_deny(); } if (is_null($effectiveperiod)) { $effectiveperiod = ZBX_MIN_PERIOD; } $result = DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid=' . $screenid); $row = DBfetch($result); if (!$row) { return new CTableInfo(S_NO_SCREENS_DEFINED); } $sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid; $iresult = DBSelect($sql); $skip_field = array(); $irows = array(); while ($irow = DBfetch($iresult)) { $irows[] = $irow; for ($i = 0; $i < $irow['rowspan'] || $i == 0; $i++) { for ($j = 0; $j < $irow['colspan'] || $j == 0; $j++) { if ($i != 0 || $j != 0) { if (!isset($skip_field[$irow['y'] + $i])) { $skip_field[$irow['y'] + $i] = array(); } $skip_field[$irow['y'] + $i][$irow['x'] + $j] = 1; } } } } $table = new CTable(new CLink(S_NO_ROWS_IN_SCREEN . SPACE . $row['name'], 'screenconf.php?config=0&form=update&screenid=' . $screenid), $editmode == 0 || $editmode == 2 ? 'screen_view' : 'screen_edit'); $table->setAttribute('id', 'iframe'); if ($editmode == 1) { $new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); for ($c = 0; $c < $row['hsize'] + 1; $c++) { $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_col={$c}';"); array_push($new_cols, new Ccol($add_icon)); } $table->addRow($new_cols); } $empty_screen_col = array(); for ($r = 0; $r < $row['vsize']; $r++) { $new_cols = array(); $empty_screen_row = true; if ($editmode == 1) { $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$r}';"); array_push($new_cols, new Ccol($add_icon)); } for ($c = 0; $c < $row['hsize']; $c++) { $item = array(); if (isset($skip_field[$r][$c])) { continue; } $item_form = false; $irow = false; foreach ($irows as $tmprow) { if ($tmprow['x'] == $c && $tmprow['y'] == $r) { $irow = $tmprow; break; } } if ($irow) { $screenitemid = $irow['screenitemid']; $resourcetype = $irow['resourcetype']; $resourceid = $irow['resourceid']; $width = $irow['width']; $height = $irow['height']; $colspan = $irow['colspan']; $rowspan = $irow['rowspan']; $elements = $irow['elements']; $valign = $irow['valign']; $halign = $irow['halign']; $style = $irow['style']; $url = $irow['url']; $dynamic = $irow['dynamic']; } else { $screenitemid = 0; $resourcetype = 0; $resourceid = 0; $width = 0; $height = 0; $colspan = 0; $rowspan = 0; $elements = 0; $valign = VALIGN_DEFAULT; $halign = HALIGN_DEFAULT; $style = 0; $url = ''; $dynamic = 0; } if ($screenitemid > 0) { $empty_screen_row = false; $empty_screen_col[$c] = 1; } if ($editmode == 1 && $screenitemid != 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&screenitemid=' . $screenitemid . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitemid . '#form'; } else { if ($editmode == 1 && $screenitemid == 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&x=' . $c . '&y=' . $r . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r . '#form'; } else { $action = NULL; } } if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['x']) && $_REQUEST['x'] == $c && isset($_REQUEST['y']) && $_REQUEST['y'] == $r) { // click on empty field $item = get_screen_item_form(); $item_form = true; } else { if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['screenitemid']) && bccomp($_REQUEST['screenitemid'], $screenitemid) == 0) { // click on element $item = get_screen_item_form(); $item_form = true; } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_GRAPH) { if ($editmode == 0) { $action = 'charts.php?graphid=' . $resourceid . url_param('period') . url_param('stime'); } // GRAPH & ZOOM features $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid; $graphDims = getGraphDims($resourceid); $graphDims['graphHeight'] = $height; $graphDims['width'] = $width; $graph = get_graph_by_graphid($resourceid); $graphid = $graph['graphid']; $legend = $graph['show_legend']; $graph3d = $graph['show_3d']; //------------- // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { $options = array('hostids' => $_REQUEST['hostid'], 'output' => array('hostid', 'host')); $hosts = CHost::get($options); $host = reset($hosts); $options = array('graphids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_REFER, 'select_graph_items' => API_OUTPUT_EXTEND); $graph = CGraph::get($options); $graph = reset($graph); if (count($graph['hosts']) == 1) { // if items from one host we change them, or set calculated if not exist on that host if ($graph['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymax_itemid']) { $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymax_itemid'])), $_REQUEST['hostid'], false); $new_dinamic = reset($new_dinamic); if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) { $graph['ymax_itemid'] = $new_dinamic['itemid']; } else { $graph['ymax_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } if ($graph['ymin_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymin_itemid']) { $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymin_itemid'])), $_REQUEST['hostid'], false); $new_dinamic = reset($new_dinamic); if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) { $graph['ymin_itemid'] = $new_dinamic['itemid']; } else { $graph['ymin_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } } $url = $graph['graphtype'] == GRAPH_TYPE_PIE || $graph['graphtype'] == GRAPH_TYPE_EXPLODED ? 'chart7.php' : 'chart3.php'; $url = new Curl($url); foreach ($graph as $name => $value) { if ($name == 'width' || $name == 'height') { continue; } $url->setArgument($name, $value); } $new_items = get_same_graphitems_for_host($graph['gitems'], $_REQUEST['hostid'], false); foreach ($new_items as $gitem) { unset($gitem['gitemid']); unset($gitem['graphid']); foreach ($gitem as $name => $value) { $url->setArgument('items[' . $gitem['itemid'] . '][' . $name . ']', $value); } } $url->setArgument('name', $host['host'] . ': ' . $graph['name']); $url = $url->getUrl(); } //------------- $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0); $default = false; if ($graphDims['graphtype'] == GRAPH_TYPE_PIE || $graphDims['graphtype'] == GRAPH_TYPE_EXPLODED) { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart6.php?graphid=' . $resourceid; $default = true; } $timeline = array(); $timeline['period'] = $effectiveperiod; $timeline['starttime'] = date('YmdHis', get_min_itemclock_by_graphid($resourceid)); if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } // $src = $url.'&width='.$width.'&height='.$height.'&legend='.$legend.'&graph3d='.$graph3d; $src = $url . '&width=' . $width . '&height=' . $height . '&legend=' . $legend . '&graph3d=' . $graph3d . '&period=' . $effectiveperiod . url_param('stime'); $objData['src'] = $src; } else { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart2.php?graphid=' . $resourceid; $default = true; } $src = $url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime'); $timeline = array(); if (isset($graphid) && !is_null($graphid) && $editmode != 1) { $timeline['period'] = $effectiveperiod; $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD); //get_min_itemclock_by_graphid($graphid); if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } $objData['loadSBox'] = 1; } $objData['src'] = $src; } if ($editmode || !$default) { $item = new CDiv(); } else { $item = new CLink(null, $action); } $item->setAttribute('id', $containerid); $item = array($item); if ($editmode == 1) { $item[] = BR(); $item[] = new CLink(S_CHANGE, $action); } if ($editmode == 2) { insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } else { zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) { $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid; $graphDims = getGraphDims(); $graphDims['graphHeight'] = $height; $graphDims['width'] = $width; $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0); // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = ''; } } //------------- if ($editmode == 0 && !empty($resourceid)) { $action = 'history.php?action=showgraph&itemid=' . $resourceid . url_param('period') . url_param('stime'); } $timeline = array(); $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD); if (!zbx_empty($resourceid) && $editmode != 1) { $timeline['period'] = $effectiveperiod; if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } $objData['loadSBox'] = 1; } $src = zbx_empty($resourceid) ? 'chart3.php?' : 'chart.php?itemid=' . $resourceid . '&'; $src .= $url . 'width=' . $width . '&height=' . $height; $objData['src'] = $src; if ($editmode) { $item = new CDiv(); } else { $item = new CLink(null, $action); } $item->setAttribute('id', $containerid); $item = array($item); if ($editmode == 1) { $item[] = BR(); $item[] = new CLink(S_CHANGE, $action); } if ($editmode == 2) { insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } else { zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_MAP) { $image_map = new CImg("map.php?noedit=1&sysmapid={$resourceid}" . "&width={$width}&height={$height}&curtime=" . time()); if ($editmode == 0) { $options = array('sysmapids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_selements' => API_OUTPUT_EXTEND, 'nopermissions' => 1); $sysmaps = CMap::get($options); $sysmap = reset($sysmaps); $action_map = getActionMapBySysmap($sysmap); $image_map->setMap($action_map->getName()); $item = array($action_map, $image_map); } else { $item = $image_map; // $item = new CLink($image_map, $action); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) { // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = 0; } } //------------- $item = array(get_screen_plaintext($resourceid, $elements, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTGROUP_TRIGGERS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements); $tr_form = S_ALL_S; if ($resourceid > 0) { $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND); $hostgroups = CHostgroup::get($options); $hostgroup = reset($hostgroups); $tr_form = new CSpan(S_GROUP . ': ' . $hostgroup['name'], 'white'); $params['groupids'] = $hostgroup['groupid']; } else { $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0)); $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0)); CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID); CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); order_result($groups, 'name'); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); if ($groupid > 0) { $options['groupids'] = $groupid; } $hosts = CHost::get($options); $hosts = zbx_toHash($hosts, 'hostid'); order_result($hosts, 'host'); if (!isset($hosts[$hostid])) { $hostid = 0; } $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); foreach ($groups as $gnum => $group) { $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']); } foreach ($hosts as $hnum => $host) { $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); if ($groupid > 0) { $params['groupids'] = $groupid; } if ($hostid > 0) { $params['hostids'] = $hostid; } } $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form)); $item[] = make_latest_issues($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } ///----------------------- } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOST_TRIGGERS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements); $tr_form = S_ALL_S; if ($resourceid > 0) { $options = array('hostids' => $resourceid, 'output' => API_OUTPUT_EXTEND); $hosts = CHost::get($options); $host = reset($hosts); $tr_form = new CSpan(S_HOST . ': ' . $host['host'], 'white'); $params['hostids'] = $host['hostid']; } else { $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0)); $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0)); CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID); CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); order_result($groups, 'name'); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); if ($groupid > 0) { $options['groupids'] = $groupid; } $hosts = CHost::get($options); $hosts = zbx_toHash($hosts, 'hostid'); order_result($hosts, 'host'); if (!isset($hosts[$hostid])) { $hostid = 0; } $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); foreach ($groups as $gnum => $group) { $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']); } foreach ($hosts as $hnum => $host) { $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); if ($groupid > 0) { $params['groupids'] = $groupid; } if ($hostid > 0) { $params['hostids'] = $hostid; } } ///----------------------- $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form)); $item[] = make_latest_issues($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SYSTEM_STATUS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => null, 'extAck' => 0); $item = array(get_table_header(array(S_SYSTEM_STATUS, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)))); $item[] = make_system_status($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTS_INFO) { $item = array(new CHostsInfo($resourceid, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) { $item = new CTriggersInfo($resourceid, null, $style); $item = array($item); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SERVER_INFO) { // $item = array(get_table_header(S_STATUS_OF_ZABBIX_BIG),make_status_of_zbx()); $item = array(new CServerInfo()); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_CLOCK) { $item = new CFlashClock($width, $height, $style, $action); } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SCREEN) { $item = array(get_screen($resourceid, 2, $effectiveperiod)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_triggers_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_DATA_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_items_data_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_URL) { $item = array(new CIFrame($url, $width, $height, "auto")); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_ACTIONS) { $item = array(get_history_of_actions($elements)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_EVENTS) { $options = array('monitored' => 1, 'value' => array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE), 'limit' => $elements); $hide_unknown = CProfile::get('web.events.filter.hide_unknown', 0); if ($hide_unknown) { $options['value'] = array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE); } $item = new CTableInfo(S_NO_EVENTS_FOUND); $item->SetHeader(array(S_TIME, is_show_all_nodes() ? S_NODE : null, S_HOST, S_DESCRIPTION, S_VALUE, S_SEVERITY)); $events = getLastEvents($options); foreach ($events as $enum => $event) { $trigger = $event['trigger']; $host = $event['host']; $value = new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value'])); // $row = zbx_array_merge($triggers[$row['triggerid']],$row); // if((1 == $hide_unknown) && (!event_initial_time($row,$hide_unknown))) continue; $item->addRow(array(zbx_date2str(S_EVENTS_TRIGGERS_EVENTS_HISTORY_LIST_DATE_FORMAT, $event['clock']), get_node_name_by_elid($event['objectid']), $host['host'], new CLink($trigger['description'], 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']), $value, new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority'])))); } $item = array($item); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { $item = array(SPACE); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } } } } } } } } } } } } } } } } } } } $str_halign = 'def'; if ($halign == HALIGN_CENTER) { $str_halign = 'cntr'; } if ($halign == HALIGN_LEFT) { $str_halign = 'left'; } if ($halign == HALIGN_RIGHT) { $str_halign = 'right'; } $str_valign = 'def'; if ($valign == VALIGN_MIDDLE) { $str_valign = 'mdl'; } if ($valign == VALIGN_TOP) { $str_valign = 'top'; } if ($valign == VALIGN_BOTTOM) { $str_valign = 'bttm'; } if ($editmode == 1 && !$item_form) { $item = new CDiv($item, 'draggable'); $item->setAttribute('id', 'position_' . $r . '_' . $c); if ($editmode == 1) { $item->setAttribute('onclick', 'javascript: ' . $onclick_action); } } $new_col = new CCol($item, $str_halign . '_' . $str_valign); if ($colspan) { $new_col->SetColSpan($colspan); } if ($rowspan) { $new_col->SetRowSpan($rowspan); } array_push($new_cols, $new_col); } if ($editmode == 1) { $rmv_icon = new Cimg('images/general/opened.gif', NULL, NULL, NULL, 'pointer'); if ($empty_screen_row) { $rmv_row_link = "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_row={$r}';"; } else { $rmv_row_link = "javascript: if(Confirm('" . S_THIS_SCREEN_ROW_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_row={$r}';}"; } $rmv_icon->addAction('onclick', $rmv_row_link); array_push($new_cols, new Ccol($rmv_icon)); } $table->addRow(new CRow($new_cols)); } if ($editmode == 1) { $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$row['vsize']}';"); $new_cols = array(new Ccol($add_icon)); for ($c = 0; $c < $row['hsize']; $c++) { $rmv_icon = new Cimg('images/general/opened.gif', NULL, NULL, NULL, 'pointer'); if (isset($empty_screen_col[$c])) { $rmv_col_link = "javascript: if(Confirm('" . S_THIS_SCREEN_COLUMN_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_col={$c}';}"; } else { $rmv_col_link = "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&rmv_col={$c}';"; } $rmv_icon->addAction('onclick', $rmv_col_link); array_push($new_cols, new Ccol($rmv_icon)); } array_push($new_cols, new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); $table->addRow($new_cols); } return $table; }
protected static function inherit($graph, $hostids = null) { $options = array('itemids' => zbx_objectValues($graph['gitems'], 'itemid'), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => 1); $graph_templates = CTemplate::get($options); if (empty($graph_templates)) { return true; } //----- $graphTemplate = reset($graph_templates); $options = array('templateids' => $graphTemplate['templateid'], 'output' => array('hostid', 'host'), 'preservekeys' => 1, 'hostids' => $hostids, 'nopermissions' => 1, 'templated_hosts' => 1); $chd_hosts = CHost::get($options); $options = array('graphids' => $graph['graphid'], 'nopermissions' => 1, 'select_items' => API_OUTPUT_EXTEND, 'select_graph_items' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND); $graph = self::get($options); $graph = reset($graph); foreach ($chd_hosts as $chd_host) { $tmp_graph = $graph; $tmp_graph['templateid'] = $graph['graphid']; if (!($tmp_graph['gitems'] = get_same_graphitems_for_host($tmp_graph['gitems'], $chd_host['hostid']))) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Graph [ ' . $tmp_graph['name'] . ' ]: cannot inherit. No required items on [ ' . $chd_host['host'] . ' ]'); } if ($tmp_graph['ymax_itemid'] > 0) { $ymax_itemid = get_same_graphitems_for_host(array(array('itemid' => $tmp_graph['ymax_itemid'])), $chd_host['hostid']); if (!$ymax_itemid) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Graph [ ' . $tmp_graph['name'] . ' ]: cannot inherit. No required items on [ ' . $chd_host['host'] . ' ] (Ymax value item)'); } $ymax_itemid = reset($ymax_itemid); $tmp_graph['ymax_itemid'] = $ymax_itemid['itemid']; } if ($tmp_graph['ymin_itemid'] > 0) { $ymin_itemid = get_same_graphitems_for_host(array(array('itemid' => $tmp_graph['ymin_itemid'])), $chd_host['hostid']); if (!$ymin_itemid) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Graph [ ' . $tmp_graph['name'] . ' ]: cannot inherit. No required items on [ ' . $chd_host['host'] . ' ] (Ymin value item)'); } $ymin_itemid = reset($ymin_itemid); $tmp_graph['ymin_itemid'] = $ymin_itemid['itemid']; } // check if templated graph exists $chd_graph = self::get(array('filter' => array('templateid' => $tmp_graph['graphid']), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'hostids' => $chd_host['hostid'])); if ($chd_graph = reset($chd_graph)) { if (zbx_strtolower($tmp_graph['name']) != zbx_strtolower($chd_graph['name']) && self::exists(array('name' => $tmp_graph['name'], 'hostids' => $chd_host['hostid']))) { self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host'])); } $tmp_graph['graphid'] = $chd_graph['graphid']; self::updateReal($tmp_graph); } else { $options = array('filter' => array('name' => $tmp_graph['name']), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'nopermissions' => 1, 'hostids' => $chd_host['hostid']); $chd_graph = self::get($options); if ($chd_graph = reset($chd_graph)) { if ($chd_graph['templateid'] != 0) { self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host']) . SPACE . S_INHERITED_FROM_ANOTHER_TEMPLATE); } $options = array('graphids' => $chd_graph['graphid'], 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'expandData' => 1, 'nopermissions' => 1); $chd_graph_items = CGraphItem::get($options); if (count($chd_graph_items) == count($tmp_graph['gitems'])) { foreach ($tmp_graph['gitems'] as $gitem) { foreach ($chd_graph_items as $chd_item) { if ($gitem['key_'] == $chd_item['key_'] && bccomp($chd_host['hostid'], $chd_item['hostid']) == 0) { continue 2; } } self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host']) . SPACE . S_ITEMS_ARE_NOT_IDENTICAL); } $tmp_graph['graphid'] = $chd_graph['graphid']; self::updateReal($tmp_graph); } else { self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host']) . SPACE . S_ITEMS_ARE_NOT_IDENTICAL); } } else { $graphid = self::createReal($tmp_graph); $tmp_graph['graphid'] = $graphid; } } self::inherit($tmp_graph); } }
function get_screen($screenid, $editmode, $effectiveperiod = NULL) { global $USER_DETAILS; if ($screenid == 0) { return new CTableInfo(S_NO_SCREENS_DEFINED); } if (!screen_accessible($screenid, $editmode == 1 ? PERM_READ_WRITE : PERM_READ_ONLY)) { access_deny(); } if (is_null($effectiveperiod)) { $effectiveperiod = ZBX_MIN_PERIOD; } $result = DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid=' . $screenid); $row = DBfetch($result); if (!$row) { return new CTableInfo(S_NO_SCREENS_DEFINED); } for ($r = 0; $r < $row['vsize']; $r++) { for ($c = 0; $c < $row['hsize']; $c++) { if (isset($skip_field[$r][$c])) { continue; } $sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid . ' AND x=' . $c . ' AND y=' . $r; $iresult = DBSelect($sql); $irow = DBfetch($iresult); if ($irow) { $colspan = $irow['colspan']; $rowspan = $irow['rowspan']; } else { $colspan = 0; $rowspan = 0; } for ($i = 0; $i < $rowspan || $i == 0; $i++) { for ($j = 0; $j < $colspan || $j == 0; $j++) { if ($i != 0 || $j != 0) { $skip_field[$r + $i][$c + $j] = 1; } } } } } $table = new CTable(new CLink('No rows in screen ' . $row['name'], 'screenconf.php?config=0&form=update&screenid=' . $screenid), $editmode == 0 || $editmode == 2 ? 'screen_view' : 'screen_edit'); $table->setAttribute('id', 'iframe'); if ($editmode == 1) { $add_col_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_col='; $new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); for ($c = 0; $c < $row['hsize'] + 1; $c++) { array_push($new_cols, new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_col_link . $c))); } $table->addRow($new_cols); } $empty_screen_col = array(); for ($r = 0; $r < $row['vsize']; $r++) { $new_cols = array(); $empty_screen_row = true; if ($editmode == 1) { $add_row_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_row='; array_push($new_cols, new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_row_link . $r))); } for ($c = 0; $c < $row['hsize']; $c++) { $item = array(); if (isset($skip_field[$r][$c])) { continue; } $item_form = false; $iresult = DBSelect('SELECT * FROM screens_items WHERE screenid=' . $screenid . ' AND x=' . $c . ' AND y=' . $r); $irow = DBfetch($iresult); if ($irow) { $screenitemid = $irow['screenitemid']; $resourcetype = $irow['resourcetype']; $resourceid = $irow['resourceid']; $width = $irow['width']; $height = $irow['height']; $colspan = $irow['colspan']; $rowspan = $irow['rowspan']; $elements = $irow['elements']; $valign = $irow['valign']; $halign = $irow['halign']; $style = $irow['style']; $url = $irow['url']; $dynamic = $irow['dynamic']; } else { $screenitemid = 0; $resourcetype = 0; $resourceid = 0; $width = 0; $height = 0; $colspan = 0; $rowspan = 0; $elements = 0; $valign = VALIGN_DEFAULT; $halign = HALIGN_DEFAULT; $style = 0; $url = ''; $dynamic = 0; } if ($screenitemid > 0) { $empty_screen_row = false; $empty_screen_col[$c] = 1; } if ($editmode == 1 && $screenitemid != 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&screenitemid=' . $screenitemid . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitemid . '#form'; } else { if ($editmode == 1 && $screenitemid == 0) { $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&x=' . $c . '&y=' . $r . "#form');"; $action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r . '#form'; } else { $action = NULL; } } if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['x']) && $_REQUEST['x'] == $c && isset($_REQUEST['y']) && $_REQUEST['y'] == $r) { // click on empty field $item = get_screen_item_form(); $item_form = true; } else { if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['screenitemid']) && bccomp($_REQUEST['screenitemid'], $screenitemid) == 0) { // click on element $item = get_screen_item_form(); $item_form = true; } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_GRAPH) { if ($editmode == 0) { $action = 'charts.php?graphid=' . $resourceid . url_param('period') . url_param('stime'); } $graphid = null; $graphtype = GRAPH_TYPE_NORMAL; $yaxis = 0; // GRAPH & ZOOM features $sql = 'SELECT MAX(g.graphid) as graphid, MAX(g.graphtype) as graphtype, MIN(gi.yaxisside) as yaxissidel, MAX(gi.yaxisside) as yaxissider,' . ' MAX(g.show_legend) as legend, MAX(g.show_3d) as show3d ' . ' FROM graphs g, graphs_items gi ' . ' WHERE g.graphid=' . $resourceid . ' AND gi.graphid=g.graphid '; $res = DBselect($sql); while ($graph = DBfetch($res)) { $graphid = $graph['graphid']; $graphtype = $graph['graphtype']; $yaxis = $graph['yaxissider']; $yaxis = $graph['yaxissidel'] == $yaxis ? $yaxis : 2; $legend = $graph['legend']; $graph3d = $graph['show3d']; } if ($yaxis == 2) { $shiftXleft = 60; $shiftXright = 60; } else { if ($yaxis == 0) { $shiftXleft = 60; $shiftXright = 20; } else { $shiftXleft = 10; $shiftXright = 60; } } //------------- // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { $def_items = array(); $di_res = get_graphitems_by_graphid($resourceid); while ($gitem = DBfetch($di_res)) { $def_items[] = $gitem; } $url = ''; if ($new_items = get_same_graphitems_for_host($def_items, $_REQUEST['hostid'])) { $url .= make_url_from_gitems($new_items); } $url = make_url_from_graphid($resourceid, false) . $url; } //------------- $default = false; if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart6.php?graphid=' . $resourceid; $default = true; } $g_img = new CImg($url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime') . '&legend=' . $legend . '&graph3d=' . $graph3d); } else { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart2.php?graphid=' . $resourceid; $default = true; } $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $g_img = new CImg($url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime')); $g_img->setAttribute('id', $dom_graph_id); if (!is_null($graphid) && $editmode != 1) { insert_js(' A_SBOX["' . $dom_graph_id . '"] = new Object;' . 'A_SBOX["' . $dom_graph_id . '"].shiftT = 17;' . 'A_SBOX["' . $dom_graph_id . '"].shiftL = ' . $shiftXleft . ';'); if (isset($_REQUEST['stime'])) { $stime = $_REQUEST['stime']; $stime = mktime(substr($stime, 8, 2), substr($stime, 10, 2), 0, substr($stime, 4, 2), substr($stime, 6, 2), substr($stime, 0, 4)); } else { $stime = 'null'; } global $page; if ($page['type'] == PAGE_TYPE_HTML) { zbx_add_post_js('graph_zoom_init("' . $dom_graph_id . '",' . $stime . ',' . $effectiveperiod . ',' . $width . ',' . $height . ', false);'); } else { $g_img->setAttribute('onload', 'javascript: graph_zoom_init("' . $dom_graph_id . '",' . $stime . ',' . $effectiveperiod . ',' . $width . ',' . $height . ', false);'); // insert_js('graph_zoom_init("'.$dom_graph_id.'",'.$stime.','.$effectiveperiod.','.$width.','.$height.', false);'); } } } if ($default && $editmode == 0) { $item = new CLink($g_img, $action); } else { $item =& $g_img; } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) { if ($editmode == 0) { $action = "history.php?action=showgraph&itemid={$resourceid}" . url_param("period") . url_param("inc") . url_param("dec"); } // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = ''; } } //------------- $url = empty($resourceid) ? 'chart3.php?' : "chart.php?itemid={$resourceid}&"; $item = new CLink(new CImg($url . "width={$width}&height={$height}" . "&period={$effectiveperiod}" . url_param("stime")), $action); } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_MAP) { $image_map = new CImg("map.php?noedit=1&sysmapid={$resourceid}" . "&width={$width}&height={$height}"); if ($editmode == 0) { $action_map = get_action_map_by_sysmapid($resourceid); $image_map->SetMap($action_map->GetName()); $item = array($action_map, $image_map); } else { $item = $image_map; // $item = new CLink($image_map, $action); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) { // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) { $resourceid = $newitemid; } else { $resourceid = 0; } } //------------- $item = array(get_screen_plaintext($resourceid, $elements, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_STATUS_OF_TRIGGERS) { $params = array(); $params['groupid'] = get_request('tr_groupid', get_profile('web.screens.tr_groupid', 0)); $params['hostid'] = get_request('tr_hostid', get_profile('web.screens.tr_hostid', 0)); $params['limit'] = $elements; update_profile('web.screens.tr_groupid', $params['groupid'], PROFILE_TYPE_ID); update_profile('web.screens.tr_hostid', $params['hostid'], PROFILE_TYPE_ID); $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $params['groupid'], 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $params['hostid'], 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY); $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY); $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY); $sql = 'SELECT DISTINCT g.groupid,g.name ' . ' FROM groups g, hosts_groups hg, hosts h ' . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND hg.groupid=g.groupid ' . ' AND h.hostid=hg.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND EXISTS(SELECT i.itemid FROM items i WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND i.hostid=h.hostid ) ' . ' ORDER BY g.name'; $tresult = DBselect($sql); while ($tr_row = DBfetch($tresult)) { $cmbGroup->addItem($tr_row['groupid'], get_node_name_by_elid($tr_row['groupid']) . $tr_row['name']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $sql_from = ''; $sql_where = ''; if ($params['groupid'] > 0) { $sql_from .= ',hosts_groups hg '; $sql_where .= ' AND hg.hostid=h.hostid AND hg.groupid=' . $params['groupid']; } $sql = 'SELECT DISTINCT h.hostid,h.host ' . ' FROM hosts h, items i, functions f, triggers t ' . $sql_from . ' WHERE h.status=' . HOST_STATUS_MONITORED . $sql_where . ' AND h.hostid=i.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' ORDER BY h.host'; $tresult = DBselect($sql); while ($tr_row = DBfetch($tresult)) { $cmbHosts->addItem($tr_row['hostid'], get_node_name_by_elid($tr_row['hostid']) . $tr_row['host']); } $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, date('[H:i:s]', time())), $tr_form)); //*/ // $item = array(); $item[] = make_latest_issues($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SYSTEM_STATUS) { $item = array(get_table_header(array(S_SYSTEM_STATUSBIG, SPACE, date('[H:i:s]', time())))); $item[] = make_system_summary(); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTS_INFO) { $item = array(new CHostsInfo($resourceid, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) { $item = new CTriggersInfo($style); if ($resourceid > 0) { $item->set_host_group($resourceid); } $item = array($item); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SERVER_INFO) { // $item = array(get_table_header(S_STATUS_OF_ZABBIX_BIG),make_status_of_zbx()); $item = array(new CServerInfo()); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_CLOCK) { $item = new CFlashClock($width, $height, $style, $action); } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SCREEN) { $item = array(get_screen($resourceid, 2, $effectiveperiod)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_triggers_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_DATA_OVERVIEW) { $hostids = array(); $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid); while ($tmp_host = DBfetch($res)) { $hostids[$tmp_host['hostid']] = $tmp_host['hostid']; } $item = array(get_items_data_overview($hostids, $style)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_URL) { $item = array(new CIFrame($url, $width, $height, "auto")); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_ACTIONS) { $item = array(get_history_of_actions($elements)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_EVENTS) { $item = array(get_history_of_triggers_events(0, $elements)); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } } else { $item = array(SPACE); if ($editmode == 1) { array_push($item, BR(), new CLink(S_CHANGE, $action)); } } } } } } } } } } } } } } } } } } } $str_halign = 'def'; if ($halign == HALIGN_CENTER) { $str_halign = 'cntr'; } if ($halign == HALIGN_LEFT) { $str_halign = 'left'; } if ($halign == HALIGN_RIGHT) { $str_halign = 'right'; } $str_valign = 'def'; if ($valign == VALIGN_MIDDLE) { $str_valign = 'mdl'; } if ($valign == VALIGN_TOP) { $str_valign = 'top'; } if ($valign == VALIGN_BOTTOM) { $str_valign = 'bttm'; } if ($editmode == 1 && !$item_form) { $item = new CDiv($item, 'draggable'); $item->setAttribute('id', 'position_' . $r . '_' . $c); if ($editmode == 1) { $item->setAttribute('onclick', 'javascript: ' . $onclick_action); } } $new_col = new CCol($item, $str_halign . '_' . $str_valign); if ($colspan) { $new_col->SetColSpan($colspan); } if ($rowspan) { $new_col->SetRowSpan($rowspan); } array_push($new_cols, $new_col); } if ($editmode == 1) { $rmv_icon = new Cimg('images/general/opened.gif'); if ($empty_screen_row) { $rmv_row_link = 'javascript: location.href = ' . "'screenedit.php?config=1&screenid=" . $screenid . '&rmv_row=' . $r . "';"; } else { $rmv_row_link = "javascript: if(Confirm('This screen-row is not empty. Delete it?')){" . " location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_row=" . $r . "';}"; } $rmv_icon->addAction('onclick', $rmv_row_link); array_push($new_cols, new Ccol($rmv_icon)); } $table->AddRow(new CRow($new_cols)); } if ($editmode == 1) { $add_row_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_row='; $new_cols = array(new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_row_link . $row['vsize']))); for ($c = 0; $c < $row['hsize']; $c++) { $rmv_icon = new Cimg('images/general/opened.gif'); if (isset($empty_screen_col[$c])) { $rmv_col_link = "javascript: if(Confirm('This screen-column is not empty. Delete it?')){" . " location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_col=" . $c . "';}"; } else { $rmv_col_link = "javascript: location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_col=" . $c . "';"; } $rmv_icon->addAction('onclick', $rmv_col_link); array_push($new_cols, new Ccol($rmv_icon)); } array_push($new_cols, new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); $table->addRow($new_cols); } return $table; }