Fixing lots of bugs and fixing billing

git-svn-id: http://www.observium.org/svn/observer/trunk@129 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2008-03-09 21:13:27 +00:00
parent 062a0399bd
commit ab77b6e2f1
16 changed files with 288 additions and 61 deletions

View File

@@ -10,6 +10,10 @@ include("graphing.php");
include("print-functions.php");
include("billing-functions.php");
function rrdtool_update($rrdfile, $rrdupdate) {
global $rrdtool;
return `$rrdtool update $rrdfile $rrdupdate`;
}
function strgen ($length = 8)
{
@@ -542,7 +546,7 @@ function createHost ($host, $community, $snmpver){
$host_os = getHostOS($host, $community, $snmpver);
global $valid_os;
$nullhost = 1;
echo("$host -> $host_os<br />");
#echo("$host -> $host_os<br />");
foreach($valid_os as $os) {
if ($os == $host_os) {
$nullhost = '0';
@@ -550,9 +554,9 @@ function createHost ($host, $community, $snmpver){
}
if($nullhost == '0') {
$sql = mysql_query("INSERT INTO `devices` (`hostname`, `community`, `os`, `status`) VALUES ('$host', '$community', '$host_os', '1')");
echo("Created host : $host\n");
return("Created host : $host ($host_os)");
} else {
echo("Not added bad host : $host\n");
return("Not added bad host : $host");
}
}

View File

@@ -30,7 +30,7 @@ if($device[os] != "Snom") {
if(strstr($data, "No") || strstr($data, "d") || strstr($data, "s")) { $data = ""; }
$rrdupdate .= ":$data";
}
rrd_update($rrdfile, $rrdupdate);
rrdtool_update($rrdfile, $rrdupdate);
}
?>

View File

@@ -44,6 +44,6 @@
}
$rrdupdate = "N:$rxbytes:$txbytes:$rxpkts:$rxbytes:$calls:$registrations";
$ret = rrd_update("$rrdfile", $rrdupdate);
$ret = rrdtool_update("$rrdfile", $rrdupdate);
?>

View File

@@ -34,7 +34,7 @@ while ($dr = mysql_fetch_array($dq)) {
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
rrd_update($storerrd, "N:$hrStorageSize:$used:$perc");
rrdtool_update($storerrd, "N:$hrStorageSize:$used:$perc");
mysql_query("UPDATE `storage` SET `hrStorageUsed` = '$used_units', `storage_perc` = '$perc' WHERE storage_id = '" . $dr['storage_id'] . "'");
if($dr['storage_perc'] < '40' && $perc >= '40') {
@@ -97,7 +97,7 @@ if (!is_file($cpurrd)) {
RRA:MAX:0.5:24:800 \
RRA:MAX:0.5:288:800`;
}
rrd_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
rrdtool_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
## If the device isn't monowall or pfsense, monitor all the pretty things
@@ -164,9 +164,9 @@ if($device[os] != "m0n0wall" && $device[os] != "Voswall" && $device[os] != "pfSe
$load_raw = `$load_cmd`;
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");
rrdtool_update($sysrrd, "N:$users:$procs");
rrdtool_update($loadrrd, "N:$load1:$load5:$load10");
rrdtool_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached");
if($device['courier']) {
include("includes/polling/courierstats.inc.php");

View File

@@ -0,0 +1,116 @@
<?
$interface_query = mysql_query("SELECT * FROM `interfaces` $where");
while ($interface = mysql_fetch_array($interface_query)) {
if(!$device) { $device = mysql_fetch_array(mysql_query("SELECT * FROM `devices` WHERE device_id = '" . $interface['device_id'] . "'")); }
unset($ifAdminStatus, $ifOperStatus, $ifAlias, $ifDescr);
$interface['hostname'] = $device['hostname'];
$interface['device_id'] = $device['device_id'];
if($device['status'] == '1') {
unset($update);
unset($update_query);
unset($seperator);
echo("Looking at " . $interface['ifDescr'] . " on " . $device['hostname'] . "\n");
$snmp_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$snmp_cmd .= " ifAdminStatus." . $interface['ifIndex'] . " ifOperStatus." . $interface['ifIndex'] . " ifAlias." . $interface['ifIndex'];
$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);
$snmp_output = str_replace("\"", "", $snmp_output);
list($ifAdminStatus, $ifOperStatus, $ifAlias) = explode("\n", $snmp_output);
if ($ifAlias == " ") { $ifAlias = str_replace(" ", "", $ifAlias); }
$ifAlias = trim(str_replace("\"", "", $ifAlias));
$ifAlias = trim($ifAlias);
$rrdfile = "rrd/" . $device['hostname'] . "." . $interface['ifIndex'] . ".rrd";
if(!is_file($rrdfile)) {
$woo = `rrdtool create $rrdfile \
DS:INOCTETS:COUNTER:600:U:100000000000 \
DS:OUTOCTETS:COUNTER:600:U:10000000000 \
DS:INERRORS:COUNTER:600:U:10000000000 \
DS:OUTERRORS:COUNTER:600:U:10000000000 \
DS:INUCASTPKTS:COUNTER:600:U:10000000000 \
DS:OUTUCASTPKTS:COUNTER:600:U:10000000000 \
DS:INNUCASTPKTS:COUNTER:600:U:10000000000 \
DS:OUTNUCASTPKTS:COUNTER:600:U:10000000000 \
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 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797`;
}
if ( $interface['ifAlias'] != $ifAlias ) {
$update .= $seperator . "`ifAlias` = '$ifAlias'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Desc -> $ifAlias')");
}
if ( $interface['ifOperStatus'] != $ifOperStatus && $ifOperStatus != "" ) {
$update .= $seperator . "`ifOperStatus` = '$ifOperStatus'";
$seperator = ", ";
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface went $ifOperStatus')");
}
if ( $interface['ifAdminStatus'] != $ifAdminStatus && $ifAdminStatus != "" ) {
$update .= $seperator . "`ifAdminStatus` = '$ifAdminStatus'";
$seperator = ", ";
if($ifAdminStatus == "up") { $admin = "enabled"; } else { $admin = "disabled"; }
mysql_query("INSERT INTO eventlog (`host`, `interface`, `datetime`, `message`) VALUES ('" . $interface['device_id'] . "', '" . $interface['interface_id'] . "', NOW(), 'Interface $admin')");
}
if ($update) {
$update_query = "UPDATE `interfaces` SET ";
$update_query .= $update;
$update_query .= " WHERE `interface_id` = '" . $interface['interface_id'] . "'";
echo("Updating : " . $device['hostname'] . " $ifDescr\nSQL :$update_query\n\n");
$update_result = mysql_query($update_query);
} else {
# echo("Not Updating : " . $device['hostname'] ." $ifDescr ( " . $interface['ifDescr'] . " )\n\n");
}
if($ifOperStatus == "up") {
$snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$snmp_data_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$snmp_data_cmd .= " ifHCInOctets." . $interface['ifIndex'] . " ifHCOutOctets." . $interface['ifIndex'] . " ifInErrors." . $interface['ifIndex'];
$snmp_data_cmd .= " ifOutErrors." . $interface['ifIndex'] . " ifInUcastPkts." . $interface['ifIndex'] . " ifOutUcastPkts." . $interface['ifIndex'];
$snmp_data_cmd .= " ifInNUcastPkts." . $interface['ifIndex'] . " ifOutNUcastPkts." . $interface['ifIndex'];
$snmp_data = `$snmp_data_cmd`;
$snmp_data = str_replace("Wrong Type (should be Counter32): ","", $snmp_data);
$snmp_data = str_replace("No Such Instance currently exists at this OID","", $snmp_data);
list($ifHCInOctets, $ifHCOutOctets, $ifInErrors, $ifOutErrors, $ifInUcastPkts, $ifOutUcastPkts, $ifInNUcastPkts, $ifOutNUcastPkts) = explode("\n", $snmp_data);
if($ifHCInOctets == "" || strpos($ifHCInOctets, "No") !== FALSE ) {
$octets_cmd = "snmpget -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'];
$octets_cmd .= " ifInOctets." . $interface['ifIndex'] . " ifOutOctets." . $interface['ifIndex'];
$octets = `$octets_cmd`;
list ($ifHCInOctets, $ifHCOutOctets) = explode("\n", $octets);
}
$woo = "N:$ifHCInOctets:$ifHCOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts";
$ret = rrdtool_update("$rrdfile", $woo);
} else {
echo("Interface " . $device['hostname'] . " " . $interface['ifDescr'] . " is down\n");
}
}
$rates = interface_rates ($interface);
mysql_query("UPDATE `interfaces` SET in_rate = '" . $rates['in'] . "', out_rate = '" . $rates['out'] . "' WHERE interface_id= '" . $interface['interface_id'] . "'");
}
?>

View File

@@ -42,7 +42,7 @@ function pollDeviceSNOM() {
}
$rrdupdate = "N:$rxbytes:$txbytes:$rxpkts:$rxbytes:$calls:$registrations";
$ret = rrd_update("$rrdfile", $rrdupdate);
$ret = rrdtool_update("$rrdfile", $rrdupdate);
}

View File

@@ -107,10 +107,10 @@ function pollDeviceWin() {
$load_raw = `$load_cmd`;
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");
rrd_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
rrdtool_update($sysrrd, "N:$users:$procs");
rrdtool_update($loadrrd, "N:$load1:$load5:$load10");
rrdtool_update($memrrd, "N:$memTotalSwap:$memAvailSwap:$memTotalReal:$memAvailReal:$memTotalFree:$memShared:$memBuffer:$memCached");
rrdtool_update($cpurrd, "N:$cpuUser:$cpuSystem:$cpuNice:$cpuIdle");
}
function memgraphWin ($rrd, $graph, $from="-2d")