Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to emove only autodiscovered offline addresses #3505

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config.dist.php
Expand Up @@ -56,6 +56,7 @@
# remove_offline_addresses.php script parameters
$config['removed_addresses_send_mail'] = true; // true/false, send or not mail on pomoving inactive addresses
$config['removed_addresses_timelimit'] = 86400 * 7; // int, after how many seconds of inactivity address will be deleted (7 days)
$config['removed_addresses_autodiscovered'] = false; // Only remove addresses with -- autodiscovered -- description
# resolveIPaddresses.php script parameters
$config['resolve_emptyonly'] = true; // if true it will only update the ones without DNS entry!
$config['resolve_verbose'] = true; // verbose response - prints results, cron will email it to you!
Expand Down
29 changes: 18 additions & 11 deletions functions/scripts/remove_offline_addresses.php
Expand Up @@ -34,17 +34,24 @@

// set query to fetch addresses and belongign subnets
$query = "select
`ip`.`id`,`ip`.`ip_addr`,`ip`.`lastSeen`,`ip`.`subnetId`,`ip`.`description`,`ip`.`hostname`,`ip`.`lastSeen`,
`su`.`subnet`,`su`.`mask`,`su`.`sectionId`,`su`.`description`,
'delete' as `action`
from
`ipaddresses` as `ip`, `subnets` as `su`
where
`ip`.`subnetId` = `su`.`id`
and `su`.`pingSubnet` = 1
and (`ip`.`excludePing` IS NULL or `ip`.`excludePing`!=1 )
and
(`ip`.`lastSeen` < '$beforetime' and `ip`.`lastSeen` != '1970-01-01 00:00:01' and `ip`.`lastSeen` is not NULL);";
`ip`.`id`,`ip`.`ip_addr`,`ip`.`lastSeen`,`ip`.`subnetId`,`ip`.`description`,`ip`.`hostname`,`ip`.`lastSeen`,
`su`.`subnet`,`su`.`mask`,`su`.`sectionId`,`su`.`description`,
'delete' as `action`
from
`ipaddresses` as `ip`, `subnets` as `su`
where
`ip`.`subnetId` = `su`.`id`
and `su`.`pingSubnet` = 1
and (`ip`.`excludePing` IS NULL or `ip`.`excludePing`!=1)
and (`ip`.`lastSeen` < '$beforetime' and `ip`.`lastSeen` != '1970-01-01 00:00:01' and `ip`.`lastSeen` is not NULL) ";

// Only remove autodiscovered IPs ? (based on description)
if (isset($config['removed_addresses_autodiscovered']) && $config['removed_addresses_autodiscovered']) {
$query.= " and `ip`.`description` = '" . _('-- autodiscovered --') . "'";
}

// End the query gracefully
$query.= ";";

# fetch
try { $offline_addresses = $Database->getObjectsQuery($query); }
Expand Down