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
+16 -36
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;
}
+7 -7
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°C";
$optsa[] = "GPRINT:temp$fs[temp_id]:MAX:%3.0lf°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°C";
$optsa[] = "GPRINT:temp" . $temperature[temp_id] . ":MAX:%3.0lf°C\l";
$iter++;
}
if($width <= "300") {$optsb = array("--font", "LEGEND:7:$mono_font",
+1 -1
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'];
+3 -4
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();
+8 -6
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 \
+1 -1
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'];
+1 -1
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'];
-191
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
}
+8 -4
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");