Added cli options debug and bill_id to poll-billing.php (#9042)

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`
This commit is contained in:
Tony Murray 2018-08-25 15:57:08 -05:00 committed by Neil Lathwood
parent b74fcdd0a8
commit a60dda8217
1 changed files with 21 additions and 27 deletions

View File

@ -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';
if (isset($argv[1]) && is_numeric($argv[1])) {
// allow old cli style
$options = ['b' => $argv[1]];
} else {
$options = getopt('db:');
}
set_debug(isset($options['d']));
// Wait for schema update, as running during update can break update
if (get_db_schema() < 107) {
logfile("BILLING: Cannot continue until the database schema update to >= 107 is complete");
exit(1);
}
rrdtool_initialize();
$poller_start = microtime(true);
echo "Starting Polling Session ... \n\n";
// Wait for schema update, as running during update can break update
$dbVersion = get_db_schema();
if ($dbVersion < 107) {
logfile("BILLING: Cannot continue until the database schema update to >= 107 is complete");
exit(1);
$query = \LibreNMS\DB\Eloquent::DB()->table('bills');
if (isset($options['b'])) {
$query->where('bill_id', $options['b']);
}
foreach (dbFetchRows('SELECT * FROM `bills`') as $bill_data) {
echo 'Bill : '.$bill_data['bill_name']."\n";
foreach ($query->get(['bill_id', 'bill_name']) as $bill) {
echo 'Bill : '.$bill->bill_name."\n";
$bill_id = $bill->bill_id;
// 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'];
}
CollectData($bill_data['bill_id']);
$iter++;
}
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()');
@ -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);