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:
@@ -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 `voltage` CHANGE `volt_index` `volt_index` VARCHAR(10) NOT NULL;
|
||||||
ALTER TABLE `frequency` CHANGE `freq_index` `freq_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;
|
ALTER TABLE `sensors` CHANGE `sensor_index` `sensor_index` VARCHAR(10) NOT NULL;
|
||||||
|
DROP TABLE `fanspeed`;
|
||||||
|
DROP TABLE `temperature`;
|
||||||
|
DROP TABLE `voltage`;
|
||||||
|
@@ -240,4 +240,43 @@ function print_optionbar_end ()
|
|||||||
</div>");
|
</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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('<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>');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@@ -6,7 +6,7 @@ $device = device_by_id_cache($id);
|
|||||||
$rrd_options .= " -l 0 -E ";
|
$rrd_options .= " -l 0 -E ";
|
||||||
|
|
||||||
$iter = "1";
|
$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'";
|
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
|
||||||
while($voltage = mysql_fetch_array($sql))
|
while($voltage = mysql_fetch_array($sql))
|
||||||
{
|
{
|
||||||
@@ -39,9 +39,9 @@ while($voltage = mysql_fetch_array($sql))
|
|||||||
|
|
||||||
$hostname = gethostbyid($voltage['device_id']);
|
$hostname = gethostbyid($voltage['device_id']);
|
||||||
|
|
||||||
$descr = substr(str_pad($voltage['volt_descr'], 15),0,15);
|
$descr = substr(str_pad($voltage['sensor_descr'], 15),0,15);
|
||||||
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("volt-" . $voltage['volt_descr'] . ".rrd");
|
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("volt-" . $voltage['sensor_descr'] . ".rrd");
|
||||||
$volt_id = $voltage['volt_id'];
|
$volt_id = $voltage['sensor_id'];
|
||||||
|
|
||||||
$rrd_options .= " DEF:volt$volt_id=$rrd_filename:volt:AVERAGE";
|
$rrd_options .= " DEF:volt$volt_id=$rrd_filename:volt:AVERAGE";
|
||||||
$rrd_options .= " LINE1:volt$volt_id#".$colour.":'" . $descr . "'";
|
$rrd_options .= " LINE1:volt$volt_id#".$colour.":'" . $descr . "'";
|
||||||
|
@@ -8,13 +8,13 @@ $rrd_options .= " -A ";
|
|||||||
|
|
||||||
$rrd_options .= " COMMENT:' Last Max\\n'";
|
$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);
|
$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=$rrd_filename:volt:AVERAGE";
|
||||||
$rrd_options .= " DEF:volt_max=$rrd_filename:volt:MAX";
|
$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_min#ffffffff";
|
||||||
|
|
||||||
#$rrd_options .= " AREA:volt#FFFF99";
|
#$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:LAST:%3.2lfV";
|
||||||
$rrd_options .= " GPRINT:volt:MAX:%3.2lfV\\\\l";
|
$rrd_options .= " GPRINT:volt:MAX:%3.2lfV\\\\l";
|
||||||
|
|
||||||
|
@@ -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);
|
$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);
|
$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);
|
$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);
|
$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);
|
$current = mysql_result(mysql_query("select count(*) from current WHERE device_id = '" . $device['device_id'] . "'"), 0);
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$sql = "SELECT * FROM `voltage` WHERE device_id = '" . $_GET[id] . "' ORDER BY volt_descr";
|
$sql = "SELECT * FROM `sensors` WHERE sensor_class='voltage' AND device_id = '" . $_GET[id] . "' ORDER BY sensor_descr";
|
||||||
$query = mysql_query($sql);
|
$query = mysql_query($sql);
|
||||||
|
|
||||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||||
@@ -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; }
|
if(!is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
|
||||||
|
|
||||||
echo("<tr class=list-large style=\"background-color: $row_colour; padding: 5px;\">
|
echo("<tr class=list-large style=\"background-color: $row_colour; padding: 5px;\">
|
||||||
<td width=350>" . $volt['volt_descr'] . "</td>
|
<td width=350>" . $volt['sensor_descr'] . "</td>
|
||||||
<td>" . $volt['volt_current'] . "V</td>
|
<td>" . $volt['sensor_current'] . "V</td>
|
||||||
<td>" . $volt['volt_limit_low'] . 'V - ' . $volt['volt_limit'] . "V</td>
|
<td>" . $volt['sensor_limit_low'] . 'V - ' . $volt['sensor_limit'] . "V</td>
|
||||||
<td>" . $volt['volt_notes'] . "</td>
|
<td>" . $volt['sensor_notes'] . "</td>
|
||||||
</tr>\n");
|
</tr>\n");
|
||||||
echo("<tr bgcolor=$row_colour><td colspan='4'>");
|
echo("<tr bgcolor=$row_colour><td colspan='4'>");
|
||||||
|
|
||||||
@@ -23,17 +23,17 @@ while($volt = mysql_fetch_array($query)) {
|
|||||||
|
|
||||||
// start voltage graphs
|
// start voltage graphs
|
||||||
|
|
||||||
$daily_volt = "graph.php?id=" . $volt['volt_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100";
|
$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['volt_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
|
$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_volt = "graph.php?id=" . $volt['sensor_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_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_volt = "graph.php?id=" . $volt['sensor_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_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_volt = "graph.php?id=" . $volt['sensor_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_url = "graph.php?id=" . $volt['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150";
|
||||||
|
|
||||||
echo("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
echo("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||||
<img src='$daily_volt' border=0></a> ");
|
<img src='$daily_volt' border=0></a> ");
|
||||||
|
@@ -1,13 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
unset($volt_seperator);
|
unset($volt_seperator);
|
||||||
if(mysql_result(mysql_query("SELECT count(volt_id) from voltage WHERE device_id = '" . $device['device_id'] . "'"),0)) {
|
if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "'"),0)) {
|
||||||
$total = mysql_result(mysql_query("SELECT count(volt_id) from voltage WHERE device_id = '" . $device['device_id'] . "'"),0);
|
|
||||||
$rows = round($total / 2,0);
|
$rows = round($total / 2,0);
|
||||||
echo("<div style='background-color: #eeeeee; margin: 5px; padding: 5px;'>");
|
echo("<div style='background-color: #eeeeee; margin: 5px; padding: 5px;'>");
|
||||||
echo("<p style='padding: 0px 5px 5px;' class=sectionhead><img align='absmiddle' src='".$config['base_url']."/images/icons/voltages.png'> Voltages</p>");
|
echo("<p style='padding: 0px 5px 5px;' class=sectionhead><img align='absmiddle' src='".$config['base_url']."/images/icons/voltages.png'> Voltages</p>");
|
||||||
$i = '1';
|
$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("<table width=100% valign=top>");
|
echo("<table width=100% valign=top>");
|
||||||
echo("<tr><td width=50%>");
|
echo("<tr><td width=50%>");
|
||||||
echo("<table width=100% cellspacing=0 cellpadding=2>");
|
echo("<table width=100% cellspacing=0 cellpadding=2>");
|
||||||
@@ -16,21 +15,21 @@ if(mysql_result(mysql_query("SELECT count(volt_id) from voltage WHERE device_id
|
|||||||
|
|
||||||
$graph_colour = str_replace("#", "", $row_colour);
|
$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_day = "graph.php?id=" . $volt['sensor_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_week = "graph.php?id=" . $volt['sensor_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_month = "graph.php?id=" . $volt['sensor_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_year = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$year&to=$now&width=300&height=100";
|
||||||
$volt_minigraph = "<img src='graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
|
$volt_minigraph = "<img src='graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
|
||||||
|
|
||||||
$volt_link = "<a href='/device/".$device['device_id']."/health/voltages/' onmouseover=\"return ";
|
$volt_link = "<a href='/device/".$device['device_id']."/health/voltages/' onmouseover=\"return ";
|
||||||
$volt_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$volt['volt_descr'];
|
$volt_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$volt['sensor_descr'];
|
||||||
$volt_link .= "</div><div style=\'width: 750px\'><img src=\'$volt_day\'><img src=\'$volt_week\'><img src=\'$volt_month\'><img src=\'$volt_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
|
$volt_link .= "</div><div style=\'width: 750px\'><img src=\'$volt_day\'><img src=\'$volt_week\'><img src=\'$volt_month\'><img src=\'$volt_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
|
||||||
|
|
||||||
$volt_link_c = $volt_link . "<span " . ($volt['volt_current'] < $volt['volt_limit_low'] || $volt['volt_current'] > $volt['volt_limit'] ? "style='color: red'" : '') . '>' . $volt['volt_current'] . "V</span></a>";
|
$volt_link_c = $volt_link . "<span " . ($volt['sensor_current'] < $volt['sensor_limit_low'] || $volt['sensor_current'] > $volt['sensor_limit'] ? "style='color: red'" : '') . '>' . $volt['sensor_current'] . "V</span></a>";
|
||||||
$volt_link_b = $volt_link . $volt_minigraph . "</a>";
|
$volt_link_b = $volt_link . $volt_minigraph . "</a>";
|
||||||
$volt_link_a = $volt_link . $volt['volt_descr'] . "</a>";
|
$volt_link_a = $volt_link . $volt['sensor_descr'] . "</a>";
|
||||||
|
|
||||||
$volt['volt_descr'] = truncate($volt['volt_descr'], 25, '');
|
$volt['sensor_descr'] = truncate($volt['sensor_descr'], 25, '');
|
||||||
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$volt_link_a</strong></td><td width=80 align=right class=tablehead>$volt_link_b<td width=80 align=right class=tablehead>$volt_link_c</td></tr>");
|
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$volt_link_a</strong></td><td width=80 align=right class=tablehead>$volt_link_b<td width=80 align=right class=tablehead>$volt_link_c</td></tr>");
|
||||||
if($i == $rows) { echo("</table></td><td valign=top><table width=100% cellspacing=0 cellpadding=2>"); }
|
if($i == $rows) { echo("</table></td><td valign=top><table width=100% cellspacing=0 cellpadding=2>"); }
|
||||||
$i++;
|
$i++;
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if($_SESSION['userlevel'] >= '5') {
|
if($_SESSION['userlevel'] >= '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 {
|
} 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);
|
$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; }
|
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 = "<a onmouseover=\"return overlib('<img src=\'$weekly_volt\'>', LEFT);\" onmouseout=\"return nd();\">
|
$volt_popup = "<a onmouseover=\"return overlib('<img src=\'$weekly_volt\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||||
" . $volt['volt_descr'] . "</a>";
|
" . $volt['sensor_descr'] . "</a>";
|
||||||
|
|
||||||
if($volt['volt_current'] >= $volt['volt_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
|
if($volt['sensor_current'] >= $volt['sensor_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
|
||||||
|
|
||||||
$volt_day = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&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['volt_id'] . "&type=voltage&from=$week&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['volt_id'] . "&type=voltage&from=$month&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['volt_id'] . "&type=voltage&from=$year&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 = "<img src='graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&to=$now&width=100&height=20'";
|
$volt_minigraph = "<img src='graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$day&to=$now&width=100&height=20'";
|
||||||
$volt_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$volt['hostname']." - ".$volt['volt_descr'];
|
$volt_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$volt['hostname']." - ".$volt['sensor_descr'];
|
||||||
$volt_minigraph .= "</div><div style=\'width: 750px\'><img src=\'$volt_day\'><img src=\'$volt_week\'><img src=\'$volt_month\'><img src=\'$volt_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
|
$volt_minigraph .= "</div><div style=\'width: 750px\'><img src=\'$volt_day\'><img src=\'$volt_week\'><img src=\'$volt_month\'><img src=\'$volt_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
|
||||||
|
|
||||||
echo("<tr bgcolor=$row_colour>
|
echo("<tr bgcolor=$row_colour>
|
||||||
@@ -46,26 +46,26 @@ while($volt = mysql_fetch_array($query))
|
|||||||
<td>$volt_popup</td>
|
<td>$volt_popup</td>
|
||||||
<td>$volt_minigraph</td>
|
<td>$volt_minigraph</td>
|
||||||
<td width=100>$alert</td>
|
<td width=100>$alert</td>
|
||||||
<td style='text-align: center; font-weight: bold;'>" . $volt['volt_current'] . "V</td>
|
<td style='text-align: center; font-weight: bold;'>" . $volt['sensor_current'] . "V</td>
|
||||||
<td style='text-align: center'>" . $volt['volt_limit_low'] . "V - " . $volt['volt_limit'] . "V</td>
|
<td style='text-align: center'>" . $volt['sensor_limit_low'] . "V - " . $volt['sensor_limit'] . "V</td>
|
||||||
<td>" . (isset($volt['volt_notes']) ? $volt['volt_notes'] : '') . "</td>
|
<td>" . (isset($volt['sensor_notes']) ? $volt['sensor_notes'] : '') . "</td>
|
||||||
</tr>\n");
|
</tr>\n");
|
||||||
|
|
||||||
if($_GET['optb'] == "graphs") { ## If graphs
|
if($_GET['optb'] == "graphs") { ## If graphs
|
||||||
|
|
||||||
echo("<tr bgcolor='$row_colour'><td colspan=7>");
|
echo("<tr bgcolor='$row_colour'><td colspan=7>");
|
||||||
|
|
||||||
$daily_graph = "graph.php?id=" . $volt['volt_id'] . "&type=voltage&from=$day&to=$now&width=211&height=100";
|
$daily_graph = "graph.php?id=" . $volt['sensor_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_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_graph = "graph.php?id=" . $volt['sensor_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_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_graph = "graph.php?id=" . $volt['sensor_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_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_graph = "graph.php?id=" . $volt['sensor_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_url = "graph.php?id=" . $volt['sensor_id'] . "&type=voltage&from=$year&to=$now&width=400&height=150";
|
||||||
|
|
||||||
echo("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
echo("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||||
<img src='$daily_graph' border=0></a> ");
|
<img src='$daily_graph' border=0></a> ");
|
||||||
|
@@ -195,7 +195,7 @@ function discover_fan(&$valid, $device, $oid, $index, $type, $descr, $precision
|
|||||||
}
|
}
|
||||||
else
|
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");
|
echo("U");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,14 +213,14 @@ function discover_volt(&$valid, $device, $oid, $index, $type, $descr, $precision
|
|||||||
$low_limit = $config['limit']['volt'];
|
$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(!$high_limit && isset($current)) { $high_limit = round($current * 1.05, 2); }
|
||||||
if(!$low_limit && isset($current)) { $low_limit = round($current * 0.95, 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 = "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 ('".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$low_limit', '$current')";
|
$query .= " VALUES ('voltage','".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$low_limit', '$current')";
|
||||||
mysql_query($query);
|
mysql_query($query);
|
||||||
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); }
|
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); }
|
||||||
echo("+");
|
echo("+");
|
||||||
@@ -228,21 +228,21 @@ function discover_volt(&$valid, $device, $oid, $index, $type, $descr, $precision
|
|||||||
else
|
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(!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(!$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['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(!$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(".");
|
echo(".");
|
||||||
}
|
}
|
||||||
else
|
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);
|
$query = mysql_query($sql);
|
||||||
echo("U");
|
echo("U");
|
||||||
if($debug) { echo("$sql ". mysql_affected_rows() . " updated"); }
|
if($debug) { echo("$sql ". mysql_affected_rows() . " updated"); }
|
||||||
|
@@ -161,20 +161,6 @@ function format_bi($size, $round = '2')
|
|||||||
return round($size, $round).$ext;
|
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)
|
function percent_colour($perc)
|
||||||
{
|
{
|
||||||
$r = min(255, 5 * ($perc - 25));
|
$r = min(255, 5 * ($perc - 25));
|
||||||
@@ -182,16 +168,6 @@ function percent_colour($perc)
|
|||||||
return sprintf('#%02x%02x%02x', $r, $b, $b);
|
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
|
function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/out errors value in RRD
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
@@ -207,17 +183,7 @@ function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/ou
|
|||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
function geteventicon ($message)
|
# FIXME: below function is unused, only commented out in html/pages/device/overview/ports.inc.php - do we still need it?
|
||||||
{
|
|
||||||
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 device_traffic_image($device, $width, $height, $from, $to)
|
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' />";
|
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;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getImage($host)
|
function getImage($host)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
@@ -300,8 +265,6 @@ function delete_device($id)
|
|||||||
mysql_query("DELETE FROM `ports` WHERE `device_id` = '$id'");
|
mysql_query("DELETE FROM `ports` WHERE `device_id` = '$id'");
|
||||||
mysql_query("DELETE FROM `services` 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 `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 `toner` WHERE `device_id` = '$id'");
|
||||||
mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'");
|
mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'");
|
||||||
mysql_query("DELETE FROM `current` 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";
|
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)
|
function addHost($host, $community, $snmpver, $port = 161)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
@@ -353,10 +289,6 @@ function addHost($host, $community, $snmpver, $port = 161)
|
|||||||
} else { echo("Could not resolve $host\n"); }
|
} else { echo("Could not resolve $host\n"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function overlibprint($text) {
|
|
||||||
return "onmouseover=\"return overlib('" . $text . "');\" onmouseout=\"return nd();\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
function scanUDP ($host, $port, $timeout)
|
function scanUDP ($host, $port, $timeout)
|
||||||
{
|
{
|
||||||
$handle = fsockopen($host, $port, &$errno, &$errstr, 2);
|
$handle = fsockopen($host, $port, &$errno, &$errstr, 2);
|
||||||
@@ -374,19 +306,6 @@ function scanUDP ($host, $port, $timeout)
|
|||||||
} else { fclose($handle); return 0; }
|
} 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)
|
function netmask2cidr($netmask)
|
||||||
{
|
{
|
||||||
list ($network, $cidr) = explode("/", trim(`ipcalc $address/$mask | grep Network | cut -d" " -f 4`));
|
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 = "")
|
function eventlog($eventtext,$device_id = "", $interface_id = "")
|
||||||
{
|
{
|
||||||
$event_query = "INSERT INTO eventlog (host, interface, datetime, message) VALUES (" . ($device_id ? $device_id : "NULL");
|
$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);
|
mysql_query($event_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Use this function to write to the eventlog table
|
||||||
function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
|
function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
|
||||||
{
|
{
|
||||||
global $debug;
|
global $debug;
|
||||||
@@ -748,14 +669,16 @@ function hex2str($hex)
|
|||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Convert an SNMP hex string to regular string
|
||||||
function snmp_hexstring($hex)
|
function snmp_hexstring($hex)
|
||||||
{
|
{
|
||||||
return hex2str(str_replace(' ','',str_replace(' 00','',$hex)));
|
return hex2str(str_replace(' ','',str_replace(' 00','',$hex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check if the supplied string is an SNMP hex string
|
||||||
function isHexString($str)
|
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
|
<?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);
|
$volt_data = mysql_query($query);
|
||||||
while($voltage = mysql_fetch_array($volt_data)) {
|
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 = snmp_get($device, $voltage['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
|
||||||
#$volt = trim(str_replace("\"", "", shell_exec($volt_cmd)));
|
|
||||||
|
|
||||||
$volt = snmp_get($device, $voltage['volt_oid'], "-OUqnv", "SNMPv2-MIB");
|
if ($voltage['sensor_precision'])
|
||||||
|
|
||||||
if ($voltage['volt_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)) {
|
if (!is_file($voltrrd)) {
|
||||||
`rrdtool create $voltrrd \
|
`rrdtool create $voltrrd \
|
||||||
@@ -32,26 +29,26 @@ while($voltage = mysql_fetch_array($volt_data)) {
|
|||||||
|
|
||||||
rrdtool_update($voltrrd,"N:$volt");
|
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']; }
|
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']);
|
$msg .= "V) at " . date($config['timestamp_format']);
|
||||||
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
|
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['sensor_descr'], $msg, $config['email_headers']);
|
||||||
echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n");
|
echo("Alerting for " . $device['hostname'] . " " . $voltage['sensor_descr'] . "\n");
|
||||||
log_event('Voltage ' . $voltage['volt_descr'] . " under threshold: " . $volt . " V (< " . $voltage['volt_limit_low'] . " V)", $device['device_id'], 'voltage', $voltage['volt_id']);
|
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']; }
|
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']);
|
$msg .= "V) at " . date($config['timestamp_format']);
|
||||||
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['volt_descr'], $msg, $config['email_headers']);
|
mail($email, "Voltage Alarm: " . $device['hostname'] . " " . $voltage['sensor_descr'], $msg, $config['email_headers']);
|
||||||
echo("Alerting for " . $device['hostname'] . " " . $voltage['volt_descr'] . "\n");
|
echo("Alerting for " . $device['hostname'] . " " . $voltage['sensor_descr'] . "\n");
|
||||||
log_event('Voltage ' . $voltage['volt_descr'] . " above threshold: " . $volt . " V (> " . $voltage['volt_limit'] . " V)", $device['device_id'], 'voltage', $voltage['volt_id']);
|
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