Changed id field in devices table to device_id (!!!1!!1!!eleven!1)

git-svn-id: http://www.observium.org/svn/observer/trunk@69 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2007-04-08 14:34:19 +00:00
parent ff04606a2f
commit e52334f578
20 changed files with 151 additions and 367 deletions

View File

@@ -11,15 +11,15 @@
include("includes/authenticate.inc");
if($_GET['host']) {
$device = $_GET['host'];
$device_id = $_GET['host'];
} elseif($_GET['device']) {
$device = $_GET['device'];
} else {
$device = getifhost($_GET['if']);
$device_id = $_GET['device'];
} elseif($_GET['if']) {
$device_id = getifhost($_GET['if']);
$ifIndex = getifindexbyid($_GET['if']);
}
if($device) {
$hostname = gethostbyid($device);
if($device_id) {
$hostname = gethostbyid($device_id);
}
$from = $_GET['from'];
@@ -33,7 +33,7 @@
$graphfile = $hostname . ".". $ifIndex . "-" . $type . ".png";
$os = gethostosbyid($device);
$os = gethostosbyid($device_id);
switch ($type) {
@@ -41,7 +41,7 @@
$graph = graph_global_bits ("global_bits.png", $from, $to, $width, $height);
break;
case 'device_bits':
$graph = graph_device_bits ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
$graph = graph_device_bits ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'bits':
$graph = trafgraph ($hostname . ".". $ifIndex . ".rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
@@ -59,7 +59,7 @@
$graph = uptimegraph ($hostname . "-uptime.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'unixfs':
$graph = unixfsgraph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
$graph = unixfsgraph ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'calls':
$graph = callsgraphSNOM ($hostname . "-data.rrd", $graphfile, $from, $to, $width, $height, $title, $vertical);
@@ -90,7 +90,7 @@
}
break;
case 'temp':
$graph = temp_graph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
$graph = temp_graph ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical);
break;
case 'mem':
if($os == "Linux" || $os == "FreeBSD" || $os == "DragonFly" || $os == "OpenBSD" || $os == "NetBSD" ) {
@@ -127,7 +127,7 @@
break;
case 'unixfs':
if($os == "Linux" || $os == "FreeBSD" || $os == "DragonFly" || $os == "OpenBSD" || $os == "NetBSD" ) {
$graph = unixfsgraph ($device, $graphfile, $from, $to, $width, $height, $title, $vertical);
$graph = unixfsgraph ($device_id, $graphfile, $from, $to, $width, $height, $title, $vertical);
}
break;
case 'postfix':

View File

@@ -1,16 +1,16 @@
<?php
$daily_traffic = "graph.php?host=$device[id]&type=$graph_type&from=$day&to=$now&width=215&height=100";
$daily_url = "graph.php?host=$device[id]&type=$graph_type&from=$day&to=$now&width=400&height=150";
$daily_traffic = "graph.php?host=" . $device['device_id'] . "&type=$graph_type&from=$day&to=$now&width=215&height=100";
$daily_url = "graph.php?host=" . $device['device_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
$weekly_traffic = "graph.php?host=$device[id]&type=$graph_type&from=$week&to=$now&width=215&height=100";
$weekly_url = "graph.php?host=$device[id]&type=$graph_type&from=$week&to=$now&width=400&height=150";
$weekly_traffic = "graph.php?host=" . $device['device_id'] . "&type=$graph_type&from=$week&to=$now&width=215&height=100";
$weekly_url = "graph.php?host=" . $device['device_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150";
$monthly_traffic = "graph.php?host=$device[id]&type=$graph_type&from=$month&to=$now&width=215&height=100";
$monthly_url = "graph.php?host=$device[id]&type=$graph_type&from=$month&to=$now&width=400&height=150";
$monthly_traffic = "graph.php?host=" . $device['device_id'] . "&type=$graph_type&from=$month&to=$now&width=215&height=100";
$monthly_url = "graph.php?host=" . $device['device_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150";
$yearly_traffic = "graph.php?host=$device[id]&type=$graph_type&from=$year&to=$now&width=215&height=100";
$yearly_url = "graph.php?host=$device[id]&type=$graph_type&from=$year&to=$now&width=400&height=150";
$yearly_traffic = "graph.php?host=" . $device['device_id'] . "&type=$graph_type&from=$year&to=$now&width=215&height=100";
$yearly_url = "graph.php?host=" . $device['device_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_traffic' border=0></a> ");

View File

@@ -7,15 +7,14 @@
$query_a = mysql_query("SELECT * FROM `devices`");
while($device = mysql_fetch_array($query_a)) {
if($device[status] == 0 && $device[ignore] == '0') { $this_alert = "1"; } elseif($device[ignore] == '0') {
if($device['status'] == 0 && $device['ignore'] == '0') { $this_alert = "1"; } elseif($device['ignore'] == '0') {
if(mysql_result(mysql_query("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_host = '$device[id]'"),0)) { $this_alert = "1"; }
if(mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = '$device[id]'"),0)) { $this_alert = "1"; }
if(mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND device_id = '" . $device[device_id] . "'"),0)) { $this_alert = "1"; }
}
if($this_alert) {
$device_alerts++;
$device_alert_sql .= " OR `id` = '$device[id]'";
$device_alert_sql .= " OR `device_id` = '" . $device['device_id'] . "'";
}
unset($this_alert);
}

View File

@@ -1,9 +1,9 @@
<?php
$devices['count'] = mysql_result(mysql_query("SELECT count(id) FROM devices"),0);
$devices['up'] = mysql_result(mysql_query("SELECT count(id) FROM devices WHERE status = '1' AND `ignore` = '0'"),0);
$devices['down'] = mysql_result(mysql_query("SELECT count(id) FROM devices WHERE status = '0' AND `ignore` = '0'"),0);
$devices['disabled'] = mysql_result(mysql_query("SELECT count(id) FROM devices WHERE `ignore` = '1'"),0);
$devices['count'] = mysql_result(mysql_query("SELECT count(*) FROM devices"),0);
$devices['up'] = mysql_result(mysql_query("SELECT count(*) FROM devices WHERE status = '1' AND `ignore` = '0'"),0);
$devices['down'] = mysql_result(mysql_query("SELECT count(*) FROM devices WHERE status = '0' AND `ignore` = '0'"),0);
$devices['disabled'] = mysql_result(mysql_query("SELECT count(*) FROM devices WHERE `ignore` = '1'"),0);
$interfaces['count'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces"),0);
$interfaces['up'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE ifOperStatus = 'up'"),0);

View File

@@ -1,8 +1,8 @@
<?php
$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'");
$sql = mysql_query("SELECT * FROM `devices` AS D, `devices_attribs` AS U WHERE D.device_id = U.device_id AND U.attrib_type = 'uptime' AND U.attrib_value > '0' AND U.attrib_value < '86400'");
while($device = mysql_fetch_array($sql)){
$rebooted[] = "$device[id]";
$rebooted[] = "$device[device_id]";
}
?>
@@ -20,41 +20,41 @@ while($device = mysql_fetch_array($sql)){
unset($already);
$i = 0;
while ($i <= count($nodes)) {
$thisnode = "$device[id]";
$thisnode = $device['device_id'];
if ($nodes[$i] == $thisnode) {
$already = "yes";
}
$i++;
}
if(!$already) { $nodes[] = "$device[id]"; }
if(!$already) { $nodes[] = $device['device_id']; }
}
$sql = mysql_query("SELECT D.id as `id` FROM `interfaces` AS I, `devices` AS D WHERE I.host = D.id AND up = 'down' AND up_admin = 'up'");
$sql = mysql_query("SELECT * FROM `interfaces` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up'");
while($device = mysql_fetch_array($sql)){
unset($already);
$i = 0;
while ($i <= count($nodes)) {
$thisnode = "$device[id]";
$thisnode = $device['device_id'];
if ($nodes[$i] == $thisnode) {
$already = "yes";
}
$i++;
}
if(!$already) { $nodes[] = "$device[id]"; }
if(!$already) { $nodes[] = $device['device_id']; }
}
$sql = mysql_query("SELECT D.id as `id` FROM `services` AS S, `devices` AS D WHERE S.service_host = D.id AND service_status = 'down'");
$sql = mysql_query("SELECT D.device_id FROM `services` AS S, `devices` AS D WHERE S.service_host = D.device_id AND service_status = 'down'");
while($device = mysql_fetch_array($sql)){
unset($already);
$i = 0;
while ($i <= count($nodes)) {
$thisnode = "$device[id]";
$thisnode = $device['device_id'];
if ($nodes[$i] == $thisnode) {
$already = "yes";
}
$i++;
}
if(!$already) { $nodes[] = "$device[id]"; }
if(!$already) { $nodes[] = $device['device_id']; }
}
foreach($nodes as $node) {
@@ -63,11 +63,11 @@ foreach($nodes as $node) {
$host = gethostbyid($node);
$ints = mysql_result(mysql_query("SELECT count(id) FROM `interfaces` WHERE `up` = 'down' AND `up_admin` = 'up' AND `host` = '$node'"),0);
$ints = mysql_result(mysql_query("SELECT count(*) FROM `interfaces` WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `device_id` = '$node'"),0);
$services = mysql_result(mysql_query("SELECT count(service_id) FROM `services` WHERE `service_status` = '0' AND `service_host` = '$node'"),0);
$intlist = array();
$sql = mysql_query("SELECT `if`, `name` FROM interfaces WHERE `up` = 'down' AND `up_admin` = 'up' AND `host` = '$node'");
$sql = mysql_query("SELECT `ifDescr`, `ifAlias` FROM interfaces WHERE `ifOperStatus` = 'down' AND `ifAdminStatus` = 'up' AND `device_id` = '$node'");
while($int = mysql_fetch_row($sql)) { $intlist[] = "<b>$int[0]</b> - $int[1]"; }
foreach ($intlist as $intname) { $intpop .= "$br $intname"; $br = "<br />"; }
unset($br);

View File

@@ -10,7 +10,7 @@ $sectionx = str_replace("-", "", $section);
$select[$sectionx] = "selected";
$device_query = mysql_query("select * from devices WHERE id = '$_GET[id]'");
$device_query = mysql_query("select * from devices WHERE `device_id` = '$_GET[id]'");
while($device = mysql_fetch_array($device_query)) {
$hostname = $device[hostname];
#$bg="#ffffff";
@@ -23,34 +23,34 @@ echo("<div class=mainpane>");
echo("
<ul id='maintab' class='shadetabs'>
<li class=$select[devoverview]>
<a href='?page=device&id=$device[id]&section=dev-overview' >
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-overview' >
<img src='images/16/server_lightning.png' align=absmiddle border=0> Overview
</a>
</li>");
if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '$device[id]'"), 0) > '0') {
if(@mysql_result(mysql_query("select count(interface_id) from interfaces WHERE device_id = '" . $device['device_id'] . "'"), 0) > '0') {
echo("
<li class=$select[devifs]>
<a href='?page=device&id=$device[id]&section=dev-ifs' >
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-ifs' >
<img src='images/16/link.png' align=absmiddle border=0> Port Details
</a>
</li>
<li class=$select[devifgraphs]>
<a href='?page=device&id=$device[id]&section=dev-ifgraphs'>
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-ifgraphs'>
<img src='images/16/chart_curve_link.png' align=absmiddle border=0> Port Graphs
</a>
</li>");
}
echo("<li class=$select[devgraphs]>
<a href='?page=device&id=$device[id]&section=dev-graphs'>
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-graphs'>
<img src='images/16/server_chart.png' align=absmiddle border=0> Host Graphs
</a>
</li>
");
if(mysql_result(mysql_query("select count(service_id) from services WHERE service_host = '$device[id]'"), 0) > '0') {
if(mysql_result(mysql_query("select count(service_id) from services WHERE service_host = '" . $device['device_id'] . "'"), 0) > '0') {
echo("
<li class=$select[devsrv]>
<a href='?page=device&id=$device[id]&section=dev-srv'>
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-srv'>
<img src='images/16/cog.png' align=absmiddle border=0> Service Details
</a>
</li>
@@ -59,14 +59,14 @@ if(mysql_result(mysql_query("select count(service_id) from services WHERE servic
echo("
<li class=$select[devevents]>
<a href='?page=device&id=$device[id]&section=dev-events'>
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-events'>
<img src='images/16/report_magnify.png' align=absmiddle border=0> Eventlog
</a>
</li>");
echo("
<li class=$select[devsyslog]>
<a href='?page=device&id=$device[id]&section=dev-syslog'>
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-syslog'>
<img src='images/16/printer.png' align=absmiddle border=0> Syslog
</a>
</li>
@@ -75,7 +75,7 @@ echo("
if($_SESSION[userlevel] > "5") {
echo("
<li class=$select[devedit]>
<a href='?page=device&id=$device[id]&section=dev-edit'>
<a href='?page=device&id=" . $device['device_id'] . "&section=dev-edit'>
<img src='images/16/server_edit.png' align=absmiddle border=0> Edit Device
</a>
</li>

View File

@@ -1,6 +1,6 @@
<?
$device_query = mysql_query("select * from devices WHERE id = '$_GET[id]'");
$device_query = mysql_query("select * from devices WHERE `device_id` = '$_GET[id]'");
while($device = mysql_fetch_array($device_query)) {
$hostname = $device[hostname];
$bg="#ffffff";

View File

@@ -4,7 +4,7 @@ $overview = 1;
$id = $_GET[id];
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE id = '$_GET[id]'"));
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE `device_id` = '$_GET[id]'"));
$interfaces['total'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id'"),0);
$interfaces['up'] = mysql_result(mysql_query("SELECT count(*) FROM interfaces WHERE device_id = '$id' AND ifOperStatus = 'up'"),0);
@@ -51,7 +51,7 @@ echo("</td><td width=50% valign=top>");
if($interfaces['total']) {
echo("<div style='background-color: #eeeeee; margin: 5px; padding: 5px;'>
<p class=sectionhead>Total Traffic</p>" . device_traffic_image($device['id'], 490, 100, $day, $now) . "</div>");
<p class=sectionhead>Total Traffic</p>" . device_traffic_image($device['device_id'], 490, 100, $day, $now) . "</div>");
}
if($interfaces['total']) {

View File

@@ -1,15 +1,12 @@
<?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 = "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`";
if($_GET['status'] == "alerted") { $sql = "select * from devices " . $device_alert_sql . " GROUP BY `id` ORDER BY `ignore`, `status`, `os`, `hostname`"; }
if($_GET['status'] == "alerted") { $sql = "select * from devices " . $device_alert_sql . " GROUP BY `device_id` ORDER BY `ignore`, `status`, `os`, `hostname`"; }
$device_query = mysql_query($sql);

View File

@@ -53,18 +53,17 @@ function generateiflink($interface, $text=0) {
if(!$text) { $text = fixIfName($interface['ifDescr']); }
$class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']);
$graph_url = "graph.php?if=" . $interface['interface_id'] . "&from=$twoday&to=$now&width=400&height=120&type=bits";
$link = "<a class=$class href='?page=interface&id=" . $interface[interface_id] . "' onmouseover=\"return overlib('<img src=\'$graph_url\'>');\" onmouseout=\"return nd();\">$text</a>";
$link = "<a class=$class href='?page=interface&id=" . $interface['interface_id'] . "' onmouseover=\"return overlib('<img src=\'$graph_url\'>');\" onmouseout=\"return nd();\">$text</a>";
return $link;
}
function generatedevicelink($device, $text=0) {
global $twoday;
global $now;
if($device['dev_id']) { $id = $device['dev_id']; } else { $id = $device['id']; }
$class = devclass($device);
if(!$text) { $text = $device[hostname]; }
$graph_url = "graph.php?host=$id&from=$twoday&to=$now&width=400&height=120&type=cpu";
$link = "<a class=$class href='?page=device&id=$id' onmouseover=\"return overlib('<img src=\'$graph_url\'>');\" onmouseout=\"return nd();\">$text</a>";
if(!$text) { $text = $device['hostname']; }
$graph_url = "graph.php?host=" . $device[device_id] . "&from=$twoday&to=$now&width=400&height=120&type=cpu";
$link = "<a class=$class href='?page=device&id=" . $device['device_id'] . "' onmouseover=\"return overlib('<img src=\'$graph_url\'>');\" onmouseout=\"return nd();\">$text</a>";
return $link;
}
@@ -85,7 +84,7 @@ function devclass($device) {
function getImage($host) {
$sql = "SELECT * FROM `devices` WHERE `id` = '$host'";
$sql = "SELECT * FROM `devices` WHERE `device_id` = '$host'";
$data = mysql_fetch_array(mysql_query($sql));
$type = strtolower($data['os']);
@@ -108,8 +107,8 @@ $type = strtolower($data['os']);
function delHost($id) {
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE id = '$id'"), 0);
mysql_query("DELETE FROM `devices` WHERE `id` = '$id'");
$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 `interfaces` WHERE `host` = '$id'");
while($int_data = mysql_fetch_array($int_query)) {
$int_if = $int_data['if'];
@@ -123,7 +122,7 @@ function delHost($id) {
mysql_query("DELETE FROM `storage` WHERE `host_id` = '$id'");
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `eventlog` WHERE `host` = '$id'");
mysql_query("DELETE FROM `interfaces` WHERE `host` = '$id'");
mysql_query("DELETE FROM `interfaces` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `services` WHERE `service_host` = '$id'");
`rm -f rrd/$host-*.rrd`;
echo("Removed device $host<br />");
@@ -282,12 +281,12 @@ function isValidInterface($if) {
} else { return 0; }
}
function ifclass($up, $up_admin) {
function ifclass($ifOperStatus, $ifAdminStatus) {
$ifclass = "interface-upup";
if ($up_admin == "down") { $ifclass = "interface-admindown"; }
if ($up_admin == "up" && $up == "down") { $ifclass = "interface-updown"; }
if ($up_admin == "up" && $up == "up") { $ifclass = "interface-upup"; }
if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; }
if ($ifAdminStatus == "up" && $ifOperStatus== "down") { $ifclass = "interface-updown"; }
if ($ifAdminStatus == "up" && $ifOperStatus== "up") { $ifclass = "interface-upup"; }
return $ifclass;
}
@@ -939,37 +938,18 @@ function createHost ($host, $community, $snmpver){
}
}
function createInterface ($host, $if, $ifIndex, $up,$up_admin,$speed,$duplex,$mac,$name){
$sql = "INSERT INTO `interfaces` (`host`,`if`,`ifIndex`, `up`,`up_admin`,`speed`,`duplex`,`mac`,`name`)";
$sql = $sql . " VALUES ('$host', '$if','$ifIndex','$up','$up_admin','$speed','$duplex','$mac',\"$name\")";
mysql_query($sql);
}
function updateInterfaceStatus ($id,$ifOperStatus,$ifAdminStatus,$speed,$duplex,$mac,$ifAlias) {
$sql = "UPDATE `interfaces` SET `up` = '$ifOperStatus', `up_admin` = '$ifAdminStatus', `speed` = '$speed', ";
$sql .= "`duplex` = '$duplex', `mac` = '$mac', `name` = \"$ifAlias\" WHERE `id` = '$id'";
mysql_query($sql);
echo("$sql\n");
}
function updateInterface ($host, $if, $ifIndex, $up, $up_admin, $speed, $duplex, $mac, $name){
$sql = "UPDATE `interfaces` SET `up` = '$up',`up_admin` = '$up_admin',`speed` = '$speed',`duplex` = '$duplex',`mac` = '$mac',`name` = \"$name\"";
$sql .= " WHERE `host` = '$host' AND `if` = '$if'";
mysql_query($sql);
}
function isDomainResolves($domain){
return gethostbyname($domain) != $domain;
}
function hoststatus($id) {
$sql = mysql_query("SELECT `status` FROM `devices` WHERE `id` = '$id'");
$sql = mysql_query("SELECT `status` FROM `devices` WHERE `device_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
}
function gethostbyid($id) {
$sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `id` = '$id'");
$sql = mysql_query("SELECT `hostname` FROM `devices` WHERE `device_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
}
@@ -993,13 +973,13 @@ function getifbyid($id) {
}
function getidbyname($domain){
$sql = mysql_query("SELECT `id` FROM `devices` WHERE `hostname` = '$domain'");
$sql = mysql_query("SELECT `device_id` FROM `devices` WHERE `hostname` = '$domain'");
$result = @mysql_result($sql, 0);
return $result;
}
function gethostosbyid($id) {
$sql = mysql_query("SELECT `os` FROM `devices` WHERE `id` = '$id'");
$sql = mysql_query("SELECT `os` FROM `devices` WHERE `device_id` = '$id'");
$result = @mysql_result($sql, 0);
return $result;
}

View File

@@ -12,18 +12,18 @@ function temp_graph ($device, $graph, $from, $to, $width, $height, $title, $vert
$iter = "1";
$sql = mysql_query("SELECT * FROM temperature where temp_host = '$device'");
$optsa[] = "COMMENT: Cur Max";
while($fs = mysql_fetch_array($sql)) {
while($temperature = mysql_fetch_array($sql)) {
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
} elseif($iter=="7") {$colour="FF0084"; unset($iter); }
$fs[temp_descr] = str_pad($fs[temp_descr], 28);
$fs[temp_descr] = substr($fs[temp_descr],0,28);
$temperature['temp_descr'] = str_pad($temperature['temp_descr'], 28);
$temperature['temp_descr'] = substr($temperature['temp_descr'],0,28);
$optsa[] = "DEF:temp$fs[temp_id]=rrd/$hostname-temp$fs[temp_id].rrd:temp:AVERAGE";
$optsa[] = "LINE1:temp$fs[temp_id]#" . $colour . ":$fs[temp_descr]";
$optsa[] = "GPRINT:temp$fs[temp_id]:LAST:%3.0lf<EFBFBD>C";
$optsa[] = "GPRINT:temp$fs[temp_id]:MAX:%3.0lf<EFBFBD>C\l";
$optsa[] = "DEF:temp" . $temperature[temp_id] . "=rrd/" . $hostname . "-temp-" . $temperature['temp_id'] . ".rrd:temp:AVERAGE";
$optsa[] = "LINE1:temp" . $temperature[temp_id] . "#" . $colour . ":" . $temperature[temp_descr];
$optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":LAST:%3.0lf<EFBFBD>C";
$optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":MAX:%3.0lf<EFBFBD>C\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",

View File

@@ -4,7 +4,7 @@ function pollDeviceIOS() {
global $device;
global $community;
$id = $device['id'];
$id = $device['device_id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];

View File

@@ -7,7 +7,7 @@ $oids = array ('ipForwDatagrams','ipInDelivers','ipInReceives','ipOutRequests','
'tcpEstabResets','tcpInSegs','tcpOutSegs','tcpRetransSegs','udpInDatagrams','udpOutDatagrams','udpInErrors',
'udpNoPorts');
$rrdfile = "rrd/" . $hostname . "-netinfo.rrd";
$rrdfile = "rrd/" . $device['hostname'] . "-netinfo.rrd";
$rrd_create = "rrdtool create $rrdfile ";
$rrd_create .= "RRA:AVERAGE:0.5:1:600 RRA:AVERAGE:0.5:6:700 RRA:AVERAGE:0.5:24:775 RRA:AVERAGE:0.5:288:797 RRA:MAX:0.5:1:600 \
@@ -22,7 +22,8 @@ foreach($oids as $oid){
if(!file_exists($rrdfile)) { `$rrd_create`; }
$snmpdata = trim(`snmpget -O qv -$snmpver -c $community $hostname $snmpstring`);
$snmpdata_cmd = "snmpbulkget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " $snmpstring";
$snmpdata = trim(`$snmpdata_cmd`);
$rrdupdate = "N";
@@ -31,8 +32,6 @@ foreach(explode("\n", $snmpdata) as $data) {
$rrdupdate .= ":$data";
}
echo("\n$rrdfile $rrdupdate\n");
rrd_update($rrdfile, $rrdupdate);
rrd_error();

View File

@@ -1,17 +1,19 @@
<?
$query = "SELECT * FROM temperature AS T temp_host = '" . $device[id] . "'";
$query = "SELECT * FROM temperature WHERE temp_host = '" . $device['device_id'] . "'";
$temp_data = mysql_query($query);
while($temperature = mysql_fetch_array($temp_data)) {
$community = $temperature[community];
$hostname = $temperature[hostname];
$snmpver = $temperature[snmpver];
$temp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $temperature['temp_oid'];
echo($temp_cmd);
$temp = `$temp_cmd`;
$temprrd = "rrd/" . $temperature[hostname] . "-temp" . $temperature[temp_id] . ".rrd";
$temprrd = "rrd/" . $device[hostname] . "-temp-" . $temperature[temp_id] . ".rrd";
$temprrdold = "rrd/" . $device[hostname] . "-temp" . $temperature[temp_id] . ".rrd";
if (is_file($temprrdold)) {
rename($temprrdold, $temprrd);
}
if (!is_file($temprrd)) {
`rrdtool create $temprrd \
--step 300 \

View File

@@ -6,7 +6,7 @@ function pollDeviceHP() {
global $device;
global $community;
$id = $device['id'];
$id = $device['device_id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];

View File

@@ -7,7 +7,7 @@ function pollDeviceSNOM() {
global $device;
global $community;
$snmpver = $device['snmpver'];
$id = $device['id'];
$id = $device['device_id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];

View File

@@ -2,194 +2,3 @@
include("unix-graphing.php");
function pollDeviceUnix() {
global $device;
global $community;
global $rrdtool;
$id = $device['id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
$features = $device['features'];
if($device['apache'] == "1") { $apache = "yes"; }
$loadrrd = "rrd/" . $hostname . "-load.rrd";
$loadgraph = "public_html/graphs/" . $hostname . "-load.png";
$cpurrd = "rrd/" . $hostname . "-cpu.rrd";
$cpugraph = "public_html/graphs/" . $hostname . "-cpu.png";
$memrrd = "rrd/" . $hostname . "-mem.rrd";
$memgraph = "public_html/graphs/" . $hostname . "-mem.png";
$sysrrd = "rrd/" . $hostname . "-sys.rrd";
$sysgraph = "public_html/graphs/" . $hostname . "-sys.png";
## Check Disks
$dq = mysql_query("SELECT * FROM storage WHERE host_id = '$id'");
while ($dr = mysql_fetch_array($dq)) {
$hrStorageIndex = $dr['hrStorageIndex'];
$hrStorageAllocationUnits = $dr['hrStorageAllocationUnits'];
$hrStorageSize = $dr['hrStorageAllocationUnits'] * $dr['hrStorageSize'];
$hrStorageDescr = $dr['hrStorageDescr'];
$used = `snmpget -O qv -v2c -c $community $hostname hrStorageUsed.$hrStorageIndex`;
$used = $used * $hrStorageAllocationUnits;
$perc = $used / $hrStorageSize * 100;
$filedesc = str_replace("\"", "", str_replace("/", "_", $hrStorageDescr));
$storerrd = "rrd/" . $hostname . "-storage-" . $filedesc . ".rrd";
if (!is_file($storerrd)) {
`rrdtool create $storerrd \
--step 300 \
DS:size:GAUGE:600:0:U \
DS:used:GAUGE:600:0:U \
DS:perc:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
rrd_update($storerrd, "N:$hrStorageSize:$used:$perc");
}
## Set OIDs
$oid_ssCpuRawUser = ".1.3.6.1.4.1.2021.11.50.0";
$oid_ssCpuRawNice = ".1.3.6.1.4.1.2021.11.51.0";
$oid_ssCpuRawSystem = ".1.3.6.1.4.1.2021.11.52.0";
$oid_ssCpuRawIdle = ".1.3.6.1.4.1.2021.11.53.0";
$oid_hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0";
$oid_hrSystemNumUsers = ".1.3.6.1.2.1.25.1.5.0";
$s = `snmpget -O qv -v2c -c $community $hostname $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers .1.3.6.1.4.1.2021.1.101.1`;
list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users, $cputemp) = explode("\n", $s);
## Create CPU RRD if it doesn't already exist
if (!is_file($cpurrd)) {
`rrdtool create $cpurrd \
--step 300 \
DS:user:COUNTER:600:0:U \
DS:system:COUNTER:600:0:U \
DS:nice:COUNTER:600:0:U \
DS:idle:COUNTER:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
rrd_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
## If the device isn't monowall or pfsense, monitor all the pretty things
if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSense" ) {
if (!is_file($sysrrd)) {
`rrdtool create $sysrrd \
--step 300 \
DS:users:GAUGE:600:0:U \
DS:procs:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
if (!is_file($memrrd)) {
`rrdtool create $memrrd \
--step 300 \
DS:totalswap:GAUGE:600:0:10000000000 \
DS:availswap:GAUGE:600:0:10000000000 \
DS:totalreal:GAUGE:600:0:10000000000 \
DS:availreal:GAUGE:600:0:10000000000 \
DS:totalfree:GAUGE:600:0:10000000000 \
DS:shared:GAUGE:600:0:10000000000 \
DS:buffered:GAUGE:600:0:10000000000 \
DS:cached:GAUGE:600:0:10000000000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
if(!is_file($loadrrd)) {
`$rrdtool create $loadrrd \
--step 300 \
DS:1min:GAUGE:600:0:5000 \
DS:5min:GAUGE:600:0:5000 \
DS:15min:GAUGE:600:0:5000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:800 \
RRA:AVERAGE:0.5:24:800 \
RRA:AVERAGE:0.5:288:800 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:800 \
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
$mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0";
$mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`;
list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", $mem_raw);
$load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3";
$load_raw = `snmpget -O qv -v2c -c $community $hostname $load_get`;
list ($load1, $load5, $load10) = explode ("\n", $load_raw);
rrd_update($sysrrd, "N:$users:$procs");
rrd_update($loadrrd, "N:$load1:$load5:$load10");
rrd_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached");
if($device['temp'] = 1) {
$temprrd = "rrd/" . $hostname . "-temp.rrd";
$cputemp = str_replace("\"", "", $cputemp);
if (!is_file($temprrd)) {
$rrdcreate = `rrdtool create $temprrd --step 300 \
DS:cputemp:GAUGE:600:-25:125 \
DS:systemp:GAUGE:600:-25:125 \
RRA:AVERAGE:0.5:1:2000 \
RRA:AVERAGE:0.5:6:2000 \
RRA:AVERAGE:0.5:24:2000 \
RRA:AVERAGE:0.5:288:2000 \
RRA:MAX:0.5:1:2000 \
RRA:MAX:0.5:6:2000 \
RRA:MAX:0.5:24:2000 \
RRA:MAX:0.5:288:2000`;
}
rrd_update($temprrd, "N:$cputemp:0");
}
if($apache) {
$apacherrd = "rrd/" . $hostname . "-apache.rrd";
if(!is_file($apacherrd)) {
$woo= `rrdtool create $apacherrd \
DS:bits:COUNTER:600:U:10000000 \
DS:hits:COUNTER:600:U:10000000 \
RRA:AVERAGE:0.5:1:800 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MAX:0.5:1:800 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797`;
}
list($ahits,$abits) = explode("\n", `./get-apache.sh $hostname`);
$abits = $abits * 8;
rrd_update($apacherrd,"N:$abits:$ahits");
}
} // End Monowall Test
}

View File

@@ -5,7 +5,7 @@ function pollDeviceWin() {
global $device;
global $community;
global $rrdtool;
$id = $device['id'];
$id = $device['device_id'];
$hostname = $device['hostname'];
$hardware = $device['hardware'];
$version = $device['version'];
@@ -23,7 +23,9 @@ function pollDeviceWin() {
$oid_hrSystemProcesses = ".1.3.6.1.2.1.25.1.6.0";
$oid_hrSystemNumUsers = ".1.3.6.1.2.1.25.1.5.0";
$s = `snmpget -O qv -v2c -c $community $hostname $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers`;
$s_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$s_cmd .= " $oid_ssCpuRawUser $oid_ssCpuRawSystem $oid_ssCpuRawNice $oid_ssCpuRawIdle $oid_hrSystemProcesses $oid_hrSystemNumUsers";
$s = `$s_cmd`;
list ($cpuUser, $cpuSystem, $cpuNice, $cpuIdle, $procs, $users) = explode("\n", $s);
if (!is_file($cpurrd)) {
@@ -96,11 +98,13 @@ function pollDeviceWin() {
}
$mem_get = "memTotalSwap.0 memAvailSwap.0 memTotalReal.0 memAvailReal.0 memTotalFree.0 memShared.0 memBuffer.0 memCached.0";
$mem_raw = `snmpget -O qv -v2c -c $community $hostname $mem_get`;
$mem_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $mem_get;
$mem_raw = `$mem_cmd`;
list($memTotalSwap, $memAvailSwap, $memTotalReal, $memAvailReal, $memTotalFree, $memShared, $memBuffer, $memCached) = explode("\n", $mem_raw);
$load_get = "laLoadInt.1 laLoadInt.2 laLoadInt.3";
$load_raw = `snmpget -O qv -v2c -c $community $hostname $load_get`;
$load_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " " . $load_get;
$load_raw = `$load_cmd`;
list ($load1, $load5, $load10) = explode ("\n", $load_raw);
rrd_update($sysrrd, "N:$users:$procs");

View File

@@ -4,34 +4,29 @@
include("config.php");
include("includes/functions.php");
$device_query = mysql_query("SELECT * FROM `devices` WHERE `id` like '%$argv[1]' AND `ignore` = '0' ORDER BY `id` ASC");
$device_query = mysql_query("SELECT * FROM `devices` WHERE `device_id` like '%$argv[1]' AND `ignore` = '0' ORDER BY `device_id` ASC");
while ($device = mysql_fetch_array($device_query)) {
$hostname = $device['hostname'];
$id = $device['id'];
$status = $device['status'];
$community = $device['community'];
$snmpver = $device['snmpver'];
unset($update); unset($update_query); unset($seperator); unset($newversion); unset($newuptime); unset($newfeatures);
unset($newlocation); unset($newhardware);
$pingable = isPingable($hostname);
$pingable = isPingable($device['hostname']);
$snmpable = FALSE;
if($pingable) {
$snmpable = isSNMPable($hostname, $community, $snmpver);
}
if ($pingable !== FALSE && $snmpable !== FALSE ) {
$newstatus = '1';
$hardware = $device['hardware'];
$version = $device['version'];
$old_rebooted = $device['rebooted'];
$features = $device['features'];
$location = $device['location'];
$old_sysDescr = $device['sysDescr'];
$os = $device['os'];
if($os == "FreeBSD" || $os == "OpenBSD" || $os == "Linux" || $os == "Windows") { $uptimeoid = ".1.3.6.1.2.1.25.1.1.0"; } else { $uptimeoid = "1.3.6.1.2.1.1.3.0"; }
if($device['monowall']) { $uptimeoid = ".1.3.6.1.2.1.1.3.0"; }
$snmp = "$uptimeoid sysLocation.0 .1.3.6.1.2.1.47.1.1.1.1.13.1 sysDescr.0";
$snmpdata = `snmpget -O qv -$snmpver -c $community $hostname $snmp | grep -v "Cisco Internetwork Operating System Software"`;
if($pingable) {
$snmpable = isSNMPable($device['hostname'], $device['community'], $device['snmpver']);
}
if ($pingable !== FALSE && $snmpable !== FALSE ) {
$status = '1';
if($device['os'] == "FreeBSD" || $device['os'] == "OpenBSD" || $device['os'] == "Linux" || $device['os'] == "Windows") {
$uptimeoid = ".1.3.6.1.2.1.25.1.1.0";
} else {
$uptimeoid = "1.3.6.1.2.1.1.3.0";
}
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$snmp_cmd .= " $uptimeoid sysLocation.0 .1.3.6.1.2.1.47.1.1.1.1.13.1 sysDescr.0";
$snmp_cmd .= " | grep -v 'Cisco Internetwork Operating System Software'";
$snmpdata = `$snmp_cmd`;
$snmpdata = preg_replace("/^.*IOS/","", $snmpdata);
$snmpdata = trim($snmpdata);
list($sysUptime, $sysLocation, $ciscomodel, $sysDescr) = explode("\n", $snmpdata);
@@ -45,7 +40,7 @@ while ($device = mysql_fetch_array($device_query)) {
$secs = $secs + ($mins * 60);
$newuptime = $secs;
switch ($os) {
switch ($device['os']) {
case "FreeBSD":
case "DragonFly":
case "OpenBSD":
@@ -54,39 +49,40 @@ while ($device = mysql_fetch_array($device_query)) {
case "Voswall":
case "NetBSD":
case "pfSense":
if($os == "FreeBSD") {
if($device['os'] == "FreeBSD") {
$sysDescr = str_replace(" 0 ", " ", $sysDescr);
list(,,$newversion) = explode (" ", $sysDescr);
$newhardware = "i386";
$newfeatures = "GENERIC";
} elseif($os == "DragonFly") {
} elseif($device['os'] == "DragonFly") {
list(,,$newversion,,,$newfeatures,,$newhardware) = explode (" ", $sysDescr);
} elseif($os == "NetBSD") {
} elseif($device['os'] == "NetBSD") {
list(,,$newversion,,,$newfeatures) = explode (" ", $sysDescr);
$newfeatures = str_replace("(", "", $newfeatures);
$newfeatures = str_replace(")", "", $newfeatures);
list(,,$newhardware) = explode ("$newfeatures", $sysDescr);
} elseif($os == "OpenBSD") {
} elseif($device['os'] == "OpenBSD") {
list(,,$newversion,$newfeatures,$newhardware) = explode (" ", $sysDescr);
$newfeatures = str_replace("(", "", $newfeatures);
$newfeatures = str_replace(")", "", $newfeatures);
} elseif($os == "m0n0wall" || $os == "Voswall") {
} elseif($device['os'] == "m0n0wall" || $device['os'] == "Voswall") {
list(,,$newversion,$newhardware,$freebsda, $freebsdb, $arch) = split(" ", $sysDescr);
$newfeatures = $freebsda . " " . $freebsdb;
$newhardware = "$newhardware ($arch)";
$newhardware = str_replace("\"", "", $newhardware);
} elseif ($os == "Linux") {
} elseif ($device['os'] == "Linux") {
list(,,$newversion) = explode (" ", $sysDescr);
if(strstr($sysDescr, "386")|| strstr($sysDescr, "486")||strstr($sysDescr, "586")||strstr($sysDescr, "686")) { $newhardware = "Generic x86"; }
# list($newversion,$newfeatures,$newfeaturesb) = explode("-", $newversion);
$newfeatures = `snmpget -O qv -$snmpver -c $community $hostname .1.3.6.1.4.1.2021.7890.1.101.1`;
$cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " .1.3.6.1.4.1.2021.7890.1.101.1";
$newfeatures = `$cmd`;
$newfeatures = str_replace("No Such Object available on this agent at this OID", "", $newfeatures);
$newfeatures = str_replace("\"", "", $newfeatures);
}
pollDeviceUnix();
include("includes/polling/device-unix.inc.php");
break;
case "Windows":
if($os == "Windows") {
if($device['os'] == "Windows") {
if(strstr($sysDescr, "x86")) { $newhardware = "Generic x86"; }
if(strstr($sysDescr, "Windows Version 5.2")) { $newversion = "2003 Server"; }
if(strstr($sysDescr, "Uniprocessor Free")) { $newfeatures = "Uniprocessor"; }
@@ -95,7 +91,7 @@ while ($device = mysql_fetch_array($device_query)) {
pollDeviceWin();
break;
case "IOS":
if ($os == "IOS") {
if ($device['os'] == "IOS") {
$newversion = str_replace("Cisco IOS Software,", "", $sysDescr);
$newversion = str_replace("IOS (tm) ", "", $newversion);
$newversion = str_replace(",RELEASE SOFTWARE", "", $newversion);
@@ -132,7 +128,8 @@ while ($device = mysql_fetch_array($device_query)) {
pollDeviceHP();
break;
case "Snom":
$sysDescr = `snmpget -Oqv -$snmpver -c $community $hostname 1.3.6.1.2.1.7526.2.4`;
$cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " 1.3.6.1.2.1.7526.2.4";
$sysDescr = `$cmd`;
$sysDescr = str_replace("-", " ", $sysDescr);
$sysDescr = str_replace("\"", "", $sysDescr);
list($newhardware, $newfeatures, $newversion) = explode(" ", $sysDescr);
@@ -144,55 +141,54 @@ while ($device = mysql_fetch_array($device_query)) {
$newlocation = str_replace("\"","", $sysLocation);
include("includes/polling/temperatures.inc.php");
include("includes/polling/device-netstats.inc.php");
} else {
$newstatus = '0';
}
if ( $sysDescr && $sysDescr != $old_sysDescr ) {
if ( $sysDescr && $sysDescr != $device['sysDescr'] ) {
$update = "`sysDescr` = '$sysDescr'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'New sysDescr - $sysDescr')");
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'sysDescr -> $sysDescr')");
}
if ( $newlocation && $location != $newlocation ) {
if ( $newlocation && $device['location'] != $newlocation ) {
$update = "`location` = '$newlocation'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed location from $location to $newlocation')");
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Location -> $newlocation')");
}
if ( $newversion && $version != $newversion ) {
if ( $newversion && $device['version'] != $newversion ) {
$update .= $seperator . "`version` = '$newversion'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed version from $version to $newversion')");
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Version -> $newversion')");
}
if ( $newfeatures && $newfeatures != $features ) {
if ( $newfeatures && $newfeatures != $device['features'] ) {
$update .= $seperator . "`features` = '$newfeatures'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed features from $features to $newfeatures')");
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'OS Features -> $newfeatures')");
}
if ( $newhardware && $newhardware != $hardware ) {
if ( $newhardware && $newhardware != $device['hardware'] ) {
$update .= $seperator . "`hardware` = '$newhardware'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Changed hardware from $hardware to $newhardware')");
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Hardware -> $newhardware')");
}
if( $status != $newstatus ) {
if( $device['status'] != $newstatus ) {
$update .= $seperator . "`status` = '$newstatus'";
$seperator = ", ";
if ($newstatus == '1') { $stat = "Up";
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '$id', 'Device is up\n')");
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('0', '" . $device['device_id'] . "', 'Device is up\n')");
} else {
$stat = "Down";
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '$id', 'Device is down\n')");
mysql_query("INSERT INTO alerts (importance, device_id, message) VALUES ('9', '" . $device['device_id'] . "', 'Device is down\n')");
}
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('$id', NULL, NOW(), 'Device status changed to $stat')");
mysql_query("INSERT INTO eventlog (host, interface, datetime, message) VALUES ('" . $device['device_id'] . "', NULL, NOW(), 'Device status changed to $stat')");
}
if ($newuptime) {
echo("Uptime : $newuptime\n");
$uptimerrd = "rrd/" . $hostname . "-uptime.rrd";
$uptimerrd = "rrd/" . $device['hostname'] . "-uptime.rrd";
if(!is_file($uptimerrd)) {
$woo = `rrdtool create $uptimerrd \
DS:uptime:GAUGE:600:0:U \
@@ -203,9 +199,9 @@ while ($device = mysql_fetch_array($device_query)) {
}
rrd_update($uptimerrd, "N:$newuptime");
$update_uptime_attrib = mysql_query("UPDATE devices_attribs SET attrib_value = '$newuptime' WHERE `device_id` = '$id' AND `attrib_type` = 'uptime'");
$update_uptime_attrib = mysql_query("UPDATE devices_attribs SET attrib_value = '$newuptime' WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'");
if(mysql_affected_rows() == '0') {
$insert_uptime_attrib = mysql_query("INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('$id', 'uptime', '$newuptime')");
$insert_uptime_attrib = mysql_query("INSERT INTO devices_attribs (`device_id`, `attrib_type`, `attrib_value`) VALUES ('" . $device['device_id'] . "', 'uptime', '$newuptime')");
}
}
@@ -213,11 +209,11 @@ while ($device = mysql_fetch_array($device_query)) {
if ($update) {
$update_query = "UPDATE `devices` SET ";
$update_query .= $update;
$update_query .= " WHERE `id` = '$id'";
echo("Updating $hostname\n$update_query\n\n");
$update_query .= " WHERE `id` = '" . $device['device_id'] . "'";
echo("Updating " . $device['hostname'] . "\n" . $update_query . "\n\n");
$update_result = mysql_query($update_query);
} else {
echo("No Changes to $hostname \n\n");
echo("No Changes to " . $device['hostname'] . "\n\n");
}
}

View File

@@ -7,7 +7,7 @@ include("includes/functions.php");
$interface_query = mysql_query("SELECT * FROM `interfaces`");
while ($interface = mysql_fetch_array($interface_query)) {
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE id = '" . $interface['device_id'] . "'"));
$device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_id = '" . $interface['device_id'] . "'"));
if($device['status'] == '1') {
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " ifName." . $interface['ifIndex'];
@@ -15,8 +15,6 @@ while ($interface = mysql_fetch_array($interface_query)) {
$snmp_cmd .= "ifAlias." . $interface['ifIndex'] . " ifSpeed." . $interface['ifIndex'] . " 1.3.6.1.2.1.10.7.2.1." . $interface['ifIndex'];
$snmp_cmd .= " ifType." . $interface['ifIndex'] . " ifMtu." . $interface['ifIndex'] . " ifPhysAddress." . $interface['ifIndex'];
echo($snmp_cmd);
$snmp_output = trim(`$snmp_cmd`);
$snmp_output = str_replace("No Such Object available on this agent at this OID", "", $snmp_output);
$snmp_output = str_replace("No Such Instance currently exists at this OID", "", $snmp_output);