/** * @param string $targetString The string from the config file * @param the $map A reference to the map object (redundant) * @param the $mapItem A reference to the object this target is attached to * @return array invalue, outvalue, unix timestamp that the data was valid */ function ReadData($targetString, &$map, &$mapItem) { $data[IN] = null; $data[OUT] = null; $data_time = 0; $matches = 0; if (preg_match("/^time:(.*)\$/", $targetString, $matches)) { $timezone = $matches[1]; $offset = "now"; if (preg_match("/^([^:]+):(.*)\$/", $timezone, $matches2)) { $timezone = $matches2[1]; $offset = $matches2[2]; // test that the offset is valid $timestamp = strtotime($offset); if ($timestamp === false || $timestamp === -1) { warn("Time ReadData: Offset String ({$offset}) is bogus - ignoring [WMTIME03]\n"); $offset = "now"; } } $timezone_l = strtolower($timezone); if (array_key_exists($timezone_l, $this->timezones)) { $tz = $this->timezones[$timezone_l]; wm_debug("Time ReadData: Timezone exists: {$tz}\n"); $dateTime = new DateTime($offset, new DateTimeZone($tz)); $mapItem->add_note("time_time12", $dateTime->format("h:i")); $mapItem->add_note("time_time12ap", $dateTime->format("h:i A")); $mapItem->add_note("time_time24", $dateTime->format("H:i")); $mapItem->add_note("time_timet", $dateTime->format("U")); $mapItem->add_note("time_timezone", $tz); $data[IN] = $dateTime->format("H"); $data[OUT] = $dateTime->format("i"); $data_time = time(); $matches++; } if ($matches == 0) { wm_warn("Time ReadData: Couldn't recognize {$timezone} as a valid timezone name [WMTIME02]\n"); } } else { // some error code to go in here wm_warn("Time ReadData: Couldn't recognize {$targetString} \n"); } wm_debug("Time ReadData: Returning (" . WMUtility::valueOrNull($data[IN]) . "," . WMUtility::valueOrNull($data[OUT]) . ",{$data_time})\n"); return array($data[IN], $data[OUT], $data_time); }
/** * @param string $targetString The string from the config file * @param the $map A reference to the map object (redundant) * @param the $mapItem A reference to the object this target is attached to * @return array invalue, outvalue, unix timestamp that the data was valid */ function ReadData($targetString, &$map, &$mapItem) { $data[IN] = null; $data[OUT] = null; $data_time = 0; if (preg_match("/^time:(.*)\$/", $targetString, $matches)) { $timezone = $matches[1]; $offset = "now"; if (preg_match("/^([^:]+):(.*)\$/", $timezone, $matches2)) { $timezone = $matches2[1]; $offset = $matches2[2]; // test that the offset is valid $timestamp = strtotime($offset); if ($timestamp === false || $timestamp === -1) { warn("Time ReadData: Offset String ({$offset}) is bogus - ignoring [WMTIME03]\n"); $offset = "now"; } } list($required_time, $timezone_name) = $this->getTimeForTimeZone($timezone, $offset); $data = $this->populateTimeData($mapItem, $required_time, $timezone_name); $data_time = time(); } else { // some error code to go in here wm_warn("Time ReadData: Couldn't recognize {$targetString} \n"); } wm_debug("Time ReadData: Returning (" . WMUtility::valueOrNull($data[IN]) . "," . WMUtility::valueOrNull($data[OUT]) . ",{$data_time})\n"); return array($data[IN], $data[OUT], $data_time); }
/** * @param string $targetString The string from the config file * @param the $map A reference to the map object (redundant) * @param the $mapItem A reference to the object this target is attached to * @return array invalue, outvalue, unix timestamp that the data was valid */ public function ReadData($targetString, &$map, &$mapItem) { $data[IN] = null; $data[OUT] = null; $dataTime = 0; $itemName = $mapItem->name; $fullpath = realpath($targetString); $fileHandle = $this->validateAndOpenFile($fullpath); if ($fileHandle) { $data = $this->readDataFromTSV($fileHandle, $itemName); $stats = stat($fullpath); $dataTime = $stats['mtime']; } else { // some error code to go in here wm_warn("TabText ReadData: Couldn't open ({$fullpath}). [WMTABDATA01]\n"); } wm_debug("TabText ReadData: Returning (" . WMUtility::valueOrNull($data[IN]) . "," . WMUtility::valueOrNull($data[OUT]) . ",{$dataTime})\n"); return array($data[IN], $data[OUT], $dataTime); }
function ReadData($targetString, &$map, &$mapItem) { $data[IN] = null; $data[OUT] = null; $data_time = 0; $ping_count = intval($map->get_hint("fping_ping_count")); if ($ping_count == 0) { $ping_count = 5; } $target = $this->extractTargetHost($targetString); if ($target == "") { wm_warn("FPing ReadData: No target? [WMFPING05]\n"); return array(null, null, 0); } $pattern = $this->buildMatchPattern($target, $ping_count); $pipe = $this->openPipeToFping($target, $ping_count); if (!isset($pipe)) { wm_warn("FPing ReadData: Couldn't open pipe to fping [WMFPING04]\n"); return array(null, null, 0); } list($count, $hitcount, $loss, $ave, $min, $max) = $this->readDataFromFping($pipe, $pattern, $ping_count); pclose($pipe); if ($count == 0) { wm_warn("FPing ReadData: No lines read. Bad hostname? ({$target}) [WMFPING03]\n"); } if ($count > 0 && $hitcount == 0) { wm_warn("FPing ReadData: {$count} lines read. But nothing returned for target??? ({$target}) Try running with DEBUG to see output. [WMFPING02]\n"); } if ($hitcount > 0) { $data[IN] = $ave; $data[OUT] = $loss; $mapItem->add_note("fping_min", $min); $mapItem->add_note("fping_max", $max); } wm_debug("FPing ReadData: Returning (" . WMUtility::valueOrNull($data[IN]) . "," . WMUtility::valueOrNull($data[OUT]) . ", {$data_time})\n"); return array($data[IN], $data[OUT], $data_time); }
function drawBandwidthLabels($gdImage) { wm_debug("Link " . $this->name . ": Drawing bwlabels.\n"); $directions = $this->getDirectionList(); $labelOffsets = array(); // TODO - this stuff should all be in arrays already! $labelOffsets[IN] = $this->labeloffset_in; $labelOffsets[OUT] = $this->labeloffset_out; foreach ($directions as $direction) { list($position, $index, $angle, $distance) = $this->geometry->findPointAndAngleAtPercentageDistance($labelOffsets[$direction]); $percentage = $this->percentUsages[$direction]; $bandwidth = $this->absoluteUsages[$direction]; if ($this->owner->sizedebug) { $bandwidth = $this->maxValues[$direction]; } $label_text = $this->owner->ProcessString($this->bwlabelformats[$direction], $this); if ($label_text != '') { wm_debug("Bandwidth for label is " . WMUtility::valueOrNull($bandwidth) . " (label is '{$label_text}')\n"); $padding = intval($this->get_hint('bwlabel_padding')); // if screenshot_mode is enabled, wipe any letters to X and wipe any IP address to 127.0.0.1 // hopefully that will preserve enough information to show cool stuff without leaking info if ($this->owner->get_hint('screenshot_mode') == 1) { $label_text = WMUtility::stringAnonymise($label_text); } if ($this->labelboxstyle != 'angled') { $angle = 0; } $this->drawLabelRotated($gdImage, $position, $angle, $label_text, $padding, $direction); } } }
public function performDataCollection() { $channels = $this->getChannelList(); wm_debug("-------------------------------------------------------------\n"); wm_debug("ReadData for {$this}: \n"); foreach ($channels as $channelName => $channel) { $this->absoluteUsages[$channel] = 0; } $nTargets = count($this->targets); $nFails = $this->collectDataFromTargets($channels); // that was the only target, and it's failed if ($nFails == 1 && $nTargets == 1) { // this is to allow null to be passed through from DS plugins in the case of a single target // we've never defined what x + null is, so we'll treat that as a 0 foreach ($channels as $channel) { $this->absoluteUsages[$channel] = null; } } // copy to the old named variables, for now. XXX - remove these foreach ($channels as $channelName => $channel) { $bwvar = "bandwidth_" . $channelName; $this->{$bwvar} = $this->absoluteUsages[$channel]; } wm_debug("ReadData complete for %s: %s\n", $this, join(" ", $this->absoluteUsages)); wm_debug("ReadData: Setting %s,%s for %s\n", WMUtility::valueOrNull($this->absoluteUsages[IN]), WMUtility::valueOrNull($this->absoluteUsages[OUT]), $this); }