diff --git a/README b/README
index 4a4f7bc38..ae6e8503e 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
Copyright (C) 2007 Adam Armstrong
-Released under the GNU Public License
+Please see license.txt for usage requirements and restrictions.
Introduction
------------
@@ -20,7 +20,10 @@ Please see http://www.project-observer.org.
Changelog
---------
+Release 0.3.1 ( 30th November 2007 )
+Fixed a great many things and made it prettier!
+.. This release took so long that I've largely forgotten what's been changed. Again!
Release 0.3.0-pre1 ( 24th June 2007 )
Added VLAN features for cisco devices
diff --git a/check-services.php b/check-services.php
index 0c6784c26..b2d0bf31e 100755
--- a/check-services.php
+++ b/check-services.php
@@ -18,7 +18,6 @@ while ($service = mysql_fetch_array($query)) {
$status = "2";
$check = "Error : Script not found ($checker_script)";
}
-<<<<<<< .mine
if($service_status != $status) {
$updated = ", `service_changed` = '" . time() . "' ";
if($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; }
@@ -32,23 +31,6 @@ while ($service = mysql_fetch_array($query)) {
mail($email, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg, $config['email_headers']);
}
- } else { unset($updated); }
- mysql_query("UPDATE `services` SET `service_status` = '$status', `service_message` = '$check', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '$service[service_id]'");
-=======
- if($service_status != $status) {
- $updated = ", `service_changed` = '" . time() . "' ";
- if($service['sysContact']) { $email = $service['sysContact']; } else { $email = $config['email_default']; }
- if($status == "1") {
- $msg = "Service Up: " . $service['service_type'] . " on " . $service['hostname'];
- $msg .= " at " . date('l dS F Y h:i:s A');
- mail($email, "Service Up: " . $service['service_type'] . " on " . $service['hostname'], $msg, $config['email_headers']);
- } elseif ($status == "0") {
- $msg = "Service Down: " . $service['service_type'] . " on " . $service['hostname'];
- $msg .= " at " . date('l dS F Y h:i:s A');
- mail($email, "Service Down: " . $service['service_type'] . " on " . $service['hostname'], $msg, $config['email_headers']);
- }
->>>>>>> .r121
-
} else { unset($updated); }
$update_sql = "UPDATE `services` SET `service_status` = '$status', `service_message` = '" . addslashes($check) . "', `service_checked` = '" . time() . "' $updated WHERE `service_id` = '" . $service['service_id']. "'";
mysql_query($update_sql);
diff --git a/cron.sh b/cron.sh
index 8865ed867..fa5995748 100755
--- a/cron.sh
+++ b/cron.sh
@@ -7,8 +7,4 @@
./check-services.php
#./alerts.php
-wget -O /var/sites/network.vostron.net/rrd/dill.vostron.net-mail_virus.rrd http://dill.vostron.net/rrd/mailgraph_virus.rrd
-wget -O /var/sites/network.vostron.net/rrd/dill.vostron.net-mail.rrd http://dill.vostron.net/rrd/mailgraph.rrd
-wget -O /var/sites/network.vostron.net/rrd/dill.vostron.net-courier.rrd http://dill.vostron.net/rrd/couriergraph.rrd
-
./poll-billing.php
diff --git a/html/includes/authenticate.inc b/html/includes/authenticate.inc
index 1403c7d4f..53fe64f28 100644
--- a/html/includes/authenticate.inc
+++ b/html/includes/authenticate.inc
@@ -21,8 +21,10 @@ if($_GET['logout']) {
$_SESSION['encrypted']=$_COOKIE['encrypted'];
}
+
$sql = "select username, level, user_id from users where username='" . $_SESSION['username'] . "' and password='" . $_SESSION['encrypted'] . "'";
- $row = mysql_fetch_row(mysql_query($sql));
+ $query = mysql_query($sql);
+ $row = mysql_fetch_row($query);
if ( $_SESSION['username'] != "" && $row[0] == $_SESSION['username'] ) {
$_SESSION['userlevel'] = $row[1];
diff --git a/html/pages/addhost.php b/html/pages/addhost.php
index 67d79d778..aee737e27 100644
--- a/html/pages/addhost.php
+++ b/html/pages/addhost.php
@@ -7,6 +7,8 @@ exit;
}
+echo("Add Device
");
+
if($_POST['hostname'] && $_POST['community']) {
if($_SESSION['userlevel'] > '5') {
$hostname = $_POST['hostname'];
@@ -14,7 +16,8 @@ if($_POST['hostname'] && $_POST['community']) {
$snmpver = $_POST['snmpver'];
echo("");
echo("Adding host $hostname community $community
");
- addHost($hostname, $community, $snmpver);
+ $result = addHost($hostname, $community, $snmpver);
+ echo("$result");
echo("
");
} else {
echo("Error: You don't have the necessary privileges to add hosts.
");
@@ -28,20 +31,28 @@ echo("Error: A hostname is required.
");
?>
diff --git a/html/pages/logon.inc b/html/pages/logon.inc
index 6f15a700f..6124148a0 100644
--- a/html/pages/logon.inc
+++ b/html/pages/logon.inc
@@ -23,9 +23,6 @@
|
-
- | Demo login : demo/demo |
-
diff --git a/includes/functions.php b/includes/functions.php
index 323db6ac3..61ae9f47e 100755
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -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
");
+ #echo("$host -> $host_os
");
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");
}
}
diff --git a/includes/polling/device-netstats.inc.php b/includes/polling/device-netstats.inc.php
index c71e15a11..aba8cb97b 100755
--- a/includes/polling/device-netstats.inc.php
+++ b/includes/polling/device-netstats.inc.php
@@ -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);
}
?>
diff --git a/includes/polling/device-snom.inc.php b/includes/polling/device-snom.inc.php
index 346e4948b..74aafdabb 100755
--- a/includes/polling/device-snom.inc.php
+++ b/includes/polling/device-snom.inc.php
@@ -44,6 +44,6 @@
}
$rrdupdate = "N:$rxbytes:$txbytes:$rxpkts:$rxbytes:$calls:$registrations";
- $ret = rrd_update("$rrdfile", $rrdupdate);
+ $ret = rrdtool_update("$rrdfile", $rrdupdate);
?>
diff --git a/includes/polling/device-unix.inc.php b/includes/polling/device-unix.inc.php
index e7b48b473..2aec2ca5c 100755
--- a/includes/polling/device-unix.inc.php
+++ b/includes/polling/device-unix.inc.php
@@ -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");
diff --git a/includes/polling/interfaces.inc.php b/includes/polling/interfaces.inc.php
new file mode 100644
index 000000000..1bf5e4105
--- /dev/null
+++ b/includes/polling/interfaces.inc.php
@@ -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'] . "'");
+
+}
+
+?>
+
diff --git a/includes/snom.php b/includes/snom.php
index 318a31e3c..7c5dc45a8 100755
--- a/includes/snom.php
+++ b/includes/snom.php
@@ -42,7 +42,7 @@ function pollDeviceSNOM() {
}
$rrdupdate = "N:$rxbytes:$txbytes:$rxpkts:$rxbytes:$calls:$registrations";
- $ret = rrd_update("$rrdfile", $rrdupdate);
+ $ret = rrdtool_update("$rrdfile", $rrdupdate);
}
diff --git a/includes/windows.php b/includes/windows.php
index 3dff5a1e2..a86eb1a17 100755
--- a/includes/windows.php
+++ b/includes/windows.php
@@ -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")
diff --git a/poll-billing.php b/poll-billing.php
new file mode 100644
index 000000000..a5ffc9993
--- /dev/null
+++ b/poll-billing.php
@@ -0,0 +1,116 @@
+#!/usr/bin/php
+ $last_port_in_measurement) {
+ $port_in_delta = $port_in_measurement - $last_port_in_measurement;
+ } else {
+ $port_in_delta = $last_port_in_delta;
+ }
+ } else {
+ $port_in_delta = '0';
+ }
+ $pim = "INSERT INTO port_in_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_in_measurement, $port_in_delta) ";
+ #echo("$pim \n");
+ $pim_query = mysql_query($pim);
+ unset($last_data, $last_port_in_measurement, $last_port_in_delta);
+
+ $last_data = getLastPortCounter($port_id,out);
+ if ($last_data[state] == "ok") {
+ $last_port_out_measurement = $last_data[counter];
+ $last_port_out_delta = $last_data[delta];
+ if ($port_out_measurement > $last_port_out_measurement) {
+ $port_out_delta = $port_out_measurement - $last_port_out_measurement;
+ } else {
+ $port_out_delta = $last_port_out_delta;
+ }
+ } else {
+ $port_out_delta = '0';
+ }
+ $pom = "INSERT INTO port_out_measurements (port_id,timestamp,counter,delta) VALUES ($port_id, '$now', $port_out_measurement, $port_out_delta) ";
+ #echo("$pom \n");
+ $pom_query = mysql_query($pom);
+ unset($last_data, $last_port_in_measurement, $last_port_in_delta);
+
+ $delta = $delta + $port_in_delta + $port_out_delta;
+ $in_delta = $in_delta + $port_in_delta;
+ $out_delta = $out_delta + $port_out_delta;
+ unset($port_in_delta,$port_out_delta,$prev_delta,$prev_timestamp,$period);
+
+ }
+ $last_data = getLastMeasurement($bill_id);
+
+ if ($last_data[state] == "ok") {
+ $prev_delta = $last_data[delta];
+ $prev_in_delta = $last_data[in_delta];
+ $prev_out_delta = $last_data[out_delta];
+ $prev_timestamp = $last_data[timestamp];
+ $period = mysql_result(mysql_query("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('$prev_timestamp')"),0);
+ } else {
+ $prev_delta = '0';
+ $period = '0';
+ $prev_in_delta = '0';
+ $prev_out_delta = '0';
+ }
+ if( $delta < '0' ) {
+ $delta = $prev_delta;
+ $in_delta = $prev_in_delta;
+ $out_delta = $prev_out_delta;
+ }
+ $insert_string = "INSERT INTO bill_data (bill_id,timestamp,period,delta,in_delta,out_delta) VALUES ('$bill_id','$now','$period','$delta','$in_delta','$out_delta')";
+ #echo("$insert_string\n");
+ $insert_measurement = mysql_query($insert_string);
+}
+
+if ($argv[1]) { CollectData($argv[1]); }
+
+
+?>
+
diff --git a/poll-device.php b/poll-device.php
index 715bcbec1..77ab6139d 100755
--- a/poll-device.php
+++ b/poll-device.php
@@ -258,7 +258,7 @@ while ($device = mysql_fetch_array($device_query)) {
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797`;
}
- rrd_update($uptimerrd, "N:$uptime");
+ rrdtool_update($uptimerrd, "N:$uptime");
$update_uptime_attrib = mysql_query("UPDATE devices_attribs SET attrib_value = '$uptime' WHERE `device_id` = '" . $device['device_id'] . "' AND `attrib_type` = 'uptime'");
if(mysql_affected_rows() == '0') {
diff --git a/poll-interface.php b/poll-interface.php
index 345e25184..8ed4640ca 100755
--- a/poll-interface.php
+++ b/poll-interface.php
@@ -105,7 +105,7 @@ while ($interface = mysql_fetch_array($interface_query)) {
list ($ifHCInOctets, $ifHCOutOctets) = explode("\n", $octets);
}
$woo = "N:$ifHCInOctets:$ifHCOutOctets:$ifInErrors:$ifOutErrors:$ifInUcastPkts:$ifOutUcastPkts:$ifInNUcastPkts:$ifOutNUcastPkts";
- $ret = rrd_update("$rrdfile", $woo);
+ $ret = rrdtool_update("$rrdfile", $woo);
} else {
echo("Interface " . $device['hostname'] . " " . $interface['ifDescr'] . " is down\n");
}