Commit version 24.12.13800
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -400,7 +400,7 @@ class HTML_ImageMap
|
||||
{
|
||||
$html = "";
|
||||
$preg = '/'.$namefilter.'/';
|
||||
|
||||
|
||||
foreach ($this->shapes as $shape)
|
||||
{
|
||||
# if( ($namefilter == "") || ( preg_match($preg,$shape->name) ))
|
||||
@ -420,6 +420,7 @@ class HTML_ImageMap
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
@ -169,9 +169,9 @@ function wm_warn($string,$notice_only=FALSE)
|
||||
{ cacti_log($message, true, "WEATHERMAP"); }
|
||||
else
|
||||
{
|
||||
$stderr=fopen('php://stderr', 'w');
|
||||
fwrite($stderr, $message."\n");
|
||||
fclose ($stderr);
|
||||
if(OBS_DEBUG){
|
||||
r($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,31 @@
|
||||
|
||||
require_once "HTML_ImageMap.class.php";
|
||||
|
||||
|
||||
function extract_port_id($str) {
|
||||
$port_id = null;
|
||||
|
||||
// Check if the string matches the first format: obs_port:<device_id>:<ifIndex>
|
||||
if (preg_match('/^obs_port:(\d+):(\d+)$/', $str, $matches)) {
|
||||
$device_id = $matches[1];
|
||||
$ifIndex = $matches[2];
|
||||
$port_id = get_port_by_ifIndex($device_id, $ifIndex);
|
||||
}
|
||||
// Check if the string matches the second format: obs_port:<port_id>
|
||||
elseif (preg_match('/^obs_port:(\d+)$/', $str, $matches)) {
|
||||
$port_id = $matches[1];
|
||||
}
|
||||
// If the string does not match any format, return null or handle as appropriate
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $port_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class WeatherMapLink extends WeatherMapItem
|
||||
{
|
||||
var $owner, $name;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,60 +5,83 @@
|
||||
// We prefer device_id to survive hostname changes and we prefer ifIndex to survive irritating add/removals.
|
||||
// ifAlias is provided for those who prefer. Probably won't be used officially, though.
|
||||
|
||||
class WeatherMapDataSource_obsdb extends WeatherMapDataSource {
|
||||
class WeatherMapDataSource_obsdb extends WeatherMapDataSource
|
||||
{
|
||||
|
||||
function Init(&$map)
|
||||
{
|
||||
if(! function_exists("dbFetchRow") ) return FALSE;
|
||||
return(TRUE);
|
||||
}
|
||||
function Init(&$map)
|
||||
{
|
||||
if (!function_exists("dbFetchRow")) {
|
||||
return FALSE;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
// Return TRUE if we can handle this target string
|
||||
function Recognise($targetstring)
|
||||
{
|
||||
if(preg_match("/^obs_port:([^:]+):([^:]+)$/",$targetstring,$matches)) { return TRUE; } else { return FALSE; }
|
||||
}
|
||||
// Return TRUE if we can handle this target string
|
||||
function Recognise($targetstring)
|
||||
{
|
||||
if (preg_match("/^obs_port:([^:]+):([^:]+)$/", $targetstring, $matches) || preg_match("/^obs_port:([^:]+)$/", $targetstring, $matches)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function ReadData($targetstring, &$map, &$item)
|
||||
{
|
||||
$data[IN] = NULL;
|
||||
$data[OUT] = NULL;
|
||||
$data_time = 0;
|
||||
|
||||
if(preg_match("/^obs_port:([^:]+):([^:]+)$/",$targetstring,$matches))
|
||||
{
|
||||
function ReadData($targetstring, &$map, &$item)
|
||||
{
|
||||
$data[IN] = NULL;
|
||||
$data[OUT] = NULL;
|
||||
$data_time = 0;
|
||||
|
||||
//r($matches);
|
||||
if (preg_match("/^obs_port:([^:]+):([^:]+)$/", $targetstring, $matches) || preg_match("/^obs_port:([^:]+)$/", $targetstring, $matches)) {
|
||||
|
||||
// Get device from Observium DB by device_id or by hostname
|
||||
if(is_numeric($matches[1])) { $device = device_by_id_cache($matches[1]); } else { $device = device_by_name($matches[1]); }
|
||||
if(is_array($device))
|
||||
{
|
||||
if(is_numeric($matches[1]))
|
||||
{
|
||||
$port = get_port_by_ifIndex($device['device_id'], $matches[2]);
|
||||
} else {
|
||||
$port = get_port_by_ifAlias($device['device_id'], $matches[2]);
|
||||
}
|
||||
// Get device from Observium DB by device_id or by hostname
|
||||
if (count($matches) == 2) {
|
||||
$device = device_by_id_cache(get_device_id_by_port_id($matches[1]));
|
||||
} elseif (is_numeric($matches[1])) {
|
||||
$device = device_by_id_cache($matches[1]);
|
||||
} else {
|
||||
$device = device_by_name($matches[1]);
|
||||
}
|
||||
|
||||
if(is_array($port))
|
||||
{
|
||||
$data[IN] = $port['ifInOctets_rate']*8;
|
||||
$data[OUT] = $port['ifOutOctets_rate']*8;
|
||||
$data_time = $port['poll_time'];
|
||||
if (is_array($device)) {
|
||||
if (count($matches) == 2) {
|
||||
$port = get_port_by_id_cache($matches[1]);
|
||||
|
||||
$item->add_note("Errors Rate", $port['ifErrors_rate']);
|
||||
$item->add_note("PPS In Rate", $port['ifInNUcastPkts_rate'] + $port['ifInUcastPkts_rate']);
|
||||
$item->add_note("PPS Out Rate", $port['ifOutNUcastPkts_rate'] + $port['ifOutUcastPkts_rate']);
|
||||
if($port['device_id'] != $device['device_id'])
|
||||
{
|
||||
unset($port);
|
||||
wm_warn("Port didn't match device.");
|
||||
}
|
||||
|
||||
} else { wm_warn("ObsPortDB: Couldn't find port"); }
|
||||
} else { wm_warn("ObsPortDB: Couldn't find device"); }
|
||||
}
|
||||
|
||||
wm_debug ("ObsPortDB ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[IN]).",$data_time)\n");
|
||||
|
||||
return( array($data[IN], $data[OUT], $data_time) );
|
||||
}
|
||||
} else {
|
||||
if (is_numeric($matches[2])) {
|
||||
$port = get_port_by_ifIndex($device['device_id'], $matches[2]);
|
||||
} else {
|
||||
$port = get_port_by_ifAlias($device['device_id'], $matches[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($port)) {
|
||||
$data[IN] = $port['ifInOctets_rate'] * 8;
|
||||
$data[OUT] = $port['ifOutOctets_rate'] * 8;
|
||||
$data_time = $port['poll_time'];
|
||||
|
||||
$item -> add_note("Errors Rate", $port['ifErrors_rate']);
|
||||
$item -> add_note("PPS In Rate", $port['ifInNUcastPkts_rate'] + $port['ifInUcastPkts_rate']);
|
||||
$item -> add_note("PPS Out Rate", $port['ifOutNUcastPkts_rate'] + $port['ifOutUcastPkts_rate']);
|
||||
|
||||
} else {
|
||||
wm_warn("ObsPortDB: Couldn't find port");
|
||||
}
|
||||
} else {
|
||||
wm_warn("ObsPortDB: Couldn't find device");
|
||||
}
|
||||
}
|
||||
|
||||
wm_debug("ObsPortDB ReadData: Returning (" . ($data[IN] === NULL ? 'NULL' : $data[IN]) . "," . ($data[OUT] === NULL ? 'NULL' : $data[IN]) . ",$data_time)\n");
|
||||
|
||||
return ([$data[IN], $data[OUT], $data_time]);
|
||||
}
|
||||
}
|
||||
|
||||
// vim:ts=4:sw=4:
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @package observium
|
||||
* @subpackage poller
|
||||
* @author Adam Armstrong <adama@observium.org>
|
||||
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
|
||||
* @copyright (C) Adam Armstrong
|
||||
*
|
||||
*/
|
||||
|
||||
@ -18,8 +18,8 @@ chdir(dirname($argv[0]));
|
||||
// Get options before definitions!
|
||||
$options = getopt("d");
|
||||
|
||||
if (is_file("../../includes/sql-config.inc.php")) {
|
||||
include("../../includes/sql-config.inc.php");
|
||||
if (is_file("../../includes/observium.inc.php")) {
|
||||
include("../../includes/observium.inc.php");
|
||||
} else {
|
||||
include("../../includes/defaults.inc.php");
|
||||
include("../../config.php");
|
||||
|
@ -10,7 +10,7 @@ chdir(dirname($argv[0]));
|
||||
$scriptname = basename($argv[0]);
|
||||
|
||||
// Get options before definitions!
|
||||
include("../sql-config.inc.php");
|
||||
include("../observium.inc.php");
|
||||
include("../polling/functions.inc.php");
|
||||
|
||||
$scriptname = basename($argv[0]);
|
||||
|
Reference in New Issue
Block a user