public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null, $type = null, $periods_cnt = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     $item = get_item_by_itemid($itemid);
     $this->items[$this->num] = $item;
     $this->items[$this->num]['description'] = item_description($item);
     $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
     if (strpos($item['units'], ',') !== false) {
         list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']);
     } else {
         $this->items[$this->num]['unitsLong'] = '';
     }
     $host = get_host_by_hostid($item['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     $this->items[$this->num]['periods_cnt'] = is_null($periods_cnt) ? 0 : $periods_cnt;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     $this->num++;
 }
Example #2
0
 public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($itemid)));
     $item = reset($items);
     $item['name'] = $item['name_expanded'];
     $this->items[$this->num] = $item;
     $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
     if (strpos($item['units'], ',') === false) {
         $this->items[$this->num]['unitsLong'] = '';
     } else {
         list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']);
     }
     $host = get_host_by_hostid($item['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['hostname'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = GRAPH_ITEM_SIMPLE;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     $this->num++;
 }
Example #3
0
 public function getItemListFormat($list = array())
 {
     $itemList = $list['list_item'];
     $parame = $list['parame'];
     $search_key = $parame['item_name_search'];
     $order_result_list = array();
     $search = 0;
     if (empty($search_key)) {
         $search_key_list = array();
     } else {
         $search_key_list = explode(",", $search_key);
     }
     if (count($search_key_list) >= 1) {
         $search = 1;
     }
     foreach ($itemList as $each_item) {
         $each_item = (array) $each_item;
         $item = get_item_by_itemid($each_item['itemid']);
         $newItem = $item;
         // $newItem['name'] = itemName($item);
         $newItem['name'] = $item['name'];
         $newItem['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
         $host = get_host_by_hostid($item['hostid']);
         $newItem['hostname'] = $host['name'];
         if (strpos($item['units'], ',') !== false) {
             list($newItem['units'], $newItem['unitsLong']) = explode(',', $item['units']);
         } else {
             $newItem['unitsLong'] = '';
         }
         if ($search == 0) {
             $newItem['graphid'] = $each_item['graphid'];
             $order_result_list[$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => 0, 'min' => 0, 'avg' => 0, 'max' => 0, 'hostname' => $newItem['hostname'], 'chazhi' => 0);
         } else {
             foreach ($search_key_list as $each_search_key) {
                 $each_search_key = trim($each_search_key);
                 //按关键字进行筛选
                 if (strpos(strtolower($newItem['name']), strtolower($each_search_key)) === false) {
                     //echo "bupipei<br>";
                 } else {
                     $newItem['calc_fnc'] = is_null($each_item['calc_fnc']) ? CALC_FNC_AVG : $each_item->calc_fnc;
                     $newItem['calc_type'] = GRAPH_ITEM_SIMPLE;
                     $newItem['graphid'] = $each_item['graphid'];
                     $item_info_new = array_merge($newItem, $parame);
                     $data = self::GetItemValues($item_info_new);
                     if (isset($data) && isset($data['min'])) {
                         $lastvalue = convert_units(self::getLastValueBy($data), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $min = convert_units(min($data['min']), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $avg = convert_units($data['avg_orig'], $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         $max = convert_units(max($data['max']), $newItem['units'], ITEM_CONVERT_NO_UNITS);
                         //return array("lastvalue"=>$lastvalue,'min'=>$min,'avg'=>$avg,'max'=>$max);
                         $order_result_list[$each_search_key][$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => self::getLastValueBy($data), 'min' => min($data['min']), 'avg' => $data['avg_orig'], 'max' => max($data['max']), 'hostname' => $newItem['hostname'], 'chazhi' => max($data['max']) - min($data['min']));
                     } else {
                         $order_result_list[$each_search_key][$newItem['graphid']] = array("graphid" => $newItem['graphid'], "itemname" => $newItem['name'], "lastvalue" => 0, 'min' => 0, 'avg' => 0, 'max' => 0, 'hostname' => $newItem['hostname'], 'chazhi' => 0);
                     }
                     break;
                 }
             }
         }
     }
     return $order_result_list;
 }
Example #4
0
 public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null, $type = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     // TODO: graphs shouldn't retrieve items and resolve macros themselves
     // all of the data must be passed as parameters
     $items = CMacrosResolverHelper::resolveItemNames([get_item_by_itemid($itemid)]);
     $item = reset($items);
     $item['name'] = $item['name_expanded'];
     $this->items[$this->num] = $item;
     $parser = new CItemDelayFlexParser($item['delay_flex']);
     $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $parser->getFlexibleIntervals());
     $this->items[$this->num]['intervals'] = $parser->getIntervals();
     if (strpos($item['units'], ',') === false) {
         $this->items[$this->num]['unitsLong'] = '';
     } else {
         list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']);
     }
     $host = get_host_by_hostid($item['hostid']);
     $this->items[$this->num]['host'] = $host['host'];
     $this->items[$this->num]['hostname'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     $this->num++;
 }