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);
     }
 }
Esempio n. 2
0
         $items_list = API::GraphItem()->get(array("graphids" => $graphids, "output" => "extend"));
     }
 } else {
     //查询分组里面的所有机器
     $host_ids = array();
     $hosts = API::Host()->get(array("output" => "extend", "monitored_hosts" => true, "with_monitored_items" => 1, "groupids" => array($group_class)));
     foreach ($hosts as $each_host) {
         $host_ids[] = $each_host['hostid'];
     }
     //查询分组下的所有机器的所有图形
     $graphs = API::Graph()->get(array("hostids" => $host_ids, "output" => "extend", "sortfield" => "name"));
     foreach ($graphs as &$each) {
         $graphids[] = $each['graphid'];
     }
     if (!is_null($graphids)) {
         $items_list = API::GraphItem()->get(array("graphids" => $graphids, "output" => "extend"));
     }
 }
 $list = array('list_item' => $items_list, 'parame' => array('stime' => strtotime($stime), 'period' => $period, 'sizeX' => $width, 'item_name_search' => $itemkey));
 $format_list = API::ItemValue()->getItemListFormat($list);
 $format_list = (array) $format_list;
 foreach ($format_list as &$format) {
     $format = (array) $format;
     if (is_array($format)) {
         foreach ($format as $key_obj => &$value_obj) {
             if (is_object($value_obj)) {
                 $value_obj = (array) $value_obj;
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * Returns output for preview of graph prototype.
  *
  * @return CTag
  */
 protected function getPreviewOutput()
 {
     $graphPrototype = $this->getGraphPrototype();
     switch ($graphPrototype['graphtype']) {
         case GRAPH_TYPE_NORMAL:
         case GRAPH_TYPE_STACKED:
             $url = 'chart3.php';
             break;
         case GRAPH_TYPE_EXPLODED:
         case GRAPH_TYPE_3D_EXPLODED:
         case GRAPH_TYPE_3D:
         case GRAPH_TYPE_PIE:
             $url = 'chart7.php';
             break;
         default:
             show_error_message(_('Graph prototype not found.'));
             exit;
     }
     $graphPrototypeItems = API::GraphItem()->get(['output' => ['gitemid', 'itemid', 'sortorder', 'flags', 'type', 'calc_fnc', 'drawtype', 'yaxisside', 'color'], 'graphids' => [$graphPrototype['graphid']]]);
     $queryParams = ['items' => $graphPrototypeItems, 'graphtype' => $graphPrototype['graphtype'], 'period' => 3600, 'legend' => $graphPrototype['show_legend'], 'graph3d' => $graphPrototype['show_3d'], 'width' => $this->screenitem['width'], 'height' => $this->screenitem['height'], 'name' => $graphPrototype['name']];
     $url .= '?' . http_build_query($queryParams);
     return new CSpan(new CImg($url));
 }
Esempio n. 4
0
             } else {
                 $parentTemplate = get_hosts_by_graphid($parentGraph['graphid']);
                 $parentTemplate = DBfetch($parentTemplate);
                 $link = new CLink($parentTemplate['name'], 'graphs.php?form=update&graphid=' . $parentGraph['graphid'] . '&hostid=' . $parentTemplate['hostid']);
             }
             if (isset($link)) {
                 $data['templates'][] = $link;
                 $data['templates'][] = SPACE . RARR . SPACE;
             }
             $parentGraphid = $parentGraph['templateid'];
         } while ($parentGraphid != 0);
         $data['templates'] = array_reverse($data['templates']);
         array_shift($data['templates']);
     }
     // items
     $data['items'] = API::GraphItem()->get(array('output' => array('gitemid', 'graphid', 'itemid', 'type', 'drawtype', 'yaxisside', 'calc_fnc', 'color', 'sortorder'), 'graphids' => $data['graphid'], 'sortfield' => 'gitemid'));
 } else {
     $data['name'] = get_request('name', '');
     $data['graphtype'] = get_request('graphtype', GRAPH_TYPE_NORMAL);
     if ($data['graphtype'] == GRAPH_TYPE_PIE || $data['graphtype'] == GRAPH_TYPE_EXPLODED) {
         $data['width'] = get_request('width', 400);
         $data['height'] = get_request('height', 300);
     } else {
         $data['width'] = get_request('width', 900);
         $data['height'] = get_request('height', 200);
     }
     $data['ymin_type'] = get_request('ymin_type', GRAPH_YAXIS_TYPE_CALCULATED);
     $data['ymax_type'] = get_request('ymax_type', GRAPH_YAXIS_TYPE_CALCULATED);
     $data['yaxismin'] = get_request('yaxismin', 0);
     $data['yaxismax'] = get_request('yaxismax', 100);
     $data['ymin_itemid'] = get_request('ymin_itemid', 0);
Esempio n. 5
0
             } else {
                 $parentTemplate = get_hosts_by_graphid($parentGraph['graphid']);
                 $parentTemplate = DBfetch($parentTemplate);
                 $link = new CLink($parentTemplate['name'], 'graphs.php?form=update&graphid=' . $parentGraph['graphid'] . '&hostid=' . $parentTemplate['hostid']);
             }
             if (isset($link)) {
                 $data['templates'][] = $link;
                 $data['templates'][] = SPACE . RARR . SPACE;
             }
             $parentGraphid = $parentGraph['templateid'];
         } while ($parentGraphid != 0);
         $data['templates'] = array_reverse($data['templates']);
         array_shift($data['templates']);
     }
     // items
     $data['items'] = API::GraphItem()->get(array('graphids' => $data['graphid'], 'sortfield' => 'gitemid', 'output' => API_OUTPUT_EXTEND, 'expandData' => true));
 } else {
     $data['name'] = get_request('name', '');
     $data['graphtype'] = get_request('graphtype', GRAPH_TYPE_NORMAL);
     if ($data['graphtype'] == GRAPH_TYPE_PIE || $data['graphtype'] == GRAPH_TYPE_EXPLODED) {
         $data['width'] = get_request('width', 400);
         $data['height'] = get_request('height', 300);
     } else {
         $data['width'] = get_request('width', 900);
         $data['height'] = get_request('height', 200);
     }
     $data['ymin_type'] = get_request('ymin_type', GRAPH_YAXIS_TYPE_CALCULATED);
     $data['ymax_type'] = get_request('ymax_type', GRAPH_YAXIS_TYPE_CALCULATED);
     $data['yaxismin'] = get_request('yaxismin', '0.00');
     $data['yaxismax'] = get_request('yaxismax', '100.00');
     $data['ymin_itemid'] = get_request('ymin_itemid', 0);
Esempio n. 6
0
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $graphids = array_keys($result);
     // adding GraphItems
     if ($options['selectGraphItems'] !== null && $options['selectGraphItems'] !== API_OUTPUT_COUNT) {
         $gitems = API::GraphItem()->get(array('nodeids' => $options['nodeids'], 'output' => $this->outputExtend('graphs_items', array('graphid', 'gitemid'), $options['selectGraphItems']), 'graphids' => $graphids, 'nopermissions' => true, 'preservekeys' => true));
         $relationMap = $this->createRelationMap($gitems, 'graphid', 'gitemid');
         $gitems = $this->unsetExtraFields($gitems, array('graphid', 'gitemid'), $options['selectGraphItems']);
         $result = $relationMap->mapMany($result, $gitems, 'gitems');
     }
     // adding HostGroups
     if ($options['selectGroups'] !== null && $options['selectGroups'] !== API_OUTPUT_COUNT) {
         $relationMap = new CRelationMap();
         // discovered items
         $dbRules = DBselect('SELECT gi.graphid,hg.groupid' . ' FROM graphs_items gi,items i,hosts_groups hg' . ' WHERE ' . dbConditionInt('gi.graphid', $graphids) . ' AND gi.itemid=i.itemid' . ' AND i.hostid=hg.hostid');
         while ($relation = DBfetch($dbRules)) {
             $relationMap->addRelation($relation['graphid'], $relation['groupid']);
         }
         $groups = API::HostGroup()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectGroups'], 'groupids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $groups, 'groups');
     }
     // adding Hosts
     if ($options['selectHosts'] !== null && $options['selectHosts'] !== API_OUTPUT_COUNT) {
         $relationMap = new CRelationMap();
         // discovered items
         $dbRules = DBselect('SELECT gi.graphid,i.hostid' . ' FROM graphs_items gi,items i' . ' WHERE ' . dbConditionInt('gi.graphid', $graphids) . ' AND gi.itemid=i.itemid');
         while ($relation = DBfetch($dbRules)) {
             $relationMap->addRelation($relation['graphid'], $relation['hostid']);
         }
         $hosts = API::Host()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectHosts'], 'hostids' => $relationMap->getRelatedIds(), 'templated_hosts' => true, 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $hosts, 'hosts');
     }
     // adding Templates
     if ($options['selectTemplates'] !== null && $options['selectTemplates'] !== API_OUTPUT_COUNT) {
         $relationMap = new CRelationMap();
         // discovered items
         $dbRules = DBselect('SELECT gi.graphid,i.hostid' . ' FROM graphs_items gi,items i' . ' WHERE ' . dbConditionInt('gi.graphid', $graphids) . ' AND gi.itemid=i.itemid');
         while ($relation = DBfetch($dbRules)) {
             $relationMap->addRelation($relation['graphid'], $relation['hostid']);
         }
         $templates = API::Template()->get(array('nodeids' => $options['nodeids'], 'output' => $options['selectTemplates'], 'templateids' => $relationMap->getRelatedIds(), 'nopermissions' => true, 'preservekeys' => true));
         $result = $relationMap->mapMany($result, $templates, 'templates');
     }
     return $result;
 }