Skip to content

Instantly share code, notes, and snippets.

@fake666
Created April 25, 2023 11:44
Show Gist options
  • Save fake666/34b41d5c01f3a5bdea09699c24031c12 to your computer and use it in GitHub Desktop.
Save fake666/34b41d5c01f3a5bdea09699c24031c12 to your computer and use it in GitHub Desktop.
proxmox backup server task log json to ical converter
"""
requirement: pip install ics
usage:
# proxmox-backup-manager task list --all --limit 1000 --output-format json | python3 ./taskcal.py - > hostname.ics
"""
import sys
import json
from ics import Calendar, Event
if len(sys.argv) < 2:
raise Exception("Usage: taskcal.py <input json file>")
if sys.argv[1] == '-':
tasks=json.load(sys.stdin)
else:
with open(sys.argv[1], 'r') as f:
tasks = json.load(f)
c = Calendar()
for task in tasks:
if task['worker_type'] == 'aptupdate' or task['worker_type'] == 'logrotate':
continue
e = Event()
e.name = task['worker_type'] + " (" + task['upid'].split(':')[8].split('@')[0] + ")"
e.description = task['upid']
e.begin = task['starttime']
e.end = task['endtime']
candidates = c.timeline.overlapping(e.begin.shift(minutes=-15), e.end.shift(minutes=+15))
found = False
for candidate in candidates:
if candidate.name == e.name:
if candidate.begin > e.begin:
candidate.begin = e.begin
if candidate.end < e.end:
candidate.end = e.end;
found = True
break;
if not found:
c.events.add(e)
sys.stdout.writelines(c.serialize_iter())
@fake666
Copy link
Author

fake666 commented Apr 25, 2023

Screenshot 2023-04-25 at 13 41 21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment