mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
use rrdtool_update() everywhere instead of single rrdtool update lines, remove some dead code, and a bunch of coding style cleanups..
git-svn-id: http://www.observium.org/svn/observer/trunk@780 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -24,9 +24,11 @@ require('collectd/config.php');
|
||||
require('collectd/functions.php');
|
||||
require('collectd/definitions.php');
|
||||
|
||||
function device_by_id_cache($device_id) {
|
||||
function device_by_id_cache($device_id)
|
||||
{
|
||||
global $device_cache;
|
||||
if(is_array($device_cache[$device_id])) {
|
||||
if (is_array($device_cache[$device_id]))
|
||||
{
|
||||
$device = $device_cache[$device_id];
|
||||
} else {
|
||||
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'"));
|
||||
@@ -35,8 +37,8 @@ function device_by_id_cache($device_id) {
|
||||
return $device;
|
||||
}
|
||||
|
||||
function mac_clean_to_readable($mac){
|
||||
|
||||
function mac_clean_to_readable($mac)
|
||||
{
|
||||
$r = substr($mac, 0, 2);
|
||||
$r .= ":".substr($mac, 2, 2);
|
||||
$r .= ":".substr($mac, 4, 2);
|
||||
@@ -55,7 +57,9 @@ function zeropad($num)
|
||||
function zeropad_lineno($num, $length)
|
||||
{
|
||||
while (strlen($num) < $length)
|
||||
{
|
||||
$num = '0'.$num;
|
||||
}
|
||||
|
||||
return $num;
|
||||
}
|
||||
@@ -66,23 +70,30 @@ function only_alphanumeric( $string )
|
||||
}
|
||||
|
||||
|
||||
function validate_hostip($host) {
|
||||
|
||||
function validate_hostip($host)
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
function write_dev_attrib($device_id, $attrib_type, $attrib_value) {
|
||||
function write_dev_attrib($device_id, $attrib_type, $attrib_value)
|
||||
{
|
||||
$count_sql = "SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = '" . $device_id . "' AND `attrib_type` = '$attrib_type'";
|
||||
if(mysql_result(mysql_query($count_sql),0)) {
|
||||
if (mysql_result(mysql_query($count_sql),0))
|
||||
{
|
||||
$update_sql = "UPDATE devices_attribs SET attrib_value = '$attrib_value' WHERE `device_id` = '$device_id' AND `attrib_type` = '$attrib_type'";
|
||||
mysql_query($update_sql);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$insert_sql = "INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('$device_id', '$attrib_type', '$attrib_value')";
|
||||
mysql_query($insert_sql);
|
||||
}
|
||||
|
||||
return mysql_affected_rows();
|
||||
}
|
||||
|
||||
function shorthost($hostname, $len=16) {
|
||||
function shorthost($hostname, $len=16)
|
||||
{
|
||||
$parts = explode(".", $hostname);
|
||||
$shorthost = $parts[0];
|
||||
$i=1;
|
||||
@@ -94,52 +105,66 @@ function shorthost($hostname, $len=16) {
|
||||
return ($shorthost);
|
||||
}
|
||||
|
||||
function rrdtool_update($rrdfile, $rrdupdate) {
|
||||
global $config;
|
||||
global $debug;
|
||||
function rrdtool_update($rrdfile, $rrdupdate)
|
||||
{
|
||||
global $config, $debug;
|
||||
|
||||
if ($debug) { echo($config['rrdtool'] . " update $rrdfile $rrdupdate \n"); }
|
||||
return shell_exec($config['rrdtool'] . " update $rrdfile $rrdupdate");
|
||||
}
|
||||
|
||||
function rrdtool($command, $file, $options) {
|
||||
function rrdtool($command, $file, $options)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if ($config['debug']) { echo($config['rrdtool'] . " $command $file $options \n"); }
|
||||
return shell_exec($config['rrdtool'] . " $command $file $options");
|
||||
}
|
||||
|
||||
function device_array($device_id) {
|
||||
function device_array($device_id)
|
||||
{
|
||||
$sql = "SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'";
|
||||
$query = mysql_query($sql);
|
||||
$device = mysql_fetch_array($query);
|
||||
return $device;
|
||||
}
|
||||
|
||||
function getHostOS($device) {
|
||||
function getHostOS($device)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$sysDescr_cmd = $config['snmpget']." -m SNMPv2-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " sysDescr.0";
|
||||
$sysDescr = str_replace("\"", "", trim(shell_exec($sysDescr_cmd)));
|
||||
$dir_handle = @opendir($config['install_dir'] . "/includes/osdiscovery") or die("Unable to open $path");
|
||||
while ($file = readdir($dir_handle)) {
|
||||
if( preg_match("/^discover-([a-z0-9\-]*).php/", $file) ) {
|
||||
while ($file = readdir($dir_handle))
|
||||
{
|
||||
if ( preg_match("/^discover-([a-z0-9\-]*).php/", $file) )
|
||||
{
|
||||
include($config['install_dir'] . "/includes/osdiscovery/" . $file);
|
||||
}
|
||||
}
|
||||
closedir($dir_handle);
|
||||
|
||||
if ($os) { return $os; } else { return FALSE; }
|
||||
}
|
||||
|
||||
function billpermitted($bill_id)
|
||||
{
|
||||
global $_SESSION;
|
||||
if($_SESSION['userlevel'] >= "5") {
|
||||
if ($_SESSION['userlevel'] >= "5")
|
||||
{
|
||||
$allowed = TRUE;
|
||||
} elseif (@mysql_result(mysql_query("SELECT count(*) FROM bill_perms WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `bill_id` = $bill_id"), 0) > '0') {
|
||||
}
|
||||
elseif (@mysql_result(mysql_query("SELECT count(*) FROM bill_perms WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `bill_id` = $bill_id"), 0) > '0')
|
||||
{
|
||||
$allowed = TRUE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$allowed = FALSE;
|
||||
}
|
||||
return $allowed;
|
||||
|
||||
return $allowed;
|
||||
}
|
||||
|
||||
|
||||
@@ -614,7 +639,8 @@ function fixIOSFeatures($features)
|
||||
return $features;
|
||||
}
|
||||
|
||||
function fixIOSHardware($hardware){
|
||||
function fixIOSHardware($hardware)
|
||||
{
|
||||
|
||||
$hardware = preg_replace("/C([0-9]+)/", "Cisco \\1", $hardware);
|
||||
$hardware = preg_replace("/CISCO([0-9]+)/", "Cisco \\1", $hardware);
|
||||
@@ -633,18 +659,27 @@ function fixIOSHardware($hardware){
|
||||
|
||||
}
|
||||
|
||||
function createHost ($host, $community, $snmpver, $port = 161){
|
||||
function createHost ($host, $community, $snmpver, $port = 161)
|
||||
{
|
||||
$host = trim(strtolower($host));
|
||||
$device = array('hostname' => $host, 'community' => $community, 'snmpver' => $snmpver, 'port' => $port);
|
||||
$host_os = getHostOS($device);
|
||||
if($host_os) {
|
||||
if ($host_os)
|
||||
{
|
||||
$sql = mysql_query("INSERT INTO `devices` (`hostname`, `sysName`, `community`, `port`, `os`, `status`,`snmpver`) VALUES ('$host', '$host', '$community', '$port', '$host_os', '1','$snmpver')");
|
||||
if(mysql_affected_rows()) {
|
||||
if (mysql_affected_rows())
|
||||
{
|
||||
$device_id = mysql_result(mysql_query("SELECT device_id FROM devices WHERE hostname = '$host'"),0);
|
||||
mysql_query("INSERT INTO devices_attribs (attrib_type, attrib_value, device_id) VALUES ('discover','1','$device_id')");
|
||||
return("Created host : $host (id:$device_id) (os:$host_os)");
|
||||
} else { return FALSE; }
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -658,10 +693,12 @@ function hoststatus($id)
|
||||
{
|
||||
$sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'");
|
||||
$result = @mysql_result($sql, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function match_network ($nets, $ip, $first=false) {
|
||||
function match_network ($nets, $ip, $first=false)
|
||||
{
|
||||
$return = false;
|
||||
if (!is_array ($nets)) $nets = array ($nets);
|
||||
foreach ($nets as $net) {
|
||||
@@ -679,6 +716,7 @@ function match_network ($nets, $ip, $first=false) {
|
||||
if ($first && $return) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -687,6 +725,7 @@ function snmp2ipv6($ipv6_snmp)
|
||||
$ipv6 = explode('.',$ipv6_snmp);
|
||||
for ($i = 0;$i <= 15;$i++) { $ipv6[$i] = zeropad(dechex($ipv6[$i])); }
|
||||
for ($i = 0;$i <= 15;$i+=2) { $ipv6_2[] = $ipv6[$i] . $ipv6[$i+1]; }
|
||||
|
||||
return implode(':',$ipv6_2);
|
||||
}
|
||||
|
||||
@@ -696,6 +735,7 @@ function ipv62snmp($ipv6)
|
||||
for ($i = 0;$i < 8;$i++) { $ipv6_ex[$i] = zeropad_lineno($ipv6_ex[$i],4); }
|
||||
$ipv6_ip = implode('',$ipv6_ex);
|
||||
for ($i = 0;$i < 32;$i+=2) $ipv6_split[] = hexdec(substr($ipv6_ip,$i,2));
|
||||
|
||||
return implode('.',$ipv6_split);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ while ($acc = mysql_fetch_array($mac_accounting_query)) {
|
||||
RRA:MAX:0.5:288:797");
|
||||
}
|
||||
$woo = "N:".($b_in+0).":".($b_out+0).":".($p_in+0).":".($p_out+0);
|
||||
if($debug) {echo("\n rrdtool update $rrdfile $woo");}
|
||||
$ret = rrdtool_update("$rrdfile", $woo);
|
||||
|
||||
if ($update) { /// Do Updates
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
RRA:MAX:0.5:288:2000`;
|
||||
}
|
||||
|
||||
`rrdtool update $cpurrd N:$cpu5s:$cpu5m`;
|
||||
rrdtool_update($cpurrd, "N:$cpu5s:$cpu5m");
|
||||
|
||||
include("includes/polling/cisco-processors.inc.php");
|
||||
include("includes/polling/cisco-mempool.inc.php");
|
||||
|
||||
@@ -34,10 +34,7 @@ while($temperature = mysql_fetch_array($temp_data)) {
|
||||
|
||||
echo($temp . "C\n");
|
||||
|
||||
$updatecmd = "rrdtool update $temprrd N:$temp";
|
||||
|
||||
if ($debug) { echo "$updatecmd\n"; }
|
||||
shell_exec($updatecmd);
|
||||
rrdtool_update($temprrd,"N:$temp");
|
||||
|
||||
if($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_limit']) {
|
||||
$updated = ", `service_changed` = '" . time() . "' ";
|
||||
|
||||
Reference in New Issue
Block a user