mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
git-svn-id: http://www.observium.org/svn/observer/trunk@2301 61d68cd4-352d-0410-923a-c4978735b2b8
113 lines
3.6 KiB
PHP
Executable File
113 lines
3.6 KiB
PHP
Executable File
#!/usr/bin/env php
|
|
<?php
|
|
|
|
include("includes/defaults.inc.php");
|
|
include("config.php");
|
|
include("includes/functions.php");
|
|
|
|
$iter = "0";
|
|
|
|
echo("Starting Polling Session ... \n\n");
|
|
|
|
foreach (dbFetchRows("SELECT * FROM `bills`") as $bill_data)
|
|
{
|
|
echo("Bill : ".$bill_data['bill_name']."\n");
|
|
CollectData($bill_data['bill_id']);
|
|
$iter++;
|
|
}
|
|
|
|
function CollectData($bill_id)
|
|
{
|
|
foreach (dbFetchRows("SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.interface_id = P.port_id AND D.device_id = I.device_id", array($bill_id)) as $port_data)
|
|
{
|
|
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'];
|
|
$port = $port_data['port'];
|
|
|
|
echo("\nPolling ".$port_data['ifDescr']." on ".$port_data['hostname']."\n");
|
|
|
|
$port_in_measurement = getValue($host, $port, $port_data['ifIndex'], "In");
|
|
$port_out_measurement = getValue($host, $port, $port_data['ifIndex'], "Out");
|
|
|
|
$now = dbFetchCell("SELECT NOW()");
|
|
|
|
$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';
|
|
}
|
|
dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_in_measurement, 'delta' => $port_in_delta), 'port_in_measurements');
|
|
|
|
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';
|
|
}
|
|
dbInsert(array('port_id' => $port_id, 'timestamp' => $now, 'counter' => $port_out_measurement, 'delta' => $port_out_delta), 'port_out_measurements');
|
|
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 = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('".mres($prev_timestamp)."')");
|
|
} 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;
|
|
|
|
}
|
|
dbInsert(array('bill_id' => $bill_id, 'timestamp' => $now, 'period' => $period, 'delta' => $delta, 'in_delta' => $in_delta, 'out_delta' => $out_delta), 'bill_data');
|
|
}
|
|
|
|
if ($argv[1]) { CollectData($argv[1]); }
|
|
|
|
?>
|