diff --git a/daily.php b/daily.php index 3bd17bec30..b96479371b 100644 --- a/daily.php +++ b/daily.php @@ -112,6 +112,26 @@ if ($options['f'] === 'device_perf') { exit($ret); } +if ($options['f'] === 'ports_purge') { + try { + if (Config::get('distributed_poller')) { + MemcacheLock::lock('ports_purge', 0, 86000); + } + $ports_purge = Config::get('ports_purge'); + + if ($ports_purge) { + $interfaces = dbFetchRows('SELECT * from `ports` AS P, `devices` AS D WHERE `deleted` = 1 AND D.device_id = P.device_id'); + foreach ($interfaces as $interface) { + delete_port($interface['port_id']); + } + echo "All deleted ports now purged\n"; + } + } catch (LockException $e) { + echo $e->getMessage() . PHP_EOL; + exit(-1); + } +} + if ($options['f'] === 'handle_notifiable') { if ($options['t'] === 'update') { $title = 'Error: Daily update failed'; diff --git a/daily.sh b/daily.sh index 7aaccf1a01..8e4729c87c 100755 --- a/daily.sh +++ b/daily.sh @@ -264,7 +264,8 @@ main () { "purgeusers" "bill_data" "alert_log" - "rrd_purge"); + "rrd_purge" + "ports_purge"); call_daily_php "${options[@]}"; ;; submodules) diff --git a/doc/Support/Cleanup-options.md b/doc/Support/Cleanup-options.md index 20d2a8c3dd..66e35fb265 100644 --- a/doc/Support/Cleanup-options.md +++ b/doc/Support/Cleanup-options.md @@ -14,6 +14,7 @@ $config['authlog_purge'] = 30; $config['perf_times_purge'] = 30; $config['device_perf_purge'] = 7; $config['rrd_purge'] = 90;// Not set by default +$config['ports_purge'] = true;// Set to false by default ``` These options will ensure data within LibreNMS over X days old is automatically purged. You can alter these individually, values are in days. @@ -24,6 +25,6 @@ These options will ensure data within LibreNMS over X days old is automatically Over time as you add devices some interfaces will need to be purged as they are set to be ignored or bad interfaces or marked as deleted. -This Process needs to be manually done in the Web UI by admin user. +You can purge all deleted ports from the WebUI (see below) or by setting `$config['ports_purge'] = true;` in `config.php` In the Web UI Under the Ports Tab in the Nav Bar, Click on "Deleted" then click on "Purge all deleted". This will purge all the ports.