protected static function getItemValue($hostname, $categoryId, $item, $param) { if (isset($item["VALUE"])) { return $item["VALUE"]; } if (isset($item["VALUE_FUNC"])) { return call_user_func_array($item["VALUE_FUNC"], isset($item["FUNC_PARAMS"]) ? $item["FUNC_PARAMS"] : array()); } if ((!$item["RRD"] || !$item["CF"]) && !$item["OPTIONS"]) { throw new \Exception("Monitoring param item in category " . $categoryId . " has no RRD or CF fields."); } if (isset($item["RRD"])) { $rrdFile = str_replace('##HOSTNAME##', $hostname, $item["RRD"]); $rrdPath = static::$rrdPath . "/" . $hostname . "/" . $rrdFile; $file = new \Bitrix\Main\IO\File($rrdPath); if (!$file->isExists()) { throw new \Bitrix\Main\IO\FileNotFoundException($rrdPath); } $first = \rrd_first($rrdPath); $last = \rrd_last($rrdPath); } if (isset($item["OPTIONS"])) { $arOpts = $item["OPTIONS"]; $arOpts = str_replace('##HOSTNAME##', $hostname, $arOpts); } else { if ($item["CF"] == "MIN") { $agr = "MINIMUM"; } elseif ($item["CF"] == "MAX") { $agr = "MAXIMUM"; } else { $agr = $item["CF"]; } if ($item["CF"] == "LAST") { $item["CF"] = "AVERAGE"; } $format = isset($item["FORMAT"]) ? $item["FORMAT"] : "%6.2lf"; $arOpts = array("DEF:val=" . $rrdPath . ":42:" . $item["CF"], "VDEF:vval=val," . $agr, "PRINT:vval:" . $format); } if (isset($item["RRD"])) { $arOpts[] = "--start"; $arOpts[] = $first; $arOpts[] = "--end"; $arOpts[] = $last; } $data = \rrd_graph("/dev/null", $arOpts); if (isset($item["DATA_FUNC"])) { $func = create_function('$data', $item["DATA_FUNC"]); if (is_callable($func)) { $result = $func($data); } } else { if (isset($data["calcpr"])) { $data["data"] = $data["calcpr"]; } $result = static::extractRrdValue($data); } return $result; }
function GetGroupInfo(LOGGROUP $grp = NULL, $flags = 0) { $groups = array(); //array for the groups to be returned if ($this->munin_datafile) { foreach ($this->groups as $gid => &$group) { if ($grp && strcmp($grp->gid, $gid)) { continue; } //if a group is specified and existing group has same group id then skip this group if ($group['name']) { $name = $group['name']; } else { $name = false; } //else name = false if (!$name || $flags & REQUEST::NEED_INFO) { //if there was no name and there's a NEED_INFO flag if ($grp) { //if group is specified $grtest = $grp; $opts = $this->opts; } else { //no group is specified (easier to just throw error here since there can't really be a default .rrd-file)? $ginfo = array("db_group" => $gid); //create new groupinfo array $grtest = $this->CreateGroup($ginfo); //create new group $opts = $this->req->GetGroupOptions($grtest); //create new options for group } if (!$name) { //if name = false $name = $opts->Get('name', $gid); //get name from options, if there's no name use group id } } $groups[$gid] = array('gid' => $gid, 'name' => $name); if ($flags & REQUEST::NEED_INFO) { $tmp_group = new LOGGROUP($tmp_groupid = array("db_group" => $gid)); $items = $this::GetItemList($tmp_group); //change to getitemlist $rrd_fetch_opts = array("AVERAGE"); $min = false; $max = false; foreach ($items as $item) { $rrd_file = $this::GidToFilename($item['db_uid'], $this); if ($min === false) { $min = rrd_first($rrd_file); $max = rrd_last($rrd_file); } else { $first = rrd_first($rrd_file); if ($min > $first) { $min = $first; } $last = rrd_last($rrd_file); if ($max < $last) { $max = $last; } } } $groups[$gid]['first'] = $min; $groups[$gid]['last'] = $max; if ($flags & REQUEST::NEED_COUNT) { //if there's a NEED_COUNT flag $fetch = rrd_info($file); $record_num = ($groups[$gid]['last'] - $groups[$gid]['first']) / $fetch['step']; //calculate number of records $groups[$gid]['records'] = $record_num; } if ($flags & REQUEST::NEED_ITEMINFO) { //if there's a NEED_ITEMINFO flag $groups[$gid]['items'] = $this->GetItemList($grp); //get itemlist for specified group } } } //went through existing groups } else { if (!$this->groups) { return false; } foreach ($this->groups as $gid => &$group) { if ($grp && strcmp($grp->gid, $gid)) { continue; } //if a group is specified and existing group has same group id then skip this group if ($group['name']) { $name = $group['name']; } else { $name = false; } //else name = false if (!$name || $flags & REQUEST::NEED_INFO) { //if there was no name and there's a NEED_INFO flag if ($grp) { //if group is specified $grtest = $grp; $opts = $this->opts; } else { //no group is specified (easier to just throw error here since there can't really be a default .rrd-file)? $ginfo = array("db_group" => $gid); //create new groupinfo array $grtest = $this->CreateGroup($ginfo); //create new group $opts = $this->req->GetGroupOptions($grtest); //create new options for group } if (!$name) { //if name = false $name = $opts->Get('name', $gid); //get name from options, if there's no name use group id } } $groups[$gid] = array('gid' => $gid, 'name' => $name); if ($flags & REQUEST::NEED_COUNT) { $rrd_fetch_opts = array("AVERAGE"); $fetch = $this::Fetch($gid, $rrd_fetch_opts); $record_num = ($fetch['end'] - $fetch['start']) / $fetch['step']; $groups[$gid]['records'] = $record_num; } if ($flags & REQUEST::NEED_INFO) { //if there's a NEED_INFO flag $rrd_fetch_opts = array("AVERAGE"); $fetch = $this::Fetch($gid, $rrd_fetch_opts); $groups[$gid]['first'] = $fetch['start']; $groups[$gid]['last'] = $fetch['end']; if ($flags & REQUEST::NEED_COUNT) { //if there's a NEED_COUNT flag $record_num = ($fetch['end'] - $fetch['start']) / $fetch['step']; //calculate number of records $groups[$gid]['records'] = $record_num; } if ($flags & REQUEST::NEED_ITEMINFO) { //if there's a NEED_ITEMINFO flag $groups[$gid]['items'] = $this->GetItemList($grtest); //get itemlist for specified group } } } //went through existing groups } if ($grp && !$groups) { //if group is specified and there are no defined groups throw new ADEIException(translate("Invalid group (%s) is specified", $grp->gid)); } return $grp ? $groups[$grp->gid] : $groups; //if group was specified, return group in groups table at index group id, else return groups table }