Skip to content

Commit

Permalink
Added cli options debug and bill_id to poll-billing.php (librenms#9042)
Browse files Browse the repository at this point in the history
DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
  • Loading branch information
murrant authored and laf committed Aug 25, 2018
1 parent b74fcdd commit a60dda8
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions poll-billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,39 @@
* @copyright (C) 2006 - 2012 Adam Armstrong
*/

// FIXME - implement cli switches, debugging, etc.
$init_modules = array();
require __DIR__ . '/includes/init.php';

$iter = '0';

rrdtool_initialize();
if (isset($argv[1]) && is_numeric($argv[1])) {
// allow old cli style
$options = ['b' => $argv[1]];
} else {
$options = getopt('db:');
}

$poller_start = microtime(true);
echo "Starting Polling Session ... \n\n";
set_debug(isset($options['d']));

// Wait for schema update, as running during update can break update
$dbVersion = get_db_schema();
if ($dbVersion < 107) {
if (get_db_schema() < 107) {
logfile("BILLING: Cannot continue until the database schema update to >= 107 is complete");
exit(1);
}

foreach (dbFetchRows('SELECT * FROM `bills`') as $bill_data) {
echo 'Bill : '.$bill_data['bill_name']."\n";
rrdtool_initialize();

$poller_start = microtime(true);
echo "Starting Polling Session ... \n\n";

// replace old bill_gb with bill_quota (we're now storing bytes, not gigabytes)
if ($bill_data['bill_type'] == 'quota' && !is_numeric($bill_data['bill_quota'])) {
$bill_data['bill_quota'] = ($bill_data['bill_gb'] * $config['billing']['base'] * $config['billing']['base']);
dbUpdate(array('bill_quota' => $bill_data['bill_quota']), 'bills', '`bill_id` = ?', array($bill_data['bill_id']));
echo 'Quota -> '.$bill_data['bill_quota'];
}
$query = \LibreNMS\DB\Eloquent::DB()->table('bills');

CollectData($bill_data['bill_id']);
$iter++;
if (isset($options['b'])) {
$query->where('bill_id', $options['b']);
}

foreach ($query->get(['bill_id', 'bill_name']) as $bill) {
echo 'Bill : '.$bill->bill_name."\n";
$bill_id = $bill->bill_id;

function CollectData($bill_id)
{
$port_list = dbFetchRows('SELECT * FROM `bill_ports` as P, `ports` as I, `devices` as D WHERE P.bill_id=? AND I.port_id = P.port_id AND D.device_id = I.device_id', array($bill_id));

$now = dbFetchCell('SELECT NOW()');
Expand Down Expand Up @@ -134,10 +132,6 @@ function CollectData($bill_id)
}//end CollectData()


if ($argv[1]) {
CollectData($argv[1]);
}

$poller_end = microtime(true);
$poller_run = ($poller_end - $poller_start);
$poller_time = substr($poller_run, 0, 5);
Expand Down

0 comments on commit a60dda8

Please sign in to comment.