Implement cli option for days log filter, drop negative requirement
This commit is contained in:
parent
f75586b8b9
commit
fb08154feb
@ -39,7 +39,7 @@ The following actions are available for definition:
|
||||
* **path** - base path to scan for logs
|
||||
* **include** - regexp string to match log files against for inclusion (if not set = include all)
|
||||
* **exclude** - regexp string to match log files against. Excludes matched files from collection.
|
||||
* **start** - date or datetime string to collect only files modified on or after the specified time. Format - ``YYYY-MM-DD`` or ``YYYY-MM-DD HH:MM:SS`` or ``-N`` where N = number of days from now (number should be negative, meaning last N days).
|
||||
* **start** - date or datetime string to collect only files modified on or after the specified time. Format - ``YYYY-MM-DD`` or ``YYYY-MM-DD HH:MM:SS`` or ``N`` where N = integer number of days (meaning last N days).
|
||||
|
||||
===============
|
||||
Filtering nodes
|
||||
|
@ -57,6 +57,11 @@ def parse_args():
|
||||
parser.add_argument('-r', '--role', action='append',
|
||||
help=('Can be specified multiple times.'
|
||||
' Run only on the specified role.'))
|
||||
parser.add_argument('-d', '--days', type=int,
|
||||
help=('Define log collection period in days.'
|
||||
' Timmy will collect only logs updated on or'
|
||||
' more recently then today minus the given'
|
||||
' number of days. Default - 30.'))
|
||||
parser.add_argument('-G', '--get', action='append',
|
||||
help=('Enables shell mode. Can be specified multiple'
|
||||
' times. Filemask to collect via "scp -r".'
|
||||
@ -178,6 +183,8 @@ def main(argv=None):
|
||||
conf['clean'] = False
|
||||
if args.rqfile:
|
||||
conf['rqfile'] = args.rqfile
|
||||
if args.days:
|
||||
conf['logs']['start'] = -args.days
|
||||
if conf['shell_mode']:
|
||||
filter = conf['hard_filter']
|
||||
# config cleanup for shell mode
|
||||
|
@ -61,7 +61,7 @@ def load_conf(filename):
|
||||
conf['filelists'] = []
|
||||
conf['logs'] = {'path': '/var/log',
|
||||
'exclude': '\.[^12]\.gz$|\.\d{2,}\.gz$',
|
||||
'start': '-30'}
|
||||
'start': '30'}
|
||||
'''Shell mode - only run what was specified via command line.
|
||||
Skip actionable conf fields (see timmy/nodes.py -> Node.conf_actionable);
|
||||
Skip rqfile import;
|
||||
|
@ -325,14 +325,16 @@ class Node(object):
|
||||
for item in self.logs:
|
||||
start_str = ''
|
||||
if 'start' in item:
|
||||
if item['start'].startswith('-'):
|
||||
days = int(item['start'][1:])
|
||||
start = item['start']
|
||||
if any([type(start) is str and re.match(r'-?\d+', start),
|
||||
type(start) is int]):
|
||||
days = abs(int(str(start)))
|
||||
start_str = str(date.today() - timedelta(days=days))
|
||||
else:
|
||||
for format in ['%Y-%m-%d', '%Y-%m-%d %H:%M:%S']:
|
||||
try:
|
||||
if datetime.strptime(start_str, format):
|
||||
start_str = item['start']
|
||||
if datetime.strptime(start, format):
|
||||
start_str = start
|
||||
break
|
||||
except ValueError:
|
||||
pass
|
||||
@ -340,7 +342,7 @@ class Node(object):
|
||||
self.logger.warning(('incorrect value of "start"'
|
||||
' parameter in "logs": "%s" -'
|
||||
' ignoring...')
|
||||
% item['start'])
|
||||
% start)
|
||||
if start_str:
|
||||
start_param = ' -newermt "$(date -d \'%s\')"' % start_str
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user