Skip to content
Merged
244 changes: 7 additions & 237 deletions lib/WeatherMap.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@

require_once('WeatherMap.functions.php');
require_once('geometry.php');
require_once('WeatherMapDataSource.class.php');
require_once('WeatherMapPreProcessor.class.php');
require_once('WeatherMapPostProcessor.class.php');
require_once('WeatherMapBase.class.php');
require_once('WeatherMapConfigItem.class.php');
require_once('WeatherMapItem.class.php');
require_once('WeatherMapNode.class.php');
require_once('WeatherMap.notes.php');
require_once('WeatherMapLink.class.php');
Expand All @@ -69,243 +75,7 @@
// error_reporting (E_ALL|E_STRICT);
error_reporting(E_ALL);

// parameterise the in/out stuff a bit
define('IN',0);
define('OUT',1);
define('WMCHANNELS',2);

define('CONFIG_TYPE_LITERAL',0);
define('CONFIG_TYPE_COLOR',1);

// some strings that are used in more than one place
define('FMT_BITS_IN', '{link:this:bandwidth_in:%2k}');
define('FMT_BITS_OUT', '{link:this:bandwidth_out:%2k}');
define('FMT_UNFORM_IN', '{link:this:bandwidth_in}');
define('FMT_UNFORM_OUT', '{link:this:bandwidth_out}');
define('FMT_PERC_IN', '{link:this:inpercent:%.2f}%');
define('FMT_PERC_OUT', '{link:this:outpercent:%.2f}%');

// the fields within a spine triple
define('X', 0);
define('Y', 1);

define('DISTANCE', 2);

// ***********************************************

// template class for data sources. All data sources extend this class.
// I really wish PHP4 would just die overnight
class WeatherMapDataSource {
// Cacti Integration
/** @var mixed */
var $local_data_id;

/** @var array */
var $down_cache = [];

// Initialize - called after config has been read (so SETs are processed)
// but just before ReadData. Used to allow plugins to verify their dependencies
// (if any) and bow out gracefully. Return false to signal that the plugin is not
// in a fit state to run at the moment.
/**
* @param WeatherMap $map
* @return bool
*/
function Init(&$map) {
return true;
}

// called with the TARGET string. Returns true or false, depending on whether it wants to handle this TARGET
// called by map->ReadData()
/**
* @param string $targetstring
* @return bool
*/
function Recognise($targetstring) {
return false;
}

// the actual ReadData
// returns an array of two values (in,out). -1,-1 if it couldn't get valid data
// configline is passed in, to allow for better error messages
// itemtype and itemname may be used as part of the target (e.g. for TSV source line)
// function ReadData($targetstring, $configline, $itemtype, $itemname, $map) { return ([-1,-1]); }
/**
* @param string $targetstring
* @param WeatherMap $map
* @param WeatherMapItem $item
* @return mixed
*/
function ReadData($targetstring, &$map, &$item) {
return ([-1, -1, 0]);
}

// pre-register a target + context, to allow a plugin to batch up queries to a slow database, or snmp for example
/**
* @param string $targetstring
* @param WeatherMap $map
* @param WeatherMapItem $item
* @return void
*/
function Register($targetstring, &$map, &$item) {
}

// called before ReadData, to allow plugins to DO the prefetch of targets known from Register
/**
* @return void
*/
function Prefetch() {
}
}

// template classes for the pre- and post-processor plugins
class WeatherMapPreProcessor {
/**
* @param WeatherMap $map
* @return bool
*/
function run(&$map) {
return false;
}
}

class WeatherMapPostProcessor {
/**
* @param WeatherMap $map
* @return bool
*/
function run(&$map) {
return false;
}
}

// ***********************************************

// Links, Nodes and the Map object inherit from this class ultimately.
// Just to make some common code common.
class WeatherMapBase {
// Declared for static analysis (dynamically populated at runtime)
/** @var mixed */
var $name;

/** @var array */
var $notes = [];
/** @var array */
var $hints = [];
/** @var mixed */
var $inherit_fieldlist;

/**
* @param string $name
* @param mixed $value
* @return void
*/
function add_note($name,$value) {
wm_debug("Adding note $name='$value' to " . $this->name);

$this->notes[$name] = $value;
}

/**
* @param string $name
* @return mixed
*/
function get_note($name) {
if (isset($this->notes[$name])) {
// debug("Found note $name in ".$this->name." with value of ".$this->notes[$name].".\n");
return ($this->notes[$name]);
} else {
// debug("Looked for note $name in ".$this->name." which doesn't exist.\n");
return (null);
}
}

/**
* @param string $name
* @param string $value
* @return void
*/
function add_hint($name,$value) {
wm_debug("Adding hint $name='$value' to " . $this->name);

$this->hints[$name] = $value;
// warn("Adding hint $name to ".$this->my_type()."/".$this->name."\n");
}

/**
* @param string $name
* @param mixed $default Value returned when the hint is not set.
* @return mixed
*/
function get_hint($name, $default = null) {
if (isset($this->hints[$name])) {
// debug("Found hint $name in ".$this->name." with value of ".$this->hints[$name].".\n");
return ($this->hints[$name]);
} else {
// debug("Looked for hint $name in ".$this->name." which doesn't exist.\n");
return ($default);
}
}
}

class WeatherMapConfigItem {
/** @var mixed */
var $defined_in;
/** @var mixed */
var $name;
/** @var mixed */
var $value;
/** @var mixed */
var $type;
}

// The 'things on the map' class. More common code (mainly variables, actually)
class WeatherMapItem extends WeatherMapBase {
// Declared for static analysis (dynamically populated at runtime)
/** @var mixed */
var $a;
/** @var mixed */
var $b;
/** @var mixed */
var $name;
/** @var mixed */
var $notestext;
/** @var mixed */
var $targets;
/** @var mixed */
var $x;
/** @var mixed */
var $y;

/** @var mixed */
var $owner;

/** @var mixed */
var $configline;
/** @var mixed */
var $infourl;
/** @var mixed */
var $overliburl;
/** @var mixed */
var $overlibwidth;
/** @var mixed */
var $overlibheight;
/** @var mixed */
var $overlibcaption;
/** @var mixed */
var $my_default;
/** @var mixed */
var $defined_in;
/** @var mixed */
var $config_override; // used by the editor to allow text-editing

/**
* @return mixed
*/
function my_type() {
return 'ITEM';
}
}
require_once('WeatherMap.constants.php');

class WeatherMap extends WeatherMapBase {
// Declared for static analysis (dynamically populated at runtime)
Expand Down
114 changes: 114 additions & 0 deletions lib/WeatherMap.constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2022-2026 The Cacti Group, Inc. |
| |
| Based on the Original Plugin developed by Howard Jones |
| |
| Copyright (C) 2005-2022 Howard Jones and contributors |
| |
| Permission is hereby granted, free of charge, to any person obtaining |
| a copy of this software and associated documentation files |
| (the "Software"), to deal in the Software without restriction, |
| including without limitation the rights to use, copy, modify, merge, |
| publish, distribute, sublicense, and/or sell copies of the Software, |
| and to permit persons to whom the Software is furnished to do so, |
| subject to the following conditions: |
| |
| The above copyright notice and this permission notice shall be |
| included in all copies or substantial portions of the Software. |
| |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| SOFTWARE. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| Extensions to Howard Jones' original work are designed, written, and |
| maintained by the Cacti Group. |
| |
| Howard Jones was the original author of Weathermap. You can reach |
| him at: howie@thingy.com |
+-------------------------------------------------------------------------+
| http://www.network-weathermap.com/ |
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/

/*
* Each define is guarded so a test or caller that already declared one can
* still load the engine.
*/

/**
* Channel indices into the in/out value pairs, and the channel count.
*/
if (!defined('IN')) {
define('IN', 0);
}

if (!defined('OUT')) {
define('OUT', 1);
}

if (!defined('WMCHANNELS')) {
define('WMCHANNELS', 2);
}

/**
* Value types in the WriteConfig() field tables: literal text or a colour.
*/
if (!defined('CONFIG_TYPE_LITERAL')) {
define('CONFIG_TYPE_LITERAL', 0);
}

if (!defined('CONFIG_TYPE_COLOR')) {
define('CONFIG_TYPE_COLOR', 1);
}

/**
* Default link label format strings for bits, unformatted values and percentages.
*/
if (!defined('FMT_BITS_IN')) {
define('FMT_BITS_IN', '{link:this:bandwidth_in:%2k}');
}

if (!defined('FMT_BITS_OUT')) {
define('FMT_BITS_OUT', '{link:this:bandwidth_out:%2k}');
}

if (!defined('FMT_UNFORM_IN')) {
define('FMT_UNFORM_IN', '{link:this:bandwidth_in}');
}

if (!defined('FMT_UNFORM_OUT')) {
define('FMT_UNFORM_OUT', '{link:this:bandwidth_out}');
}

if (!defined('FMT_PERC_IN')) {
define('FMT_PERC_IN', '{link:this:inpercent:%.2f}%');
}

if (!defined('FMT_PERC_OUT')) {
define('FMT_PERC_OUT', '{link:this:outpercent:%.2f}%');
}

/**
* Field indices within a link spine point: x, y and the distance along the spine.
*/
if (!defined('X')) {
define('X', 0);
}

if (!defined('Y')) {
define('Y', 1);
}

if (!defined('DISTANCE')) {
define('DISTANCE', 2);
}
Loading
Loading