mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Move voltages to sensors table, clean up some unused functions and move web-only functions to the html includes file
git-svn-id: http://www.observium.org/svn/observer/trunk@1311 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -195,7 +195,7 @@ function discover_fan(&$valid, $device, $oid, $index, $type, $descr, $precision
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("UPDATE fanspeed SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = 'fanspeed' AND `device_id` = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index' ");
|
||||
mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = 'fanspeed' AND `device_id` = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index' ");
|
||||
echo("U");
|
||||
}
|
||||
}
|
||||
@@ -213,14 +213,14 @@ function discover_volt(&$valid, $device, $oid, $index, $type, $descr, $precision
|
||||
$low_limit = $config['limit']['volt'];
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(volt_id) FROM `voltage` WHERE device_id = '".$device['device_id']."' AND volt_type = '$type' AND `volt_index` = '$index'"),0) == '0')
|
||||
if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='voltage' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0')
|
||||
{
|
||||
|
||||
if(!$high_limit && isset($current)) { $high_limit = round($current * 1.05, 2); }
|
||||
if(!$low_limit && isset($current)) { $low_limit = round($current * 0.95, 2); }
|
||||
|
||||
$query = "INSERT INTO voltage (`device_id`, `volt_oid`, `volt_index`, `volt_type`, `volt_descr`, `volt_precision`, `volt_limit`, `volt_limit_low`, `volt_current`) ";
|
||||
$query .= " VALUES ('".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$low_limit', '$current')";
|
||||
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_low`, `sensor_current`) ";
|
||||
$query .= " VALUES ('voltage','".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$low_limit', '$current')";
|
||||
mysql_query($query);
|
||||
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); }
|
||||
echo("+");
|
||||
@@ -228,21 +228,21 @@ function discover_volt(&$valid, $device, $oid, $index, $type, $descr, $precision
|
||||
else
|
||||
{
|
||||
|
||||
$volt_entry = mysql_fetch_array(mysql_query("SELECT * FROM `voltage` WHERE device_id = '".$device['device_id']."' AND volt_type = '$type' AND `volt_index` = '$index'"));
|
||||
$volt_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='voltage' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"));
|
||||
|
||||
if(!isset($current) && isset($volt_entry['current'])) { $current = $volt_entry['current']; }
|
||||
|
||||
|
||||
if(!$high_limit && !$volt_entry['volt_limit'] && $current) { $high_limit = round($current * 1.05, 2); } elseif (!$high_limit && $volt_entry['volt_limit']) { $high_limit = $volt_entry['volt_limit']; }
|
||||
if(!$low_limit && !$volt_entry['volt_limit_low'] && $current) { $low_limit = round($current * 0.95, 2); } elseif (!$low_limit && $volt_entry['volt_limit_low']) { $low_limit = $volt_entry['volt_limit_low']; }
|
||||
if(!$high_limit && !$volt_entry['sensor_limit'] && $current) { $high_limit = round($current * 1.05, 2); } elseif (!$high_limit && $volt_entry['sensor_limit']) { $high_limit = $volt_entry['sensor_limit']; }
|
||||
if(!$low_limit && !$volt_entry['sensor_limit_low'] && $current) { $low_limit = round($current * 0.95, 2); } elseif (!$low_limit && $volt_entry['sensor_limit_low']) { $low_limit = $volt_entry['sensor_limit_low']; }
|
||||
|
||||
if($oid == $volt_entry['volt_oid'] && $descr == $volt_entry['volt_descr'] && $precision == $volt_entry['volt_precision'] && $volt_entry['volt_limit'] == $high_limit && $volt_entry['volt_limit_low'] == $low_limit)
|
||||
if($oid == $volt_entry['sensor_oid'] && $descr == $volt_entry['sensor_descr'] && $precision == $volt_entry['sensor_precision'] && $volt_entry['sensor_limit'] == $high_limit && $volt_entry['sensor_limit_low'] == $low_limit)
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = "UPDATE voltage SET `volt_descr` = '$descr', `volt_oid` = '$oid', `volt_precision` = '$precision', `volt_limit_low` = '$low_limit', `volt_limit` = '$high_limit' WHERE `device_id` = '" . $device['device_id'] . "' AND volt_type = '$type' AND `volt_index` = '$index'";
|
||||
$sql = "UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision', `sensor_limit_low` = '$low_limit', `sensor_limit` = '$high_limit' WHERE `sensor_class` = 'voltage' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index'";
|
||||
$query = mysql_query($sql);
|
||||
echo("U");
|
||||
if($debug) { echo("$sql ". mysql_affected_rows() . " updated"); }
|
||||
|
||||
@@ -161,20 +161,6 @@ function format_bi($size, $round = '2')
|
||||
return round($size, $round).$ext;
|
||||
}
|
||||
|
||||
function arguments($argv)
|
||||
{
|
||||
$_ARG = array();
|
||||
foreach ($argv as $arg) {
|
||||
if (ereg('--([^=]+)=(.*)',$arg,$reg)) {
|
||||
$_ARG[$reg[1]] = $reg[2];
|
||||
} elseif (ereg('-([a-zA-Z0-9])',$arg,$reg)) {
|
||||
$_ARG[$reg[1]] = 'true';
|
||||
}
|
||||
|
||||
}
|
||||
return $_ARG;
|
||||
}
|
||||
|
||||
function percent_colour($perc)
|
||||
{
|
||||
$r = min(255, 5 * ($perc - 25));
|
||||
@@ -182,16 +168,6 @@ function percent_colour($perc)
|
||||
return sprintf('#%02x%02x%02x', $r, $b, $b);
|
||||
}
|
||||
|
||||
function print_error($text)
|
||||
{
|
||||
echo('<table class="errorbox" cellpadding="3"><tr><td><img src="/images/15/exclamation.png" align="absmiddle">'.$text.'</td></tr></table>');
|
||||
}
|
||||
|
||||
function print_message($text)
|
||||
{
|
||||
echo('<table class="messagebox" cellpadding="3"><tr><td><img src="/images/16/tick.png" align="absmiddle">'.$text.'</td></tr></table>');
|
||||
}
|
||||
|
||||
function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/out errors value in RRD
|
||||
{
|
||||
global $config;
|
||||
@@ -207,17 +183,7 @@ function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/ou
|
||||
return $errors;
|
||||
}
|
||||
|
||||
function geteventicon ($message)
|
||||
{
|
||||
if ($message == "Device status changed to Down") { $icon = "server_connect.png"; }
|
||||
if ($message == "Device status changed to Up") { $icon = "server_go.png"; }
|
||||
if ($message == "Interface went down" || $message == "Interface changed state to Down" ) { $icon = "if-disconnect.png"; }
|
||||
if ($message == "Interface went up" || $message == "Interface changed state to Up" ) { $icon = "if-connect.png"; }
|
||||
if ($message == "Interface disabled") { $icon = "if-disable.png"; }
|
||||
if ($message == "Interface enabled") { $icon = "if-enable.png"; }
|
||||
if (isset($icon)) { return $icon; } else { return false; }
|
||||
}
|
||||
|
||||
# FIXME: below function is unused, only commented out in html/pages/device/overview/ports.inc.php - do we still need it?
|
||||
function device_traffic_image($device, $width, $height, $from, $to)
|
||||
{
|
||||
return "<img src='graph.php?device=" . $device . "&type=device_bits&from=" . $from . "&to=" . $to . "&width=" . $width . "&height=" . $height . "&legend=no' />";
|
||||
@@ -233,7 +199,6 @@ function devclass($device)
|
||||
return $class;
|
||||
}
|
||||
|
||||
|
||||
function getImage($host)
|
||||
{
|
||||
global $config;
|
||||
@@ -300,8 +265,6 @@ function delete_device($id)
|
||||
mysql_query("DELETE FROM `ports` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `voltage` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `fanspeed` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `toner` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `current` WHERE `device_id` = '$id'");
|
||||
@@ -310,33 +273,6 @@ function delete_device($id)
|
||||
return $ret . "Removed device $host\n";
|
||||
}
|
||||
|
||||
function retireHost($id)
|
||||
{
|
||||
global $config;
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
|
||||
mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'");
|
||||
$int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'");
|
||||
while($int_data = mysql_fetch_array($int_query)) {
|
||||
$int_if = $int_data['ifDescr'];
|
||||
$int_id = $int_data['interface_id'];
|
||||
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `local_interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `links` WHERE `remote_interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ipaddr` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ip6adjacencies` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `ip6addr` WHERE `interface_id` = '$int_id'");
|
||||
mysql_query("DELETE from `pseudowires` WHERE `interface_id` = '$int_id'");
|
||||
echo("Removed interface $int_id ($int_if)<br />");
|
||||
}
|
||||
mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `temperature` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'");
|
||||
shell_exec("rm -rf ".$config['rrd_dir']."/$host");
|
||||
echo("Removed device $host<br />");
|
||||
}
|
||||
|
||||
function addHost($host, $community, $snmpver, $port = 161)
|
||||
{
|
||||
global $config;
|
||||
@@ -353,10 +289,6 @@ function addHost($host, $community, $snmpver, $port = 161)
|
||||
} else { echo("Could not resolve $host\n"); }
|
||||
}
|
||||
|
||||
function overlibprint($text) {
|
||||
return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\"";
|
||||
}
|
||||
|
||||
function scanUDP ($host, $port, $timeout)
|
||||
{
|
||||
$handle = fsockopen($host, $port, &$errno, &$errstr, 2);
|
||||
@@ -374,19 +306,6 @@ function scanUDP ($host, $port, $timeout)
|
||||
} else { fclose($handle); return 0; }
|
||||
}
|
||||
|
||||
function humanmedia($media)
|
||||
{
|
||||
array_preg_replace($rewrite_iftype, $media);
|
||||
return $media;
|
||||
}
|
||||
|
||||
function humanspeed($speed)
|
||||
{
|
||||
$speed = formatRates($speed);
|
||||
if ($speed == "") { $speed = "-"; }
|
||||
return $speed;
|
||||
}
|
||||
|
||||
function netmask2cidr($netmask)
|
||||
{
|
||||
list ($network, $cidr) = explode("/", trim(`ipcalc $address/$mask | grep Network | cut -d" " -f 4`));
|
||||
@@ -684,6 +603,7 @@ function get_astext($asn)
|
||||
}
|
||||
}
|
||||
|
||||
# DEPRECATED
|
||||
function eventlog($eventtext,$device_id = "", $interface_id = "")
|
||||
{
|
||||
$event_query = "INSERT INTO eventlog (host, interface, datetime, message) VALUES (" . ($device_id ? $device_id : "NULL");
|
||||
@@ -691,6 +611,7 @@ function eventlog($eventtext,$device_id = "", $interface_id = "")
|
||||
mysql_query($event_query);
|
||||
}
|
||||
|
||||
# Use this function to write to the eventlog table
|
||||
function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
|
||||
{
|
||||
global $debug;
|
||||
@@ -748,14 +669,16 @@ function hex2str($hex)
|
||||
return $string;
|
||||
}
|
||||
|
||||
# Convert an SNMP hex string to regular string
|
||||
function snmp_hexstring($hex)
|
||||
{
|
||||
return hex2str(str_replace(' ','',str_replace(' 00','',$hex)));
|
||||
}
|
||||
|
||||
# Check if the supplied string is an SNMP hex string
|
||||
function isHexString($str)
|
||||
{
|
||||
return preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is",$str);
|
||||
return preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is",trim($str));
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
<?php
|
||||
|
||||
$query = "SELECT * FROM voltage WHERE device_id = '" . $device['device_id'] . "'";
|
||||
$query = "SELECT * FROM sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "'";
|
||||
$volt_data = mysql_query($query);
|
||||
while($voltage = mysql_fetch_array($volt_data)) {
|
||||
|
||||
echo("Checking voltage " . $voltage['volt_descr'] . "... ");
|
||||
echo("Checking voltage " . $voltage['sensor_descr'] . "... ");
|
||||
|
||||
#$volt_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $voltage['volt_oid'] . "|grep -v \"No Such Instance\"";
|
||||
#$volt = trim(str_replace("\"", "", shell_exec($volt_cmd)));
|
||||
$volt = snmp_get($device, $voltage['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
|
||||
|
||||
$volt = snmp_get($device, $voltage['volt_oid'], "-OUqnv", "SNMPv2-MIB");
|
||||
|
||||
if ($voltage['volt_precision'])
|
||||
if ($voltage['sensor_precision'])
|
||||
{
|
||||
$volt = $volt / $voltage['volt_precision'];
|
||||
$volt = $volt / $voltage['sensor_precision'];
|
||||
}
|
||||
|
||||
$voltrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("volt-" . $voltage['volt_descr'] . ".rrd");
|
||||
$voltrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("volt-" . $voltage['sensor_descr'] . ".rrd");
|
||||
|
||||
if (!is_file($voltrrd)) {
|
||||
`rrdtool create $voltrrd \
|
||||
@@ -32,26 +29,26 @@ while($voltage = mysql_fetch_array($volt_data)) {
|
||||
|
||||
rrdtool_update($voltrrd,"N:$volt");
|
||||
|
||||
if($voltage['volt_current'] > $voltage['volt_limit_low'] && $volt <= $voltage['volt_limit_low'])
|
||||
if($voltage['sensor_current'] > $voltage['sensor_limit_low'] && $volt <= $voltage['sensor_limit_low'])
|
||||
{
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
$msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'] . " is " . $volt . "V (Limit " . $voltage['volt_limit'];
|
||||
$msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['sensor_descr'] . " is " . $volt . "V (Limit " . $voltage['sensor_limit'];
|
||||
$msg .= "V) at " . date($config['timestamp_format']);
|
||||
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n");
|
||||
log_event('Voltage ' . $voltage['volt_descr'] . " under threshold: " . $volt . " V (< " . $voltage['volt_limit_low'] . " V)", $device['device_id'], 'voltage', $voltage['volt_id']);
|
||||
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['sensor_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $voltage['sensor_descr'] . "\n");
|
||||
log_event('Voltage ' . $voltage['sensor_descr'] . " under threshold: " . $volt . " V (< " . $voltage['sensor_limit_low'] . " V)", $device['device_id'], 'voltage', $voltage['sensor_id']);
|
||||
}
|
||||
else if($voltage['volt_current'] < $voltage['volt_limit'] && $volt >= $voltage['volt_limit'])
|
||||
else if($voltage['sensor_current'] < $voltage['sensor_limit'] && $volt >= $voltage['sensor_limit'])
|
||||
{
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
$msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'] . " is " . $volt . "V (Limit " . $voltage['volt_limit'];
|
||||
$msg = "Voltage Alarm: " . $device['hostname'] . " " . $voltage['sensor_descr'] . " is " . $volt . "V (Limit " . $voltage['sensor_limit'];
|
||||
$msg .= "V) at " . date($config['timestamp_format']);
|
||||
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n");
|
||||
log_event('Voltage ' . $voltage['volt_descr'] . " above threshold: " . $volt . " V (> " . $voltage['volt_limit'] . " V)", $device['device_id'], 'voltage', $voltage['volt_id']);
|
||||
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['sensor_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $voltage['sensor_descr'] . "\n");
|
||||
log_event('Voltage ' . $voltage['sensor_descr'] . " above threshold: " . $volt . " V (> " . $voltage['sensor_limit'] . " V)", $device['device_id'], 'voltage', $voltage['sensor_id']);
|
||||
}
|
||||
|
||||
mysql_query("UPDATE voltage SET volt_current = '$volt' WHERE volt_id = '" . $voltage['volt_id'] . "'");
|
||||
mysql_query("UPDATE sensor SET volt_current = '$volt' WHERE sensor_class='voltage' AND volt_id = '" . $voltage['sensor_id'] . "'");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user