mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix up some funky formatting; add/tidy end-of-function markers to reduce diff churn
This commit is contained in:
@@ -580,6 +580,7 @@ function edit_service($service, $descr, $service_ip, $service_param = "", $servi
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* convenience function - please use this instead of 'if ($debug) { echo ...; }'
|
||||
*/
|
||||
@@ -596,7 +597,8 @@ function d_echo($text, $no_debug_text = null) {
|
||||
elseif ($no_debug_text) {
|
||||
echo "$no_debug_text";
|
||||
}
|
||||
}
|
||||
} // d_echo
|
||||
|
||||
|
||||
/*
|
||||
* convenience function - please use this instead of 'if ($debug) { print_r ...; }'
|
||||
@@ -609,27 +611,8 @@ function d_print_r($var, $no_debug_text = null) {
|
||||
elseif ($no_debug_text) {
|
||||
echo "$no_debug_text";
|
||||
}
|
||||
}
|
||||
} // d_print_r
|
||||
|
||||
/*
|
||||
* WARNING: DEPRECATED - used only by first release of MIB poller.
|
||||
* Shorten the name so it works as an RRD data source name (limited to 19 chars by default).
|
||||
* Substitute for $subst if necessary.
|
||||
* @return the shortened name
|
||||
*/
|
||||
function name_shorten($name, $common = null, $subst = "mibval", $len = 19) {
|
||||
if ($common !== null) {
|
||||
// remove common from the beginning of the string, if present
|
||||
if (strlen($name) > $len && strpos($name, $common) >= 0) {
|
||||
$newname = str_replace($common, '', $name);
|
||||
$name = $newname;
|
||||
}
|
||||
}
|
||||
if (strlen($name) > $len) {
|
||||
$name = $subst;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/*
|
||||
* @return true if the given graph type is a dynamic MIB graph
|
||||
@@ -637,7 +620,8 @@ function name_shorten($name, $common = null, $subst = "mibval", $len = 19) {
|
||||
function is_mib_graph($type, $subtype) {
|
||||
global $config;
|
||||
return $config['graph_types'][$type][$subtype]['section'] == 'mib';
|
||||
}
|
||||
} // is_mib_graph
|
||||
|
||||
|
||||
/*
|
||||
* @return true if client IP address is authorized to access graphs
|
||||
@@ -660,7 +644,8 @@ function is_client_authorized($clientip) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // is_client_authorized
|
||||
|
||||
|
||||
/*
|
||||
* @return an array of all graph subtypes for the given type
|
||||
@@ -692,7 +677,8 @@ function get_graph_subtypes($type) {
|
||||
|
||||
sort($types);
|
||||
return $types;
|
||||
}
|
||||
} // get_graph_subtypes
|
||||
|
||||
|
||||
function get_smokeping_files($device) {
|
||||
global $config;
|
||||
@@ -723,6 +709,7 @@ function get_smokeping_files($device) {
|
||||
return $smokeping_files;
|
||||
} // end get_smokeping_files
|
||||
|
||||
|
||||
function generate_smokeping_file($device,$file='') {
|
||||
global $config;
|
||||
if ($config['smokeping']['integration'] === true) {
|
||||
@@ -731,7 +718,8 @@ function generate_smokeping_file($device,$file='') {
|
||||
else {
|
||||
return $config['smokeping']['dir'] . '/' . $file;
|
||||
}
|
||||
}
|
||||
} // generate_smokeping_file
|
||||
|
||||
|
||||
/*
|
||||
* @return rounded value to 10th/100th/1000th depending on input (valid: 10, 100, 1000)
|
||||
@@ -748,6 +736,7 @@ function round_Nth($val = 0, $round_to) {
|
||||
}
|
||||
} // end round_Nth
|
||||
|
||||
|
||||
/*
|
||||
* FIXME: Dummy implementation
|
||||
*/
|
||||
@@ -757,7 +746,8 @@ function count_mib_mempools($device)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // count_mib_mempools
|
||||
|
||||
|
||||
/*
|
||||
* FIXME: Dummy implementation
|
||||
@@ -768,12 +758,14 @@ function count_mib_processors($device)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // count_mib_processors
|
||||
|
||||
|
||||
function count_mib_health($device)
|
||||
{
|
||||
return count_mib_mempools($device) + count_mib_processors($device);
|
||||
}
|
||||
} // count_mib_health
|
||||
|
||||
|
||||
/*
|
||||
* FIXME: Dummy implementation
|
||||
@@ -790,7 +782,8 @@ function is_custom_graph($type, $subtype, $device)
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // is_custom_graph
|
||||
|
||||
|
||||
/*
|
||||
* FIXME: Dummy implementation
|
||||
@@ -803,7 +796,8 @@ function enable_os_graphs($os, &$graph_enable)
|
||||
$graph_enable[$graph['graph_section']][$graph['graph_subtype']] = "device_".$graph['graph_subtype'];
|
||||
}
|
||||
*/
|
||||
}
|
||||
} // enable_os_graphs
|
||||
|
||||
|
||||
/*
|
||||
* For each os-based or global graph relevant to $device, set its section/graph entry in $graph_enable.
|
||||
@@ -817,7 +811,8 @@ function enable_graphs($device, &$graph_enable)
|
||||
}
|
||||
|
||||
enable_os_graphs($device['os'], $graph_enable);
|
||||
}
|
||||
} // enable_graphs
|
||||
|
||||
|
||||
//
|
||||
// maintain a simple cache of objects
|
||||
@@ -827,7 +822,7 @@ function object_add_cache($section, $obj)
|
||||
{
|
||||
global $object_cache;
|
||||
$object_cache[$section][$obj] = true;
|
||||
}
|
||||
} // object_add_cache
|
||||
|
||||
|
||||
function object_is_cached($section, $obj)
|
||||
@@ -839,7 +834,8 @@ function object_is_cached($section, $obj)
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} // object_is_cached
|
||||
|
||||
|
||||
/**
|
||||
* Checks if config allows us to ping this device
|
||||
@@ -858,6 +854,7 @@ function can_ping_device($attribs) {
|
||||
}
|
||||
} // end can_ping_device
|
||||
|
||||
|
||||
/*
|
||||
* @return true if the requested module type & name is globally enabled
|
||||
*/
|
||||
@@ -872,6 +869,7 @@ function is_module_enabled($type, $module)
|
||||
}
|
||||
} // is_module_enabled
|
||||
|
||||
|
||||
/*
|
||||
* @return true if every string in $arr begins with $str
|
||||
*/
|
||||
@@ -886,6 +884,7 @@ function begins_with($str, $arr)
|
||||
return true;
|
||||
} // begins_with
|
||||
|
||||
|
||||
/*
|
||||
* @return the longest starting portion of $str that matches everything in $arr
|
||||
*/
|
||||
@@ -902,6 +901,7 @@ function longest_matching_prefix($str, $arr)
|
||||
return '';
|
||||
} // longest_matching_prefix
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the path to an RRD for the Ceph application
|
||||
* @param string $gtype The type of rrd we're looking for
|
||||
@@ -921,7 +921,7 @@ function ceph_rrd($gtype) {
|
||||
|
||||
$rrd = join('-', array('app', 'ceph', $vars['id'], $gtype, $var)).'.rrd';
|
||||
return join('/', array($config['rrd_dir'], $device['hostname'], $rrd));
|
||||
}
|
||||
} // ceph_rrd
|
||||
|
||||
/**
|
||||
* Parse location field for coordinates
|
||||
|
||||
@@ -230,7 +230,8 @@ function rrdtool_create($filename, $options) {
|
||||
*/
|
||||
|
||||
|
||||
function rrdtool_update($filename, $options) {
|
||||
function rrdtool_update($filename, $options)
|
||||
{
|
||||
$values = array();
|
||||
// Do some sanitisation on the data if passed as an array.
|
||||
|
||||
@@ -250,26 +251,25 @@ function rrdtool_update($filename, $options) {
|
||||
else {
|
||||
return 'Bad options passed to rrdtool_update';
|
||||
}
|
||||
|
||||
}
|
||||
} // rrdtool_update
|
||||
|
||||
|
||||
function rrdtool_fetch($filename, $options) {
|
||||
function rrdtool_fetch($filename, $options)
|
||||
{
|
||||
return rrdtool('fetch', $filename, $options);
|
||||
|
||||
}
|
||||
} // rrdtool_fetch
|
||||
|
||||
|
||||
function rrdtool_last($filename, $options) {
|
||||
function rrdtool_last($filename, $options)
|
||||
{
|
||||
return rrdtool('last', $filename, $options);
|
||||
|
||||
}
|
||||
} // rrdtool_last
|
||||
|
||||
|
||||
function rrdtool_lastupdate($filename, $options){
|
||||
function rrdtool_lastupdate($filename, $options)
|
||||
{
|
||||
return rrdtool('lastupdate', $filename, $options);
|
||||
|
||||
}
|
||||
} // rrdtool_lastupdate
|
||||
|
||||
|
||||
/**
|
||||
@@ -280,8 +280,6 @@ function rrdtool_lastupdate($filename, $options){
|
||||
* @param string string to escape
|
||||
* @param integer if passed, string will be padded and trimmed to exactly this length (after rrdtool unescapes it)
|
||||
*/
|
||||
|
||||
|
||||
function rrdtool_escape($string, $maxlength=null){
|
||||
$result = shorten_interface_type($string);
|
||||
$result = str_replace("'", '', $result); # remove quotes
|
||||
@@ -308,7 +306,7 @@ function rrd_name($host, $extra, $exten = ".rrd") {
|
||||
global $config;
|
||||
$filename = safename(is_array($extra) ? implode("-", $extra) : $extra);
|
||||
return implode("/", array($config['rrd_dir'], $host, $filename.$exten));
|
||||
}
|
||||
} // rrd_name
|
||||
|
||||
function rrdtool_tune($type, $filename, $max) {
|
||||
$fields = array();
|
||||
@@ -335,7 +333,6 @@ function rrdtool_tune($type, $filename, $max) {
|
||||
* @param val Array of value definitions
|
||||
*
|
||||
*/
|
||||
|
||||
function rrd_create_update($device, $name, $def, $val, $step=300) {
|
||||
global $config;
|
||||
$rrd = rrd_name($device['hostname'], $name);
|
||||
@@ -347,7 +344,6 @@ function rrd_create_update($device, $name, $def, $val, $step=300) {
|
||||
}
|
||||
|
||||
rrdtool_update($rrd, $val);
|
||||
|
||||
} // rrd_create_update
|
||||
|
||||
|
||||
@@ -362,7 +358,6 @@ function rrd_file_exists($device, $name)
|
||||
} // rrd_file_exists
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* @return bool indicating rename success or failure
|
||||
* @param device Device object as used with rrd_create_update()
|
||||
|
||||
@@ -816,8 +816,6 @@ function snmp_gen_auth(&$device) {
|
||||
* ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) ruckusRootMIB(25053) ruckusObjects(1) ruckusZD(2) ruckusZDSystemModule(1) ruckusZDSystemMIB(1) ruckusZDSystemObjects(1)
|
||||
* ruckusZDSystemStats(15) 30 }
|
||||
*/
|
||||
|
||||
|
||||
function snmp_mib_parse($oid, $mib, $module, $mibdir=null) {
|
||||
global $debug;
|
||||
|
||||
@@ -886,8 +884,7 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) {
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}//end snmp_mib_parse()
|
||||
} // snmp_mib_parse
|
||||
|
||||
|
||||
/*
|
||||
@@ -923,19 +920,19 @@ function snmp_mib_walk($mib, $module, $mibdir=null)
|
||||
|
||||
return $result;
|
||||
|
||||
}//end snmp_mib_walk()
|
||||
} // snmp_mib_walk
|
||||
|
||||
|
||||
function quote_column($a)
|
||||
{
|
||||
return '`'.$a.'`';
|
||||
}
|
||||
} // quote_column
|
||||
|
||||
|
||||
function join_array($a, $b)
|
||||
{
|
||||
return quote_column($a).'='.$b;
|
||||
}
|
||||
} // join_array
|
||||
|
||||
|
||||
/*
|
||||
@@ -970,7 +967,7 @@ function update_db_table($tablename, $columns, $numkeys, $rows)
|
||||
d_echo("Result: $result\n");
|
||||
}
|
||||
dbCommitTransaction();
|
||||
}
|
||||
} // update_db_table
|
||||
|
||||
/*
|
||||
* Load the given MIB into the database.
|
||||
@@ -989,7 +986,7 @@ function snmp_mib_load($mib, $module, $included_by, $mibdir = null)
|
||||
update_db_table('mibdefs', $columns, 3, $mibs);
|
||||
return count($mibs);
|
||||
|
||||
}//end snmp_mib_load()
|
||||
} // snmp_mib_load
|
||||
|
||||
|
||||
/*
|
||||
@@ -1028,7 +1025,7 @@ function snmp_translate($oid, $module, $mibdir = null)
|
||||
$matches[2],
|
||||
);
|
||||
|
||||
}//end snmp_translate()
|
||||
} // snmp_translate
|
||||
|
||||
|
||||
/*
|
||||
@@ -1068,7 +1065,7 @@ function oid_rrd_type($oid, $mibdef)
|
||||
|
||||
return false;
|
||||
|
||||
}//end oid_rrd_type()
|
||||
} // oid_rrd_type
|
||||
|
||||
|
||||
/*
|
||||
@@ -1086,7 +1083,7 @@ function tag_graphs($mibname, $oids, $mibdef, &$graphs)
|
||||
}
|
||||
}
|
||||
|
||||
}//end tag_graphs()
|
||||
} // tag_graphs
|
||||
|
||||
|
||||
/*
|
||||
@@ -1121,9 +1118,8 @@ function update_mib_graph_types($mibname, $oids, $mibdef, $graphs)
|
||||
dbInsert($graphdef, 'graph_types');
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
}//end update_mib_graph_types()
|
||||
}
|
||||
} // update_mib_graph_types
|
||||
|
||||
|
||||
/*
|
||||
@@ -1183,7 +1179,8 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs)
|
||||
// update database
|
||||
$columns = array('device_id', 'oid', 'module', 'mib', 'object_type', 'value', 'numvalue');
|
||||
update_db_table('device_oids', $columns, 2, $deviceoids);
|
||||
}//end save_mibs()
|
||||
} // save_mibs
|
||||
|
||||
|
||||
/*
|
||||
* @return an array of MIB objects matching $module, $name, keyed by object_type
|
||||
@@ -1207,7 +1204,7 @@ function load_mibdefs($module, $name)
|
||||
|
||||
d_print_r($result);
|
||||
return $result;
|
||||
}
|
||||
} // load_mibdefs
|
||||
|
||||
/*
|
||||
* @return an array of MIB names and modules for $device from the database
|
||||
@@ -1220,7 +1217,7 @@ function load_device_mibs($device)
|
||||
$result[$row['mib']] = $row['module'];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
} // load_device_mibs
|
||||
|
||||
|
||||
/*
|
||||
@@ -1239,7 +1236,7 @@ function is_mib_poller_enabled($device)
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // is_mib_poller_enabled
|
||||
|
||||
/*
|
||||
* Run MIB-based polling for $device. Update $graphs with the results.
|
||||
@@ -1261,7 +1258,7 @@ function poll_mibs($device, &$graphs)
|
||||
save_mibs($device, $name, $oids, load_mibdefs($module, $name), $graphs);
|
||||
}
|
||||
echo "\n";
|
||||
}//end poll_mibs()
|
||||
} // poll_mibs
|
||||
|
||||
/*
|
||||
* Take a list of MIB name => module pairs.
|
||||
@@ -1304,4 +1301,4 @@ function register_mibs($device, $mibs, $included_by)
|
||||
}
|
||||
|
||||
echo "\n";
|
||||
}
|
||||
} // register_mibs
|
||||
|
||||
Reference in New Issue
Block a user