Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Jobs/DiscoverDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handle(): void
$this->device->device_id,
$measurement->getDuration()));

Log::channel('log_file')->alert(sprintf('INFO: device:discover %s (%s) discovered in %0.3fs',
Log::alert(sprintf('INFO: device:discover %s (%s) discovered in %0.3fs',
$this->device->hostname,
$this->device->device_id,
$measurement->getDuration()));
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/PollDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function handle(): void
$measurement->getDuration()));

// add log file line, this is used by the simple python dispatcher watchdog
Log::channel('log_file')->alert(sprintf('INFO: device:poll %s (%s) polled in %0.3fs',
Log::alert(sprintf('INFO: device:poll %s (%s) polled in %0.3fs',
$this->device->hostname,
$this->device->device_id,
$measurement->getDuration()));
Expand Down
4 changes: 2 additions & 2 deletions app/Observers/ModuleModelObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function observe($model, string $name = ''): void
$class = ltrim($model, '\\');

if ($name) {
Log::channel('stdout')->info(ucwords($name) . ': ', ['nlb' => true]);
Log::info(ucwords($name) . ': ', ['nlb' => true]);
}

if (! in_array($class, $observed_models)) {
Expand All @@ -63,7 +63,7 @@ public static function observe($model, string $name = ''): void

public static function done(): void
{
Log::channel('stdout')->info(PHP_EOL, ['nlb' => true]);
Log::info(PHP_EOL, ['nlb' => true]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
app(\App\Polling\Measure\MeasurementManager::class)->printStats();
}

logfile($string);
Log::debug($string);

if ($doing !== 'new' && $discovered_devices == 0) {
// No discoverable devices, either down or disabled
Expand Down
15 changes: 0 additions & 15 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,6 @@ function parse_modules($type, $options)
return $override;
}

function logfile($string)
{
$file = LibrenmsConfig::get('log_file');
$fd = fopen($file, 'a');

if ($fd === false) {
print_error("Error: Could not write to log file: $file");

return;
}

fwrite($fd, $string . "\n");
fclose($fd);
}

function renamehost($id, $new, $source = 'console')
{
$host = gethostbyid($id);
Expand Down
31 changes: 12 additions & 19 deletions poll-billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@

$scheduler = LibrenmsConfig::get('schedule_type.billing');
if (! isset($options['f']) && $scheduler != 'legacy' && $scheduler != 'cron') {
if (Debug::isEnabled()) {
echo "Billing is not enabled for cron scheduling. Add the -f command argument if you want to force this command to run.\n";
}
Log::debug('Billing is not enabled for cron scheduling. Add the -f command argument if you want to force this command to run.');
exit(0);
}

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

$query = \LibreNMS\DB\Eloquent::DB()->table('bills');

Expand All @@ -47,7 +45,7 @@
}

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

if (LibrenmsConfig::get('distributed_poller') && LibrenmsConfig::get('distributed_billing')) {
Expand All @@ -65,7 +63,7 @@
$host = $port_data['hostname'];
$port = $port_data['port'];

echo " Polling {$port_data['ifName']} ({$port_data['ifDescr']}) on {$port_data['hostname']}\n";
Log::info(" Polling {$port_data['ifName']} ({$port_data['ifDescr']}) on {$port_data['hostname']}");

$port_data['in_measurement'] = Billing::getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], 'In');
$port_data['out_measurement'] = Billing::getValue($port_data['hostname'], $port_data['port'], $port_data['ifIndex'], 'Out');
Expand Down Expand Up @@ -99,17 +97,13 @@
$port_data['out_delta'] = '0';
}
//////////////////////////////////CountersValidation$DB-Update
echo "\nDB SNMP counters received.\n";
echo ' in_measurement: ',$port_data['in_measurement'],' out_measurement: ',$port_data['out_measurement'],"\n";
echo ' The data types are --> in_measurement:' . gettype($port_data['in_measurement']) . ' and out_measurement: ' . gettype($port_data['out_measurement']) . "\n";
//For debugging
logfile("\n****$now: " . $bill->bill_name . "\nDB SNMP counters received.");
logfile('in_measurement: ' . $port_data['in_measurement'] . ' out_measurement: ' . $port_data['out_measurement'] . "\nThe data types are. in_measurement:" . gettype($port_data['in_measurement']) . ' and out_measurement: ' . gettype($port_data['out_measurement']));
logfile('IN_delta: ' . $port_data['in_delta'] . ' OUT_delta: ' . $port_data['out_delta'] . "\nLast_IN_delta: " . ($port_data['last_in_delta'] ?? '') . ' last_OUT_delta: ' . ($port_data['last_out_delta'] ?? ''));
Log::debug("****$now: " . $bill->bill_name . ' Billing DB SNMP counters received.');
Log::debug('in_measurement: ' . $port_data['in_measurement'] . ' out_measurement: ' . $port_data['out_measurement'] . "\nThe data types are. in_measurement:" . gettype($port_data['in_measurement']) . ' and out_measurement: ' . gettype($port_data['out_measurement']));
Log::debug('IN_delta: ' . $port_data['in_delta'] . ' OUT_delta: ' . $port_data['out_delta'] . "\nLast_IN_delta: " . ($port_data['last_in_delta'] ?? '') . ' last_OUT_delta: ' . ($port_data['last_out_delta'] ?? ''));

if (is_numeric($port_data['in_measurement']) && is_numeric($port_data['out_measurement'])) {
echo "Nice, valid counters 'in/out_measurement', lets use them\n";
logfile("Nice, valid counters 'in/out_measurement', lets use them");
Log::debug("Nice, valid counters 'in/out_measurement', lets use them");
// NOTE: casting to string for mysqli bug (fixed by mysqlnd)
$fields = ['timestamp' => $now, 'in_counter' => (string) set_numeric($port_data['in_measurement']), 'out_counter' => (string) set_numeric($port_data['out_measurement']), 'in_delta' => (string) set_numeric($port_data['in_delta']), 'out_delta' => (string) set_numeric($port_data['out_delta'])];
if (dbUpdate($fields, 'bill_port_counters', "`port_id`='" . $port_id . "' AND `bill_id`='$bill_id'") == 0) {
Expand All @@ -118,8 +112,7 @@
dbInsert($fields, 'bill_port_counters');
}
} else {
echo "WATCH out! - Wrong counters. Table 'bill_port_counters' not updated\n";
logfile("WATCH out! - Wrong counters. Table 'bill_port_counters' not updated");
Log::error("WATCH out! - Wrong counters. Table 'bill_port_counters' not updated");
}
////////////////////////////////EndCountersValidation&DB-Update
$delta = ($delta + $port_data['in_delta'] + $port_data['out_delta']);
Expand Down Expand Up @@ -149,7 +142,7 @@
}

if (! empty($period) && $period < '0') {
logfile("BILLING: negative period! id:$bill_id period:$period delta:$delta in_delta:$in_delta out_delta:$out_delta");
Log::debug("BILLING: negative period! id:$bill_id period:$period delta:$delta in_delta:$in_delta out_delta:$out_delta");
} else {
// NOTE: casting to string for mysqli bug (fixed by mysqlnd)
if (LibrenmsConfig::get('distributed_poller') && LibrenmsConfig::get('distributed_billing')) {
Expand All @@ -169,8 +162,8 @@
$poller_time = substr($poller_run, 0, 5);

if ($poller_time > 300) {
logfile("BILLING: polling took longer than 5 minutes ($poller_time seconds)!");
Log::warning("BILLING: polling took longer than 5 minutes ($poller_time seconds)!");
}
echo "\nCompleted in $poller_time sec\n";
Log::info("Completed in $poller_time sec");

app('Datastore')->terminate();
2 changes: 1 addition & 1 deletion syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

$s = fopen('php://stdin', 'r');
while ($line = fgets($s)) {
//logfile($line);
// Log::channel('log_file')->critical($line); // uncomment to log input to librenms.log

$fields = explode('||', trim($line));
if (count($fields) === 8) {
Expand Down
Loading