From 27d1a215f3b72a7964ebdc471c23be8a4a469491 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Wed, 7 Jul 2010 13:58:11 +0000 Subject: [PATCH] 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 --- database-update.sql | 3 + html/includes/functions.inc.php | 39 +++++++++ html/includes/graphs/device_voltages.inc.php | 8 +- html/includes/graphs/voltage.inc.php | 8 +- html/pages/device/health.inc.php | 2 +- html/pages/device/health/voltages.inc.php | 26 +++--- html/pages/device/overview/voltages.inc.php | 23 +++-- html/pages/health/voltages.inc.php | 44 +++++----- includes/discovery/functions.inc.php | 18 ++-- includes/functions.php | 89 ++------------------ includes/polling/voltages.inc.php | 37 ++++---- 11 files changed, 129 insertions(+), 168 deletions(-) diff --git a/database-update.sql b/database-update.sql index bb7e8a44a..24f55ce5e 100644 --- a/database-update.sql +++ b/database-update.sql @@ -22,3 +22,6 @@ ALTER TABLE `devices` CHANGE `type` `type` VARCHAR(20) NOT NULL; ALTER TABLE `voltage` CHANGE `volt_index` `volt_index` VARCHAR(10) NOT NULL; ALTER TABLE `frequency` CHANGE `freq_index` `freq_index` VARCHAR(10) NOT NULL; ALTER TABLE `sensors` CHANGE `sensor_index` `sensor_index` VARCHAR(10) NOT NULL; +DROP TABLE `fanspeed`; +DROP TABLE `temperature`; +DROP TABLE `voltage`; diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 9437abdfa..404dbbbb2 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -240,4 +240,43 @@ function print_optionbar_end () "); } +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; } +} + +function overlibprint($text) { + return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\""; +} + +function humanmedia($media) +{ + array_preg_replace($rewrite_iftype, $media); + return $media; +} + +function humanspeed($speed) +{ + $speed = formatRates($speed); + if ($speed == "") { $speed = "-"; } + return $speed; +} + +function print_error($text) +{ + echo('
'.$text.'
'); +} + +function print_message($text) +{ + echo('
'.$text.'
'); +} + + ?> diff --git a/html/includes/graphs/device_voltages.inc.php b/html/includes/graphs/device_voltages.inc.php index 0f15f8110..ecfe8ac72 100644 --- a/html/includes/graphs/device_voltages.inc.php +++ b/html/includes/graphs/device_voltages.inc.php @@ -6,7 +6,7 @@ $device = device_by_id_cache($id); $rrd_options .= " -l 0 -E "; $iter = "1"; -$sql = mysql_query("SELECT * FROM voltage where device_id = '$id'"); +$sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='voltage' AND device_id = '$id'"); $rrd_options .= " COMMENT:' Cur Min Max\\n'"; while($voltage = mysql_fetch_array($sql)) { @@ -39,9 +39,9 @@ while($voltage = mysql_fetch_array($sql)) $hostname = gethostbyid($voltage['device_id']); - $descr = substr(str_pad($voltage['volt_descr'], 15),0,15); - $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("volt-" . $voltage['volt_descr'] . ".rrd"); - $volt_id = $voltage['volt_id']; + $descr = substr(str_pad($voltage['sensor_descr'], 15),0,15); + $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("volt-" . $voltage['sensor_descr'] . ".rrd"); + $volt_id = $voltage['sensor_id']; $rrd_options .= " DEF:volt$volt_id=$rrd_filename:volt:AVERAGE"; $rrd_options .= " LINE1:volt$volt_id#".$colour.":'" . $descr . "'"; diff --git a/html/includes/graphs/voltage.inc.php b/html/includes/graphs/voltage.inc.php index 600412013..262d18ea6 100644 --- a/html/includes/graphs/voltage.inc.php +++ b/html/includes/graphs/voltage.inc.php @@ -8,13 +8,13 @@ $rrd_options .= " -A "; $rrd_options .= " COMMENT:' Last Max\\n'"; - $voltage = mysql_fetch_array(mysql_query("SELECT * FROM voltage where volt_id = '".mres($_GET['id'])."'")); + $voltage = mysql_fetch_array(mysql_query("SELECT * FROM sensors WHERE sensor_class='voltage' AND sensor_id = '".mres($_GET['id'])."'")); $hostname = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '" . $voltage['device_id'] . "'"),0); - $voltage['volt_descr_fixed'] = substr(str_pad($voltage['volt_descr'], 22),0,22); + $voltage['sensor_descr_fixed'] = substr(str_pad($voltage['sensor_descr'], 22),0,22); - $rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("volt-" . $voltage['volt_descr'] . ".rrd"); + $rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("volt-" . $voltage['sensor_descr'] . ".rrd"); $rrd_options .= " DEF:volt=$rrd_filename:volt:AVERAGE"; $rrd_options .= " DEF:volt_max=$rrd_filename:volt:MAX"; @@ -24,7 +24,7 @@ $rrd_options .= " -A "; $rrd_options .= " AREA:volt_min#ffffffff"; #$rrd_options .= " AREA:volt#FFFF99"; - $rrd_options .= " LINE1.5:volt#cc0000:'" . $voltage['volt_descr_fixed']."'"; + $rrd_options .= " LINE1.5:volt#cc0000:'" . $voltage['sensor_descr_fixed']."'"; $rrd_options .= " GPRINT:volt:LAST:%3.2lfV"; $rrd_options .= " GPRINT:volt:MAX:%3.2lfV\\\\l"; diff --git a/html/pages/device/health.inc.php b/html/pages/device/health.inc.php index 1065db422..faca834a7 100644 --- a/html/pages/device/health.inc.php +++ b/html/pages/device/health.inc.php @@ -7,7 +7,7 @@ $diskio = mysql_result(mysql_query("select count(*) from ucd_diskio WHERE device $memory = mysql_result(mysql_query("select count(*) from mempools WHERE device_id = '" . $device['device_id'] . "'"), 0); $processor = mysql_result(mysql_query("select count(*) from processors WHERE device_id = '" . $device['device_id'] . "'"), 0); $fans = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "'"), 0); -$volts = mysql_result(mysql_query("select count(*) from voltage WHERE device_id = '" . $device['device_id'] . "'"), 0); +$volts = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "'"), 0); $freqs = mysql_result(mysql_query("select count(*) from frequency WHERE device_id = '" . $device['device_id'] . "'"), 0); $current = mysql_result(mysql_query("select count(*) from current WHERE device_id = '" . $device['device_id'] . "'"), 0); diff --git a/html/pages/device/health/voltages.inc.php b/html/pages/device/health/voltages.inc.php index a6b37aba4..ceaf571e4 100644 --- a/html/pages/device/health/voltages.inc.php +++ b/html/pages/device/health/voltages.inc.php @@ -1,6 +1,6 @@ "); @@ -12,10 +12,10 @@ while($volt = mysql_fetch_array($query)) { if(!is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } echo(" - " . $volt['volt_descr'] . " - " . $volt['volt_current'] . "V - " . $volt['volt_limit_low'] . 'V - ' . $volt['volt_limit'] . "V - " . $volt['volt_notes'] . " + " . $volt['sensor_descr'] . " + " . $volt['sensor_current'] . "V + " . $volt['sensor_limit_low'] . 'V - ' . $volt['sensor_limit'] . "V + " . $volt['sensor_notes'] . " \n"); echo(""); @@ -23,17 +23,17 @@ while($volt = mysql_fetch_array($query)) { // start voltage graphs - $daily_volt = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100"; - $daily_url = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150"; + $daily_volt = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100"; + $daily_url = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150"; - $weekly_volt = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100"; - $weekly_url = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150"; + $weekly_volt = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100"; + $weekly_url = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150"; - $monthly_volt = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100"; - $monthly_url = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150"; + $monthly_volt = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100"; + $monthly_url = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150"; - $yearly_volt = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100"; - $yearly_url = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150"; + $yearly_volt = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100"; + $yearly_url = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150"; echo("', LEFT);\" onmouseout=\"return nd();\"> "); diff --git a/html/pages/device/overview/voltages.inc.php b/html/pages/device/overview/voltages.inc.php index 1c751d74a..122706230 100644 --- a/html/pages/device/overview/voltages.inc.php +++ b/html/pages/device/overview/voltages.inc.php @@ -1,13 +1,12 @@ "); echo("

Voltages

"); $i = '1'; - $volts = mysql_query("SELECT * FROM voltage WHERE device_id = '" . $device['device_id'] . "'"); + $volts = mysql_query("SELECT * FROM sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "'"); echo(""); echo("
"); echo(""); @@ -16,21 +15,21 @@ if(mysql_result(mysql_query("SELECT count(volt_id) from voltage WHERE device_id $graph_colour = str_replace("#", "", $row_colour); - $volt_day = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&to=$now&width=300&height=100"; - $volt_week = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$week&to=$now&width=300&height=100"; - $volt_month = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$month&to=$now&width=300&height=100"; - $volt_year = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$year&to=$now&width=300&height=100"; - $volt_minigraph = ""; + $volt_day = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$day&to=$now&width=300&height=100"; + $volt_week = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$week&to=$now&width=300&height=100"; + $volt_month = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$month&to=$now&width=300&height=100"; + $volt_year = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$year&to=$now&width=300&height=100"; + $volt_minigraph = ""; $volt_link = ""; - $volt_link_c = $volt_link . " $volt['volt_limit'] ? "style='color: red'" : '') . '>' . $volt['volt_current'] . "V"; + $volt_link_c = $volt_link . " $volt['sensor_limit'] ? "style='color: red'" : '') . '>' . $volt['sensor_current'] . "V"; $volt_link_b = $volt_link . $volt_minigraph . ""; - $volt_link_a = $volt_link . $volt['volt_descr'] . ""; + $volt_link_a = $volt_link . $volt['sensor_descr'] . ""; - $volt['volt_descr'] = truncate($volt['volt_descr'], 25, ''); + $volt['sensor_descr'] = truncate($volt['sensor_descr'], 25, ''); echo(""); if($i == $rows) { echo("
$volt_link_a$volt_link_b$volt_link_c
"); } $i++; diff --git a/html/pages/health/voltages.inc.php b/html/pages/health/voltages.inc.php index 710340cf6..d58941c20 100644 --- a/html/pages/health/voltages.inc.php +++ b/html/pages/health/voltages.inc.php @@ -1,9 +1,9 @@ = '5') { - $sql = "SELECT * FROM `voltage` AS V, `devices` AS D WHERE V.device_id = D.device_id ORDER BY D.hostname, V.volt_descr"; + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='voltage' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr"; } else { - $sql = "SELECT * FROM `voltage` AS V, `devices` AS D, devices_perms as P WHERE V.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, V.volt_descr"; + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='voltage' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, S.sensor_descr"; } $query = mysql_query($sql); @@ -26,19 +26,19 @@ while($volt = mysql_fetch_array($query)) { if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } - $weekly_volt = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$week&to=$now&width=500&height=150"; + $weekly_volt = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$week&to=$now&width=500&height=150"; $volt_popup = "', LEFT);\" onmouseout=\"return nd();\"> - " . $volt['volt_descr'] . ""; + " . $volt['sensor_descr'] . ""; - if($volt['volt_current'] >= $volt['volt_limit']) { $alert = 'alert'; } else { $alert = ""; } + if($volt['sensor_current'] >= $volt['sensor_limit']) { $alert = 'alert'; } else { $alert = ""; } - $volt_day = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&to=$now&width=300&height=100"; - $volt_week = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$week&to=$now&width=300&height=100"; - $volt_month = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$month&to=$now&width=300&height=100"; - $volt_year = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$year&to=$now&width=300&height=100"; + $volt_day = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$day&to=$now&width=300&height=100"; + $volt_week = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$week&to=$now&width=300&height=100"; + $volt_month = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$month&to=$now&width=300&height=100"; + $volt_year = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$year&to=$now&width=300&height=100"; - $volt_minigraph = "".$volt['hostname']." - ".$volt['volt_descr']; + $volt_minigraph = "".$volt['hostname']." - ".$volt['sensor_descr']; $volt_minigraph .= "
', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >"; echo(" @@ -46,26 +46,26 @@ while($volt = mysql_fetch_array($query)) - - - + + + \n"); if($_GET['optb'] == "graphs") { ## If graphs echo("
$volt_popup $volt_minigraph $alert" . $volt['volt_current'] . "V" . $volt['volt_limit_low'] . "V - " . $volt['volt_limit'] . "V" . (isset($volt['volt_notes']) ? $volt['volt_notes'] : '') . "" . $volt['sensor_current'] . "V" . $volt['sensor_limit_low'] . "V - " . $volt['sensor_limit'] . "V" . (isset($volt['sensor_notes']) ? $volt['sensor_notes'] : '') . "
"); - $daily_graph = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&to=$now&width=211&height=100"; - $daily_url = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&to=$now&width=400&height=150"; + $daily_graph = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$day&to=$now&width=211&height=100"; + $daily_url = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$day&to=$now&width=400&height=150"; - $weekly_graph = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$week&to=$now&width=211&height=100"; - $weekly_url = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$week&to=$now&width=400&height=150"; + $weekly_graph = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$week&to=$now&width=211&height=100"; + $weekly_url = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$week&to=$now&width=400&height=150"; - $monthly_graph = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$month&to=$now&width=211&height=100"; - $monthly_url = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$month&to=$now&width=400&height=150"; + $monthly_graph = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$month&to=$now&width=211&height=100"; + $monthly_url = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$month&to=$now&width=400&height=150"; - $yearly_graph = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$year&to=$now&width=211&height=100"; - $yearly_url = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$year&to=$now&width=400&height=150"; + $yearly_graph = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$year&to=$now&width=211&height=100"; + $yearly_url = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$year&to=$now&width=400&height=150"; echo("', LEFT);\" onmouseout=\"return nd();\"> "); diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index ab06be2c9..56674639d 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -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"); } diff --git a/includes/functions.php b/includes/functions.php index 6531fb921..eeb9c9177 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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('
'.$text.'
'); -} - -function print_message($text) -{ - echo('
'.$text.'
'); -} - 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 ""; @@ -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)
"); - } - 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
"); -} - 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)); } ?> diff --git a/includes/polling/voltages.inc.php b/includes/polling/voltages.inc.php index 5dbdb0310..f80ab6e14 100755 --- a/includes/polling/voltages.inc.php +++ b/includes/polling/voltages.inc.php @@ -1,22 +1,19 @@ $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'] . "'"); } ?>