* @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ // Minimum allowed age for delete RRDs is 24h $cutoff = age_to_unixtime($config['housekeeping']['rrd']['age'], age_to_seconds('24h')); if ($cutoff || $config['housekeeping']['rrd']['invalid']) { if ($prompt) { $msg = "RRD files:" . PHP_EOL; if ($config['housekeeping']['rrd']['invalid']) { $msg .= " - not valid RRD" . PHP_EOL; } if ($cutoff) { $msg .= " - not modified since " . format_unixtime($cutoff) . PHP_EOL; } $answer = print_prompt($msg . "will be deleted"); } } else { print_message("RRD housekeeping disabled in configuration or less than 24h."); $answer = FALSE; } if ($answer) { $count_notvalid = 0; $count_notmodified = 0; foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($config['rrd_dir'])) as $file) { if (basename($file) != "." && basename($file) != ".." && substr($file, -4) == ".rrd") { print_debug("Found file ending in '.rrd': " . $file); if ($cutoff) { $file_data = stat($file); if ($file_data['mtime'] < $cutoff) { print_debug("File modification time is " . format_unixtime($file_data['mtime']) . " - deleting");
* * @package observium * @subpackage housekeeping * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ // Minimum allowed age for delete perfomance times is 24h $cutoff = age_to_unixtime($config['housekeeping']['timing']['age'], age_to_seconds('24h')); if ($cutoff) { $where = "`start` < {$cutoff}"; $count_run = dbFetchCell("SELECT COUNT(*) FROM `perf_times` WHERE {$where};"); $count_dev = dbFetchCell("SELECT COUNT(*) FROM `devices_perftimes` WHERE {$where};"); if ($count_run || $count_dev) { if ($prompt) { $answer = print_prompt("Perfomance entries - {$count_run} (per-run) and {$count_dev} (per-device) older than " . format_unixtime($cutoff) . " will be deleted"); } if ($answer) { $rows = dbDelete('devices_perftimes', $where); if ($rows === FALSE) { // Use LIMIT with big tables print_debug("Performance table (per-device) is too big, using LIMIT for delete entries"); $rows = 0; $i = 1000; while ($i && $rows < $count_dev) { $iter = dbDelete('devices_perftimes', $where . ' LIMIT 1000000'); if ($iter === FALSE) { break; } $rows += $iter; $i--;
* This file is part of Observium. * * @package observium * @subpackage housekeeping * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ // Minimum allowed age for delete syslog entries times is 24h $cutoff = age_to_unixtime($config['housekeeping']['eventlog']['age'], age_to_seconds('24h')); if ($cutoff) { $where = "UNIX_TIMESTAMP(`timestamp`) < {$cutoff}"; $count = dbFetchCell("SELECT COUNT(*) FROM `eventlog` WHERE {$where}"); if ($count) { if ($prompt) { $answer = print_prompt("{$count} eventlog entries older than " . format_unixtime($cutoff) . " will be deleted"); } if ($answer) { $rows = dbDelete('eventlog', $where); if ($rows === FALSE) { // Use LIMIT with big tables print_debug("Event log table is too big, using LIMIT to delete entries"); $rows = 0; $i = 1000; while ($i && $rows < $count) { $iter = dbDelete('eventlog', $where . ' LIMIT 1000000'); if ($iter === FALSE) { break; } $rows += $iter; $i--;
logfile("cleanup.log", "Database cleanup for table {$table}: deleted {$count} entries"); } } else { if ($prompt) { print_message("No orphaned rows found in table {$table}."); } } } // Cleanup duplicate entries in the device_graphs table foreach (dbFetchRows("SELECT * FROM `device_graphs`") as $entry) { $graphs[$entry['device_id']][$entry['graph']][] = $entry['device_graph_id']; } foreach ($graphs as $device_id => $device_graph) { foreach ($device_graph as $graph => $data) { if (count($data) > 1) { // More than one entry for a single graph type for this device, let's clean up. // Leave the first entry intact, chop it off the array $device_graph_ids = array_slice($data, 1); if ($prompt) { $answer = print_prompt(count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id} will be deleted"); } if ($answer) { $table_status = dbDelete('device_graphs', "`device_graph_id` IN (?)", array($device_graph_ids)); print_debug("Deleted " . count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id}"); logfile("cleanup.log", "Deleted " . count($device_graph_ids) . " duplicate graph rows of type {$graph} for device {$device_id}"); } } } } } // EOF
* This file is part of Observium. * * @package observium * @subpackage housekeeping * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $cutoff = age_to_unixtime($config['housekeeping']['deleted_ports']['age']); if ($cutoff) { $where = "`deleted` = 1 AND UNIX_TIMESTAMP(`ifLastChange`) < {$cutoff}"; $ports = dbFetchRows("SELECT `port_id` FROM `ports` WHERE {$where}"); $count = count($ports); if ($count) { if ($prompt) { $answer = print_prompt("{$count} ports marked as deleted before " . format_unixtime($cutoff) . " will be deleted"); } if ($answer) { foreach ($ports as $entry) { delete_port($entry['port_id']); } print_debug("Deleted ports housekeeping: deleted {$count} entries"); logfile("housekeeping.log", "Deleted ports: deleted {$count} entries older than " . format_unixtime($cutoff)); } } else { if ($prompt) { print_message("No ports found marked as deleted before " . format_unixtime($cutoff)); } } } else { print_message("Deleted ports housekeeping disabled in configuration.");
* This file is part of Observium. * * @package observium * @subpackage housekeeping * @author Adam Armstrong <*****@*****.**> * @copyright (C) 2006-2014 Adam Armstrong * */ $cutoff = age_to_unixtime($config['housekeeping']['deleted_ports']['age']); if ($cutoff) { $where = "`deleted` = 1 AND UNIX_TIMESTAMP(`ifLastChange`) < {$cutoff}"; $ports = dbFetchRows("SELECT `port_id` FROM `ports` WHERE {$where}"); $count = count($ports); if ($count) { if ($prompt) { $answer = print_prompt("{$count} ports marked as 'DELETED' older than " . format_unixtime($cutoff) . " will be deleted"); } if ($answer) { foreach ($ports as $entry) { delete_port($entry['port_id']); } print_debug("Deleted ports housekeeping: deleted {$count} entries"); logfile("housekeeping.log", "Deleted ports: deleted {$count} entries older than " . format_unixtime($cutoff)); } } else { if ($prompt) { print_message("No deleted ports found older than " . format_unixtime($cutoff)); } } } else { print_message("Deleted ports housekeeping disabled in configuration.");
// Fetch all existing device IDs foreach (dbFetch("SELECT `device_id` FROM `devices`") as $device) { $devices[] = $device['device_id']; if ($device['device_id'] > $max_id) { $max_id = $device['device_id']; } } foreach ($config['device_tables'] as $table) { $where = '`device_id` NOT IN (' . implode($devices, ',') . ') AND `device_id` < ?'; if ($table == 'entity_permissions') { $where = "`entity_type` = 'device' AND `entity_id` NOT IN (" . implode($devices, ',') . ") AND `entity_id` = ?"; } $rows = dbFetchRows("SELECT 1 FROM `{$table}` WHERE {$where}", array($max_id)); $count = count($rows); if ($count) { if ($prompt) { $answer = print_prompt("{$count} rows in table {$table} for non-existing devices will be deleted"); } if ($answer) { $table_status = dbDelete($table, $where, array($max_id)); print_debug("Database cleanup for table {$table}: deleted {$count} entries"); logfile("cleanup.log", "Database cleanup for table {$table}: deleted {$count} entries"); } } else { if ($prompt) { print_message("No orphaned rows found in table {$table}."); } } } } // EOF