-
Notifications
You must be signed in to change notification settings - Fork 91
/
housekeeping.php
executable file
·123 lines (104 loc) · 3.95 KB
/
housekeeping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env php
<?php
/**
* Observium
*
* This file is part of Observium.
*
* @package observium
* @subpackage housekeeping
* @author Adam Armstrong <[email protected]>
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
*
*/
chdir(dirname($argv[0]));
$options = getopt("A:Vyaselurptdb");
include("includes/sql-config.inc.php");
$scriptname = basename($argv[0]);
$cli = is_cli();
if (isset($options['V']))
{
print_message(OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION);
if (is_array($options['V'])) { print_versions(); }
exit;
}
print_message("%g".OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION."\n%WHouseKeeping%n\n", 'color');
if (OBS_DEBUG) { print_versions(); }
// For interactive prompt/answer checks
// if it is started from crontab - prompt disabled and answer always 'yes'
if (is_cron())
{
$prompt = FALSE;
} else {
$prompt = !isset($options['y']);
}
$answer = TRUE;
$modules = array();
if (isset($options['a']) || isset($options['s'])) { $modules[] = 'syslog'; }
if (isset($options['a']) || isset($options['e'])) { $modules[] = 'eventlog'; }
if (isset($options['a']) || isset($options['l'])) { $modules[] = 'alertlog'; }
if (isset($options['a']) || isset($options['u'])) { $modules[] = 'authlog'; }
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'; }
if (isset($options['a']) || isset($options['b'])) { $modules[] = 'staledb'; }
// 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("Invalid age specified '" . $options['A'] . "', skipped.");
}
unset($age, $module);
}
if (!count($modules))
{
print_message("%n
USAGE:
$scriptname [-Vyaselrptdbu] [-A <age>]
NOTE, by default $scriptname asks 'Are you sure want to delete (y/N)?'.
To assume 'yes' as answer to all prompts and run non-interactively,
add '-y' in command line.
Not necessary when run from cron (determined automatically).
OPTIONS:
-V Show version and exit.
-y Automatically answer 'yes' to prompts
-a Maintain all modules as specified below.
-s Clean up syslog
-e Clean up event log
-l Clean up alert log
-u Clean up auth log
-r Clean up unused RRD files
-p Clean up deleted ports
-t Clean up timing data (discovery and poll times)
-b Clean up stale database entries
-A <age> Specifies maximum age for all modules (overrides configuration)
DEBUGGING OPTIONS:
-d Enable debugging output.
-dd More verbose debugging output.
EXAMPLES:
$scriptname -a Clean up by all modules interactively (with prompts!)
$scriptname -ya Clean up by all modules without prompts
%rInvalid arguments!%n", 'color', FALSE);
exit;
} else {
foreach ($modules as $module)
{
if (is_file($config['install_dir'] . "/includes/housekeeping/$module.inc.php"))
{
include($config['install_dir'] . "/includes/housekeeping/$module.inc.php");
set_obs_attrib("housekeeping_lastrun_$module", time());
} else {
print_warning("Housekeeping module not found: $module");
}
}
set_obs_attrib("housekeeping_lastrun", time());
}
// EOF