mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
5
README
5
README
@@ -1,6 +1,6 @@
|
||||
Copyright (C) 2007 Adam Armstrong <adama@project-observer.org>
|
||||
|
||||
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
|
||||
|
@@ -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);
|
||||
|
4
cron.sh
4
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
|
||||
|
@@ -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];
|
||||
|
@@ -7,6 +7,8 @@ exit;
|
||||
|
||||
}
|
||||
|
||||
echo("<h1>Add Device</h1>");
|
||||
|
||||
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("<p class='messagebox'>");
|
||||
echo("Adding host $hostname community $community</p>");
|
||||
addHost($hostname, $community, $snmpver);
|
||||
$result = addHost($hostname, $community, $snmpver);
|
||||
echo("$result");
|
||||
echo("</p>");
|
||||
} else {
|
||||
echo("<p class='errorbox'><b>Error:</b> You don't have the necessary privileges to add hosts.</p>");
|
||||
@@ -28,20 +31,28 @@ echo("<p class='errorbox'><b>Error:</b> A hostname is required.</p>");
|
||||
?>
|
||||
|
||||
<form name="form1" method="post" action="/?page=addhost">
|
||||
<h1>Add Host</h1>
|
||||
<br />
|
||||
<p>Hostname:
|
||||
<input type="text" name="hostname">
|
||||
<br>
|
||||
Community:
|
||||
<input type="text" name="community">
|
||||
<br>
|
||||
SNMP Version: <select name="snmpver">
|
||||
<option value="v1">v1</option>
|
||||
<option value="v2c">v2c</option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" name="Submit" value="Add Host">
|
||||
</p>
|
||||
<p>Devices will be checked for Ping and SNMP reachability before being probed. Only devices with recognised OSes will be added.</p>
|
||||
|
||||
<div style="padding: 10px; background: #f0f0f0;">
|
||||
<table cellpadding=2px>
|
||||
<tr>
|
||||
<td><strong>Hostname</strong></td>
|
||||
<td><input type="text" name="hostname" size="32"></td>
|
||||
</tr>
|
||||
<td><strong>Community</strong></td>
|
||||
<td><input type="text" name="community" size="32"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>SNMP Version</strong></td>
|
||||
<td><select name="snmpver">
|
||||
<option value="v1">v1</option>
|
||||
<option value="v2c" selected>v2c</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td><td><input type="submit" name="Submit" value="Add Host"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
|
@@ -23,9 +23,6 @@
|
||||
<tr>
|
||||
<td colspan=2 align='right'><input name='submit' type='submit' value='Login'></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan=2 align='right'>Demo login : demo/demo</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form></td>
|
||||
</tr>
|
||||
|
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -44,6 +44,6 @@
|
||||
}
|
||||
|
||||
$rrdupdate = "N:$rxbytes:$txbytes:$rxpkts:$rxbytes:$calls:$registrations";
|
||||
$ret = rrd_update("$rrdfile", $rrdupdate);
|
||||
$ret = rrdtool_update("$rrdfile", $rrdupdate);
|
||||
|
||||
?>
|
||||
|
@@ -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");
|
||||
|
116
includes/polling/interfaces.inc.php
Normal file
116
includes/polling/interfaces.inc.php
Normal 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'] . "'");
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -42,7 +42,7 @@ function pollDeviceSNOM() {
|
||||
}
|
||||
|
||||
$rrdupdate = "N:$rxbytes:$txbytes:$rxpkts:$rxbytes:$calls:$registrations";
|
||||
$ret = rrd_update("$rrdfile", $rrdupdate);
|
||||
$ret = rrdtool_update("$rrdfile", $rrdupdate);
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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")
|
||||
|
116
poll-billing.php
Normal file
116
poll-billing.php
Normal file
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
$debug = "1";
|
||||
|
||||
|
||||
include("config.php");
|
||||
include("includes/functions.php");
|
||||
|
||||
$iter = "0";
|
||||
|
||||
echo("Starting Polling Session ... \n\n");
|
||||
|
||||
$bill_query = mysql_query("select * from bills");
|
||||
while ($bill_data = mysql_fetch_array($bill_query)) {
|
||||
echo("Bill : ".$bill_data['bill_name']."\n");
|
||||
|
||||
CollectData($bill_data['bill_id']);
|
||||
|
||||
$iter++;
|
||||
}
|
||||
|
||||
function CollectData($bill_id) {
|
||||
$port_query = mysql_query("select * from bill_ports as P, interfaces as I, devices as D where P.bill_id='$bill_id' AND I.interface_id = P.port_id AND D.device_id = I.device_id");
|
||||
|
||||
while ($port_data = mysql_fetch_array($port_query)) {
|
||||
unset($port_in_measurement);
|
||||
unset($port_in_delta);
|
||||
unset($last_port_in_measurement);
|
||||
unset($last_port_in_delta);
|
||||
unset($port_out_measurement);
|
||||
unset($port_out_delta);
|
||||
unset($last_port_out_measurement);
|
||||
unset($last_port_out_delta);
|
||||
|
||||
$port_id = $port_data['port_id'];
|
||||
$host = $port_data['hostname'];
|
||||
|
||||
echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n");
|
||||
|
||||
$port_in_measurement = trim(getValue($host, $port_data['community'], $port_data['ifIndex'], "In"));
|
||||
$port_out_measurement = trim(getValue($host, $port_data['community'], $port_data['ifIndex'], "Out"));
|
||||
|
||||
echo("$port_in_measurement and $port_out_measurement \n");
|
||||
|
||||
$now = mysql_result(mysql_query("SELECT NOW()"), 0);
|
||||
|
||||
$last_data = getLastPortCounter($port_id,in);
|
||||
if ($last_data[state] == "ok") {
|
||||
$last_port_in_measurement = $last_data[counter];
|
||||
$last_port_in_delta = $last_data[delta];
|
||||
if ($port_in_measurement > $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]); }
|
||||
|
||||
|
||||
?>
|
||||
|
@@ -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') {
|
||||
|
@@ -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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user