Allow different time ranges for the different sources.

This commit is contained in:
redxef 2023-11-14 18:42:55 +01:00
parent 264301ecc0
commit c892ac1aab
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

20
main.py
View file

@ -45,6 +45,16 @@ def range_str_to_timedelta(value):
weeks=values['w']
)
def multiple_timedeltas(value):
mappings = {}
for v in value.split(','):
kv = v.split(':')
if len(kv) == 1:
mappings[-1] = range_str_to_timedelta(kv[0])
continue
mappings[int(kv[0])] = range_str_to_timedelta(kv[1])
return mappings
config_schema = Schema({
'sources': [dict],
'sinks': [dict],
@ -52,12 +62,12 @@ config_schema = Schema({
Optional('level', default=':WARNING,wp_cal:INFO'): Use(str),
},
Optional('range', default='365d'): Or(
dict,
And(
Use(str),
Regex(r'[0-9]+[smhdw]'),
Use(range_str_to_timedelta),
Regex(r'(([0-9]+:)?[0-9]+[smhdw],?)*'),
Use(multiple_timedeltas),
),
lambda x: isinstance(x, datetime.timedelta)
),
})
@ -149,9 +159,9 @@ def main(config, dryrun, level, range):
# gather events
events = []
source_results = []
for source in sources:
for i, source in enumerate(sources):
try:
events += source.get_events_resolved(until=config['range'])
events += source.get_events_resolved(until=config['range'].get(i, config['range'][-1]))
source_results += [True]
except Exception:
logger.exception('failed to get events from source %s', source)