<?php /** * Observium * * This file is part of Observium. * * @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) {
} if (isset($options['a']) || isset($options['l'])) { $modules[] = 'alertlog'; } if (isset($options['a']) || isset($options['r'])) { $modules[] = 'rrd'; } if (isset($options['a']) || isset($options['p'])) { $modules[] = 'ports'; } if (isset($options['a']) || isset($options['t'])) { $modules[] = 'timing'; } // Get age from command line if (isset($options['A'])) { $age = age_to_seconds($options['A']); if ($age) { foreach ($modules as $module) { if ($module == 'ports') { $module = 'deleted_ports'; } $config['housekeeping'][$module]['age'] = $age; } } else { print_debug("指定了无效的老化时间 '" . $options['A'] . "', 跳过."); } unset($age, $module); } if (!count($modules)) { print_message("%n\nUSAGE:\n{$scriptname} [-Vyaserptd] [-A <age>]\n\nNOTE, by default {$scriptname} asks 'Are you sure want to delete (y/N)?'.\n To assume 'yes' as answer to all prompts and run non-interactively,\n add '-y' in command line.\n Not necessary when run from cron (determined automatically).\n\nOPTIONS:\n -V Show version and exit.\n -y Automatically answer 'yes' to prompts\n -a Maintain all modules as specified below.\n -s Clean up syslog\n -e Clean up event log\n -l Clean up alert log\n -r Clean up unused RRD files\n -p Clean up deleted ports\n -t Clean up timing data (discovery and poll times)\n -A <age> Specifies maximum age for all modules (overrides configuration)\n\nDEBUGGING OPTIONS:\n -d Enable debugging output.\n -dd More verbose debugging output.\n\nEXAMPLES:\n {$scriptname} -a Clean up by all modules interactively (with prompts!)\n {$scriptname} -ya Clean up by all modules without prompts\n\n%r无效的参数!%n", 'color', FALSE); exit;
/** * @dataProvider providerAgeToSeconds */ public function testAgeToSeconds($value, $result) { $this->assertSame($result, age_to_seconds($value)); }
function age_to_unixtime($age, $min_age = 1) { $age = age_to_seconds($age); if ($age >= $min_age) { return time() - $age; } return 0; }