mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
move current to sensors table, plug some sql injection holes
git-svn-id: http://www.observium.org/svn/observer/trunk@1312 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -25,3 +25,4 @@ ALTER TABLE `sensors` CHANGE `sensor_index` `sensor_index` VARCHAR(10) NOT NU
|
||||
DROP TABLE `fanspeed`;
|
||||
DROP TABLE `temperature`;
|
||||
DROP TABLE `voltage`;
|
||||
DROP TABLE `current`;
|
||||
|
@@ -6,16 +6,16 @@ include("common.inc.php");
|
||||
|
||||
$rrd_options .= " COMMENT:' Last Max\\n'";
|
||||
|
||||
$current = mysql_fetch_array(mysql_query("SELECT * FROM current where current_id = '".mres($_GET['id'])."'"));
|
||||
$current = mysql_fetch_array(mysql_query("SELECT * FROM sensors WHERE sensor_class='current' AND sensor_id = '".mres($_GET['id'])."'"));
|
||||
|
||||
$hostname = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '" . $current['device_id'] . "'"),0);
|
||||
|
||||
$current['current_descr_fixed'] = substr(str_pad($current['current_descr'], 28),0,28);
|
||||
$current['sensor_descr_fixed'] = substr(str_pad($current['sensor_descr'], 28),0,28);
|
||||
|
||||
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("current-" . $current['current_descr'] . ".rrd");
|
||||
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("current-" . $current['sensor_descr'] . ".rrd");
|
||||
|
||||
$rrd_options .= " DEF:current=$rrd_filename:current:AVERAGE";
|
||||
$rrd_options .= " LINE1.5:current#cc0000:'" . $current['current_descr_fixed']."'";
|
||||
$rrd_options .= " LINE1.5:current#cc0000:'" . $current['sensor_descr_fixed']."'";
|
||||
$rrd_options .= " GPRINT:current:LAST:%3.0lfA";
|
||||
$rrd_options .= " GPRINT:current:MAX:%3.0lfA\\\\l";
|
||||
|
||||
|
@@ -6,7 +6,7 @@ $device = device_by_id_cache($id);
|
||||
$rrd_options .= " -l 0 -E ";
|
||||
|
||||
$iter = "1";
|
||||
$sql = mysql_query("SELECT * FROM current where device_id = '$id'");
|
||||
$sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='current' AND device_id = '$id'");
|
||||
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
|
||||
while($current = mysql_fetch_array($sql))
|
||||
{
|
||||
@@ -39,9 +39,9 @@ while($current = mysql_fetch_array($sql))
|
||||
|
||||
$hostname = gethostbyid($current['device_id']);
|
||||
|
||||
$descr = substr(str_pad($current['current_descr'], 15),0,15);
|
||||
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("current-" . $current['current_descr'] . ".rrd");
|
||||
$current_id = $current['current_id'];
|
||||
$descr = substr(str_pad($current['sensor_descr'], 15),0,15);
|
||||
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("current-" . $current['sensor_descr'] . ".rrd");
|
||||
$current_id = $current['sensor_id'];
|
||||
|
||||
$rrd_options .= " DEF:current$current_id=$rrd_filename:current:AVERAGE";
|
||||
$rrd_options .= " LINE1:current$current_id#".$colour.":'" . $descr . "'";
|
||||
|
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
|
||||
$temperatures = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "'"), 0);
|
||||
$humidity = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='humidity' AND device_id = '" . $device['device_id'] . "'"), 0);
|
||||
$storage = mysql_result(mysql_query("select count(*) from storage WHERE device_id = '" . $device['device_id'] . "'"), 0);
|
||||
$diskio = mysql_result(mysql_query("select count(*) from ucd_diskio 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);
|
||||
|
||||
$temperatures = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "'"), 0);
|
||||
$humidity = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='humidity' 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 sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "'"), 0);
|
||||
$current = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='current' 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);
|
||||
|
||||
$datas[] = 'overview';
|
||||
if ($processor) { $datas[] = 'processors'; }
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `current` WHERE device_id = '" . $_GET[id] . "' ORDER BY current_descr";
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='current' AND device_id = '" . mres($_GET['id']) . "' ORDER BY sensor_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
@@ -12,10 +12,10 @@ while($current = mysql_fetch_array($query)) {
|
||||
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;\">
|
||||
<td width=350>" . $current['current_descr'] . "</td>
|
||||
<td>" . $current['current_current'] . "A</td>
|
||||
<td>" . $current['current_limit_low'] . 'A - ' . $current['current_limit'] . "A</td>
|
||||
<td>" . $current['current_notes'] . "</td>
|
||||
<td width=350>" . $current['sensor_descr'] . "</td>
|
||||
<td>" . $current['sensor_current'] . "A</td>
|
||||
<td>" . $current['sensor_limit_low'] . 'A - ' . $current['sensor_limit'] . "A</td>
|
||||
<td>" . $current['sensor_notes'] . "</td>
|
||||
</tr>\n");
|
||||
echo("<tr bgcolor=$row_colour><td colspan='4'>");
|
||||
|
||||
@@ -23,17 +23,17 @@ while($current = mysql_fetch_array($query)) {
|
||||
|
||||
// start current graphs
|
||||
|
||||
$daily_current = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100";
|
||||
$daily_url = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
|
||||
$daily_current = "graph.php?id=" . $current['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100";
|
||||
$daily_url = "graph.php?id=" . $current['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
|
||||
|
||||
$weekly_current = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100";
|
||||
$weekly_url = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150";
|
||||
$weekly_current = "graph.php?id=" . $current['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100";
|
||||
$weekly_url = "graph.php?id=" . $current['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150";
|
||||
|
||||
$monthly_current = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100";
|
||||
$monthly_url = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150";
|
||||
$monthly_current = "graph.php?id=" . $current['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100";
|
||||
$monthly_url = "graph.php?id=" . $current['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150";
|
||||
|
||||
$yearly_current = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100";
|
||||
$yearly_url = "graph.php?id=" . $current['current_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150";
|
||||
$yearly_current = "graph.php?id=" . $current['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100";
|
||||
$yearly_url = "graph.php?id=" . $current['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();\">
|
||||
<img src='$daily_current' border=0></a> ");
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `ucd_diskio` WHERE device_id = '" . $_GET[id] . "' ORDER BY diskio_descr";
|
||||
$sql = "SELECT * FROM `ucd_diskio` WHERE device_id = '" . mres($_GET['id']) . "' ORDER BY diskio_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = '" . $_GET[id] . "' ORDER BY sensor_descr";
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = '" . mres($_GET['id']) . "' ORDER BY sensor_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `frequency` WHERE device_id = '" . $_GET[id] . "' ORDER BY freq_descr";
|
||||
$sql = "SELECT * FROM `frequency` WHERE device_id = '" . mres($_GET['id']- . "' ORDER BY freq_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='humidity' AND device_id = '" . $_GET[id] . "' ORDER BY sensor_descr";
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='humidity' AND device_id = '" . mres($_GET['id']) . "' ORDER BY sensor_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `storage` WHERE device_id = '" . $_GET[id] . "' ORDER BY storage_descr";
|
||||
$sql = "SELECT * FROM `storage` WHERE device_id = '" . ($_GET['id']) . "' ORDER BY storage_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='temperature' AND device_id = '" . $_GET['id'] . "' ORDER BY sensor_descr";
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='temperature' AND device_id = '" . mres($_GET['id']) . "' ORDER BY sensor_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='voltage' AND device_id = '" . $_GET[id] . "' ORDER BY sensor_descr";
|
||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='voltage' AND device_id = '" . mres($_GET['id']) . "' ORDER BY sensor_descr";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
|
||||
|
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
unset($current_seperator);
|
||||
if(mysql_result(mysql_query("SELECT count(current_id) from current WHERE device_id = '" . $device['device_id'] . "'"),0)) {
|
||||
$total = mysql_result(mysql_query("SELECT count(current_id) from current WHERE device_id = '" . $device['device_id'] . "'"),0);
|
||||
if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE sensor_class='current' AND device_id = '" . $device['device_id'] . "'"),0)) {
|
||||
$rows = round($total / 2,0);
|
||||
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/current.png'> Current</p>");
|
||||
$i = '1';
|
||||
$currents = mysql_query("SELECT * FROM current WHERE device_id = '" . $device['device_id'] . "'");
|
||||
$currents = mysql_query("SELECT * FROM sensors WHERE sensor_class='current' AND device_id = '" . $device['device_id'] . "'");
|
||||
echo("<table width=100% valign=top>");
|
||||
echo("<tr><td width=50%>");
|
||||
echo("<table width=100% cellspacing=0 cellpadding=2>");
|
||||
@@ -16,21 +15,21 @@ if(mysql_result(mysql_query("SELECT count(current_id) from current WHERE device_
|
||||
|
||||
$graph_colour = str_replace("#", "", $row_colour);
|
||||
|
||||
$current_day = "graph.php?id=" . $current['current_id'] . "&type=current&from=$day&to=$now&width=300&height=100";
|
||||
$current_week = "graph.php?id=" . $current['current_id'] . "&type=current&from=$week&to=$now&width=300&height=100";
|
||||
$current_month = "graph.php?id=" . $current['current_id'] . "&type=current&from=$month&to=$now&width=300&height=100";
|
||||
$current_year = "graph.php?id=" . $current['current_id'] . "&type=current&from=$year&to=$now&width=300&height=100";
|
||||
$current_minigraph = "<img src='graph.php?id=" . $current['current_id'] . "&type=current&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
|
||||
$current_day = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$day&to=$now&width=300&height=100";
|
||||
$current_week = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$week&to=$now&width=300&height=100";
|
||||
$current_month = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$month&to=$now&width=300&height=100";
|
||||
$current_year = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$year&to=$now&width=300&height=100";
|
||||
$current_minigraph = "<img src='graph.php?id=" . $current['sensor_id'] . "&type=current&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
|
||||
|
||||
$current_link = "<a href='/device/".$device['device_id']."/health/current/' onmouseover=\"return ";
|
||||
$current_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$current['current_descr'];
|
||||
$current_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$current['sensor_descr'];
|
||||
$current_link .= "</div><div style=\'width: 750px\'><img src=\'$current_day\'><img src=\'$current_week\'><img src=\'$current_month\'><img src=\'$current_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
|
||||
|
||||
$current_link_c = $current_link . "<span " . ($current['current_current'] < $current['current_limit_low'] || $current['current_current'] > $current['current_limit'] ? "style='color: red'" : '') . '>' . $current['current_current'] . "A</span></a>";
|
||||
$current_link_c = $current_link . "<span " . ($current['sensor_current'] < $current['sensor_limit_low'] || $current['sensor_current'] > $current['sensor_limit'] ? "style='color: red'" : '') . '>' . $current['sensor_current'] . "A</span></a>";
|
||||
$current_link_b = $current_link . $current_minigraph . "</a>";
|
||||
$current_link_a = $current_link . $current['current_descr'] . "</a>";
|
||||
$current_link_a = $current_link . $current['sensor_descr'] . "</a>";
|
||||
|
||||
$current['current_descr'] = truncate($current['current_descr'], 25, '');
|
||||
$current['sensor_descr'] = truncate($current['sensor_descr'], 25, '');
|
||||
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$current_link_a</strong></td><td width=80 align=right class=tablehead>$current_link_b<td width=80 align=right class=tablehead>$current_link_c</td></tr>");
|
||||
if($i == $rows) { echo("</table></td><td valign=top><table width=100% cellspacing=0 cellpadding=2>"); }
|
||||
$i++;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
if($_SESSION['userlevel'] >= '5') {
|
||||
$sql = "SELECT * FROM `current` AS V, `devices` AS D WHERE V.device_id = D.device_id ORDER BY D.hostname, V.current_descr";
|
||||
$sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='current' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr";
|
||||
} else {
|
||||
$sql = "SELECT * FROM `current` 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.current_descr";
|
||||
$sql = "SELECT * FROM `current` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='current' 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);
|
||||
@@ -27,19 +27,19 @@ while($current = mysql_fetch_array($query))
|
||||
{
|
||||
if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
|
||||
|
||||
$weekly_current = "graph.php?id=" . $current['current_id'] . "&type=current&from=$week&to=$now&width=500&height=150";
|
||||
$weekly_current = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$week&to=$now&width=500&height=150";
|
||||
$current_popup = "<a onmouseover=\"return overlib('<img src=\'$weekly_current\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
" . $current['current_descr'] . "</a>";
|
||||
" . $current['sensor_descr'] . "</a>";
|
||||
|
||||
if($current['current_current'] >= $current['current_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
|
||||
if($current['sensor_current'] >= $current['sensor_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
|
||||
|
||||
$current_day = "graph.php?id=" . $current['current_id'] . "&type=current&from=$day&to=$now&width=300&height=100";
|
||||
$current_week = "graph.php?id=" . $current['current_id'] . "&type=current&from=$week&to=$now&width=300&height=100";
|
||||
$current_month = "graph.php?id=" . $current['current_id'] . "&type=current&from=$month&to=$now&width=300&height=100";
|
||||
$current_year = "graph.php?id=" . $current['current_id'] . "&type=current&from=$year&to=$now&width=300&height=100";
|
||||
$current_day = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$day&to=$now&width=300&height=100";
|
||||
$current_week = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$week&to=$now&width=300&height=100";
|
||||
$current_month = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$month&to=$now&width=300&height=100";
|
||||
$current_year = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$year&to=$now&width=300&height=100";
|
||||
|
||||
$current_minigraph = "<img src='graph.php?id=" . $current['current_id'] . "&type=current&from=$day&to=$now&width=100&height=20'";
|
||||
$current_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$current['hostname']." - ".$current['current_descr'];
|
||||
$current_minigraph = "<img src='graph.php?id=" . $current['sensor_id'] . "&type=current&from=$day&to=$now&width=100&height=20'";
|
||||
$current_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$current['hostname']." - ".$current['sensor_descr'];
|
||||
$current_minigraph .= "</div><div style=\'width: 750px\'><img src=\'$current_day\'><img src=\'$current_week\'><img src=\'$current_month\'><img src=\'$current_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
|
||||
|
||||
echo("<tr bgcolor=$row_colour>
|
||||
@@ -47,27 +47,27 @@ while($current = mysql_fetch_array($query))
|
||||
<td>$current_popup</td>
|
||||
<td>$current_minigraph</td>
|
||||
<td width=100>$alert</td>
|
||||
<td style='text-align: center; font-weight: bold;'>" . $current['current_current'] . "A</td>
|
||||
<td style='text-align: center'>" . $current['current_limit_warn'] . "A</td>
|
||||
<td style='text-align: center'>" . $current['current_limit'] . "A</td>
|
||||
<td>" . (isset($current['current_notes']) ? $current['current_notes'] : '') . "</td>
|
||||
<td style='text-align: center; font-weight: bold;'>" . $current['sensor_current'] . "A</td>
|
||||
<td style='text-align: center'>" . $current['sensor_limit_warn'] . "A</td>
|
||||
<td style='text-align: center'>" . $current['sensor_limit'] . "A</td>
|
||||
<td>" . (isset($current['sensor_notes']) ? $current['sensor_notes'] : '') . "</td>
|
||||
</tr>\n");
|
||||
|
||||
if($_GET['optb'] == "graphs") { ## If graphs
|
||||
|
||||
echo("<tr bgcolor='$row_colour'><td colspan=7>");
|
||||
|
||||
$daily_graph = "graph.php?id=" . $current['current_id'] . "&type=current&from=$day&to=$now&width=211&height=100";
|
||||
$daily_url = "graph.php?id=" . $current['current_id'] . "&type=current&from=$day&to=$now&width=400&height=150";
|
||||
$daily_graph = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$day&to=$now&width=211&height=100";
|
||||
$daily_url = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$day&to=$now&width=400&height=150";
|
||||
|
||||
$weekly_graph = "graph.php?id=" . $current['current_id'] . "&type=current&from=$week&to=$now&width=211&height=100";
|
||||
$weekly_url = "graph.php?id=" . $current['current_id'] . "&type=current&from=$week&to=$now&width=400&height=150";
|
||||
$weekly_graph = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$week&to=$now&width=211&height=100";
|
||||
$weekly_url = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$week&to=$now&width=400&height=150";
|
||||
|
||||
$monthly_graph = "graph.php?id=" . $current['current_id'] . "&type=current&from=$month&to=$now&width=211&height=100";
|
||||
$monthly_url = "graph.php?id=" . $current['current_id'] . "&type=current&from=$month&to=$now&width=400&height=150";
|
||||
$monthly_graph = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$month&to=$now&width=211&height=100";
|
||||
$monthly_url = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$month&to=$now&width=400&height=150";
|
||||
|
||||
$yearly_graph = "graph.php?id=" . $current['current_id'] . "&type=current&from=$year&to=$now&width=211&height=100";
|
||||
$yearly_url = "graph.php?id=" . $current['current_id'] . "&type=current&from=$year&to=$now&width=400&height=150";
|
||||
$yearly_graph = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$year&to=$now&width=211&height=100";
|
||||
$yearly_url = "graph.php?id=" . $current['sensor_id'] . "&type=current&from=$year&to=$now&width=400&height=150";
|
||||
|
||||
echo("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
|
||||
<img src='$daily_graph' border=0></a> ");
|
||||
|
@@ -341,24 +341,24 @@ function discover_current(&$valid, $device, $oid, $index, $type, $descr, $precis
|
||||
$low_limit = $config['limit']['current'];
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(current_id) FROM `current` WHERE device_id = '".$device['device_id']."' AND current_type = '$type' AND `current_index` = '$index'"),0) == '0')
|
||||
if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='current' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0')
|
||||
{
|
||||
$query = "INSERT INTO current (`device_id`, `current_oid`, `current_index`, `current_type`, `current_descr`, `current_precision`, `current_limit`, `current_limit_warn`, `current_limit_low`, `current_current`) ";
|
||||
$query .= " VALUES ('".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$warn_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_warn`, `sensor_limit_low`, `sensor_current`) ";
|
||||
$query .= " VALUES ('current', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$warn_limit', '$low_limit', '$current')";
|
||||
mysql_query($query);
|
||||
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); }
|
||||
echo("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
$current_entry = mysql_fetch_array(mysql_query("SELECT * FROM `current` WHERE device_id = '".$device['device_id']."' AND current_type = '$type' AND `current_index` = '$index'"));
|
||||
if($oid == $current_entry['current_oid'] && $descr == $current_entry['current_descr'] && $precision == $current_entry['current_precision'])
|
||||
$current_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='current' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"));
|
||||
if($oid == $current_entry['sensor_oid'] && $descr == $current_entry['sensor_descr'] && $precision == $current_entry['sensor_precision'])
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("UPDATE current SET `current_descr` = '$descr', `current_oid` = '$oid', `current_precision` = '$precision' WHERE `device_id` = '" . $device['device_id'] . "' AND current_type = '$type' AND `current_index` = '$index' ");
|
||||
mysql_query("UPDATE current SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class`='current' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index' ");
|
||||
echo("U");
|
||||
if($debug) { echo("$query ". mysql_affected_rows() . " updated"); }
|
||||
}
|
||||
|
@@ -277,7 +277,7 @@ function addHost($host, $community, $snmpver, $port = 161)
|
||||
{
|
||||
global $config;
|
||||
list($hostshort) = explode(".", $host);
|
||||
if ( isDomainResolves($host)){
|
||||
if ( isDomainResolves($host)) {
|
||||
if ( isPingable($host)) {
|
||||
if ( mysql_result(mysql_query("SELECT COUNT(*) FROM `devices` WHERE `hostname` = '$host'"), 0) == '0' ) {
|
||||
$snmphost = shell_exec($config['snmpget'] ." -m SNMPv2-MIB -Oqv -$snmpver -c $community $host:$port sysName.0");
|
||||
@@ -332,17 +332,17 @@ function formatUptime($diff, $format="long")
|
||||
$uptime = "";
|
||||
|
||||
if ($format == "short") {
|
||||
if ($yearsDiff > '0'){ $uptime .= $yearsDiff . "y "; }
|
||||
if ($daysDiff > '0'){ $uptime .= $daysDiff . "d "; }
|
||||
if ($hrsDiff > '0'){ $uptime .= $hrsDiff . "h "; }
|
||||
if ($minsDiff > '0'){ $uptime .= $minsDiff . "m "; }
|
||||
if ($secsDiff > '0'){ $uptime .= $secsDiff . "s "; }
|
||||
if ($yearsDiff > '0') { $uptime .= $yearsDiff . "y "; }
|
||||
if ($daysDiff > '0') { $uptime .= $daysDiff . "d "; }
|
||||
if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; }
|
||||
if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; }
|
||||
if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; }
|
||||
} else {
|
||||
if ($yearsDiff > '0'){ $uptime .= $yearsDiff . " years, "; }
|
||||
if ($daysDiff > '0'){ $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; }
|
||||
if ($hrsDiff > '0'){ $uptime .= $hrsDiff . "h "; }
|
||||
if ($minsDiff > '0'){ $uptime .= $minsDiff . "m "; }
|
||||
if ($secsDiff > '0'){ $uptime .= $secsDiff . "s "; }
|
||||
if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; }
|
||||
if ($daysDiff > '0') { $uptime .= $daysDiff . " day" . ($daysDiff != 1 ? 's' : '' ) . ", "; }
|
||||
if ($hrsDiff > '0') { $uptime .= $hrsDiff . "h "; }
|
||||
if ($minsDiff > '0') { $uptime .= $minsDiff . "m "; }
|
||||
if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; }
|
||||
}
|
||||
return trim($uptime);
|
||||
}
|
||||
@@ -368,7 +368,6 @@ function isPingable($hostname) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function is_odd($number) {
|
||||
return $number & 1; // 0 = even, 1 = odd
|
||||
}
|
||||
@@ -624,7 +623,6 @@ function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
|
||||
mysql_query($event_query);
|
||||
}
|
||||
|
||||
|
||||
function notify($device,$title,$message)
|
||||
{
|
||||
global $config;
|
||||
@@ -633,7 +631,6 @@ function notify($device,$title,$message)
|
||||
mail($email, $title, $message, $config['email_headers']);
|
||||
}
|
||||
|
||||
|
||||
function formatCiscoHardware(&$device, $short = false)
|
||||
{
|
||||
|
||||
|
@@ -1,22 +1,19 @@
|
||||
<?php
|
||||
|
||||
$query = "SELECT * FROM current WHERE device_id = '" . $device['device_id'] . "'";
|
||||
$query = "SELECT * FROM sensors WHERE sensor_class='current' AND device_id = '" . $device['device_id'] . "'";
|
||||
$current_data = mysql_query($query);
|
||||
while($dbcurrent = mysql_fetch_array($current_data)) {
|
||||
|
||||
echo("Checking current " . $dbcurrent['current_descr'] . "... ");
|
||||
echo("Checking current " . $dbcurrent['sensor_descr'] . "... ");
|
||||
|
||||
#$current_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $dbcurrent['current_oid'] . "|grep -v \"No Such Instance\"";
|
||||
#$current = trim(shell_exec($current_cmd));
|
||||
$current = snmp_get($device, $dbcurrent['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
|
||||
|
||||
$current = snmp_get($device, $dbcurrent['current_oid'], "-OUqnv", "SNMPv2-MIB");
|
||||
|
||||
if ($dbcurrent['current_precision'])
|
||||
if ($dbcurrent['sensor_precision'])
|
||||
{
|
||||
$current = $current / $dbcurrent['current_precision'];
|
||||
$current = $current / $dbcurrent['sensor_precision'];
|
||||
}
|
||||
|
||||
$currentrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("current-" . $dbcurrent['current_descr'] . ".rrd");
|
||||
$currentrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("current-" . $dbcurrent['sensor_descr'] . ".rrd");
|
||||
|
||||
if (!is_file($currentrrd)) {
|
||||
`rrdtool create $currentrrd \
|
||||
@@ -33,26 +30,26 @@ while($dbcurrent = mysql_fetch_array($current_data)) {
|
||||
rrdtool_update($currentrrd,"N:$current");
|
||||
|
||||
# FIXME also warn when crossing WARN level!!
|
||||
if($dbcurrent['current_current'] > $dbcurrent['current_limit_low'] && $current <= $dbcurrent['current_limit_low'])
|
||||
if($dbcurrent['sensor_current'] > $dbcurrent['sensor_limit_low'] && $current <= $dbcurrent['sensor_limit_low'])
|
||||
{
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
$msg = "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'] . " is " . $current . "A (Limit " . $dbcurrent['current_limit'];
|
||||
$msg = "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['sensor_descr'] . " is " . $current . "A (Limit " . $dbcurrent['sensor_limit'];
|
||||
$msg .= "A) at " . date($config['timestamp_format']);
|
||||
mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['current_descr'] . "\n");
|
||||
log_event('Current ' . $dbcurrent['current_descr'] . " under threshold: " . $current . " A (< " . $dbcurrent['current_limit_low'] . " A)", $device['device_id'], 'current', $current['current_id']);
|
||||
mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['sensor_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['sensor_descr'] . "\n");
|
||||
log_event('Current ' . $dbcurrent['sensor_descr'] . " under threshold: " . $current . " A (< " . $dbcurrent['sensor_limit_low'] . " A)", $device['device_id'], 'current', $current['sensor_id']);
|
||||
}
|
||||
else if($dbcurrent['current_current'] < $dbcurrent['current_limit'] && $current >= $dbcurrent['current_limit'])
|
||||
else if($dbcurrent['sensor_current'] < $dbcurrent['sensor_limit'] && $current >= $dbcurrent['sensor_limit'])
|
||||
{
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
$msg = "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'] . " is " . $current . "A (Limit " . $dbcurrent['current_limit'];
|
||||
$msg = "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['sensor_descr'] . " is " . $current . "A (Limit " . $dbcurrent['sensor_limit'];
|
||||
$msg .= "A) at " . date($config['timestamp_format']);
|
||||
mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['current_descr'] . "\n");
|
||||
log_event('Current ' . $dbcurrent['current_descr'] . " above threshold: " . $current . " A (> " . $dbcurrent['current_limit'] . " A)", $device['device_id'], 'current', $current['current_id']);
|
||||
mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['sensor_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['sensor_descr'] . "\n");
|
||||
log_event('Current ' . $dbcurrent['sensor_descr'] . " above threshold: " . $current . " A (> " . $dbcurrent['sensor_limit'] . " A)", $device['device_id'], 'current', $current['sensor_id']);
|
||||
}
|
||||
|
||||
mysql_query("UPDATE current SET current_current = '$current' WHERE current_id = '" . $dbcurrent['current_id'] . "'");
|
||||
mysql_query("UPDATE sensors SET sensor_current = '$current' WHERE sensor_class='current' AND sensor_id = '" . $dbcurrent['sensor_id'] . "'");
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user