Modify some locations to be more organised and move uptime tracking to a seperate table.

git-svn-id: http://www.observium.org/svn/observer/trunk@38 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2007-04-04 10:08:02 +00:00
parent 1806ee02f5
commit bfb8aa7af5
7 changed files with 31 additions and 62 deletions

View File

@@ -1,16 +1,25 @@
<?
$updated = '1';
$descr = $_POST['descr'];
$apache = $_POST['apache'];
$temp = $_POST['temp'];
$ignore = $_POST['ignore'];
$type = $_POST['type'];
$sql = "UPDATE `devices` SET `purpose` = '$descr', `apache` = '$apache', `temp` = '$temp', `type` = '$type', `ignore` = '$ignore' WHERE `id` = '$_GET[id]'";
$sql = "UPDATE `devices` SET `purpose` = '$descr', `apache` = '$apache', `type` = '$type', `ignore` = '$ignore' WHERE `id` = '$_GET[id]'";
$query = mysql_query($sql);
$affected = mysql_affected_rows() . "records affected";
$rows_updated = mysql_affected_rows();
if($rows_updated > 0) {
$update_message = mysql_affected_rows() . " Device record updated.";
$updated = 1;
} elseif ($rows_updated = '-1') {
$update_message = "Device record unchanged. No update necessary.";
$updated = -1;
} else {
$update_message = "Device record update error.";
$updated = 0;
}
?>

View File

@@ -1,7 +1,6 @@
<?php
$sql = mysql_query("SELECT * FROM `devices` WHERE `uptime` > '0' AND `uptime` < '86400'");
$sql = mysql_query("SELECT * FROM `devices` AS D, `device_uptime` AS U WHERE D.id = U.device_id AND U.device_uptime > '0' AND U.device_uptime < '86400'");
while($device = mysql_fetch_array($sql)){
$rebooted[] = "$device[id]";
}

View File

@@ -87,7 +87,7 @@ echo("</ul>");
echo("
<div class=contentstyle>");
include("includes/$section.inc");
include("pages/$page/$section.inc");
echo("</div>
");

View File

@@ -1,12 +1,10 @@
<?php
if($_GET['ignore']) { mysql_query("UPDATE devices SET `ignore` = '1' WHERE `id` = '$_GET[ignore]'"); }
if($_GET['unignore']) { mysql_query("UPDATE devices SET `ignore` = '0' WHERE `id` = '$_GET[unignore]'"); }
if($_GET['location']) { $where = "AND location = '$_GET[location]'"; }
if($_GET['location'] == "Unset") { $where = "AND location = ''"; }
if ($_GET['type']) { $where = "AND type = '$_GET[type]'"; }
if($_GET['location']) { $where = "WHERE location = '$_GET[location]'"; }
if($_GET['location'] == "Unset") { $where = "WHERE location = ''"; }
if ($_GET['type']) { $where = "WHERE type = '$_GET[type]'"; }
$sql = "select * from devices $where ORDER BY `ignore`, STATUS, os, hostname";
$sql = "select *, U.device_uptime as uptime from devices AS D, device_uptime AS U WHERE D.id = U.device_id $where ORDER BY `ignore`, `status`, `os`, `hostname`";
$device_query = mysql_query($sql);
echo("<table cellpadding=7 cellspacing=0 class=devicetable width=100%>");

View File

@@ -14,8 +14,8 @@ function callsgraphSNOM ($rrd, $graph, $from, $to, $width, $height, $title, $ver
"GPRINT:calls:LAST:Cu\: %2.0lf/min",
"GPRINT:calls:AVERAGE:Av\: %2.0lf/min",
"GPRINT:calls:MAX:Mx\: %2.0lf/min\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$installdir/DejaVuSansMono.ttf",
"--font", "AXIS:6:$installdir/DejaVuSansMono.ttf",
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);

View File

@@ -585,43 +585,3 @@ function apachebitsgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title,
return $imgfile;
}
}
function tempgraphUnix ($rrd, $graph, $from, $to, $width, $height, $title, $vertical)
{
global $rrdtool, $installdir, $mono_font;
$database = "rrd/" . $rrd;
$imgfile = "graphs/" . "$graph";
$optsa = array( "--start", $from, "--end", $to, "--width", $width, "--height", $height, "--vertical-label", $vertical ,"--alt-autoscale-max",
"-E", "-l 0", "--title", $title,
"DEF:cpu=$database:cputemp:AVERAGE",
"DEF:sys=$database:systemp:AVERAGE",
"LINE1.25:cpu#cc0000:CPU ",
"GPRINT:cpu:LAST:Cur\:%6.2lf",
"GPRINT:cpu:AVERAGE:Avg\: %6.2lf",
"GPRINT:cpu:MIN:Min\:%6.2lf",
"GPRINT:cpu:MAX:Max\:%6.2lf\\n",
"LINE1.25:sys#009900:System ",
"GPRINT:sys:LAST:Cur\:%6.2lf",
"GPRINT:sys:AVERAGE:Avg\: %6.2lf",
"GPRINT:sys:MIN:Min\:%6.2lf",
"GPRINT:sys:MAX:Max\:%6.2lf\\n");
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
"--font", "AXIS:6:$mono_font",
"--font-render-mode", "normal");}
$opts = array_merge($optsa, $optsb);
$ret = rrd_graph("$imgfile", $opts, count($opts));
if( !is_array($ret) ) {
$err = rrd_error();
# echo "rrd_graph() ERROR: $err\n";
return FALSE;
} else {
return $imgfile;
}
}
?>

View File

@@ -188,13 +188,7 @@ while ($device = mysql_fetch_array($device_query)) {
$update .= $seperator . "`uptime` = '$newuptime'";
$seperator = ", ";
}
if ( $newuptime && $newuptime < $uptime ) {
$update .= $seperator . "`lastchange` = NOW()";
$seperator = ", ";
} elseif($status != $newstatus) {
$update .= $seperator . "`lastchange` = NOW()";
$seperator = ", ";
}
if( $status != $newstatus ) {
$update .= $seperator . "`status` = '$newstatus'";
$seperator = ", ";
@@ -206,6 +200,15 @@ while ($device = mysql_fetch_array($device_query)) {
}
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Device status changed to $stat')");
}
if ( $newuptime ) {
$update_uptime = mysql_query("UPDATE device_uptime SET device_uptime = '$newuptime' WHERE `device_id` = '$id'");
if(mysql_affected_rows() == '0') {
$insert_uptime = mysql_query("INSERT INTO device_uptime (`device_uptime`, `device_id`) VALUES ('$newuptime','$id')");
}
}
if ($update) {
$update_query = "UPDATE `devices` SET ";
$update_query .= $update;