diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c677862..5901cc74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Features: Monitoring Plugins: * All plugins: Consistently reporting errors using cu() instead of oao() +* about-me: Show systemd timers with next runtime * fail2ban: Improve output, add unit-test * grafana-version: Add Grafana v9.5 * infomaniak-events: Add filter for service categories diff --git a/check-plugins/about-me/README.rst b/check-plugins/about-me/README.rst index a64d7a80..b022f80c 100644 --- a/check-plugins/about-me/README.rst +++ b/check-plugins/about-me/README.rst @@ -200,13 +200,11 @@ Full output example: * proc-sys-fs-binfmt_misc.automount systemctl list-timers: - * logrotate.timer - * unbound-anchor.timer - * duba.timer - * fstrim.timer - * systemd-tmpfiles-clean.timer - * notify-and-schedule.timer - * raid-check.timer + unit ! activates ! next + -----------------------------+--------------------------------+------------------------------ + systemd-tmpfiles-clean.timer ! systemd-tmpfiles-clean.service ! Sat 2023-09-02 05:22:46 CEST + unbound-anchor.timer ! unbound-anchor.service ! Sat 2023-09-02 00:00:00 CEST + wordpress-cron.timer ! wordpress-cron.service ! Fri 2023-09-01 10:15:00 CEST 3rd-party Python libs required by any of the plugins when running in source code variant: * Installed: psutil 5.8.0, pymysql.cursors 0.10.1 diff --git a/check-plugins/about-me/about-me b/check-plugins/about-me/about-me index e3bfbd12..51917402 100755 --- a/check-plugins/about-me/about-me +++ b/check-plugins/about-me/about-me @@ -40,7 +40,7 @@ except ImportError: __author__ = 'Linuxfabrik GmbH, Zurich/Switzerland' -__version__ = '2023052501' +__version__ = '2023090101' DESCRIPTION = 'Reports a quick overview about the host dimensions and installed software.' @@ -1938,21 +1938,43 @@ def get_systemd_timers(): # (eg systemd 239 on CentOS 7), therefore we have to parse the human output. # in order to list for a different user (`--user`), we would need to sudo to that user # first - we will skip that for now + + # NEXT LEFT LAST PASSED UNIT ACTIVATES + # Fri 2023-09-01 10:32:28 CEST 34min left Fri 2023-09-01 09:08:17 CEST 49min ago dnf-makecache.timer dnf-makecache.service cmd = 'systemctl list-timers' stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(cmd)) if stderr or retc != 0: return '' - msg = '' - start_pos = None - end_pos = None + table_data = [] + next_pos = None + left_pos = None + last_pos = None + passed_pos = None + unit_pos = None + activates_pos = None + for line in stdout.splitlines(): - if start_pos is None: - start_pos = line.find('UNIT') - end_pos = line.find('ACTIVATES', start_pos) + if next_pos is None: + next_pos = line.find('NEXT') + left_pos = line.find('LEFT') + last_pos = line.find('LAST') + passed_pos = line.find('PASSED') + unit_pos = line.find('UNIT') + activates_pos = line.find('ACTIVATES') if '.timer' in line: - msg = '{}* {}\n'.format(msg, line[start_pos:end_pos].strip()) - return msg + table_data.append({ + 'unit': line[unit_pos:activates_pos].strip(), + 'activates': line[activates_pos:].strip(), + 'next': line[next_pos:left_pos].strip(), + }) + + return lib.base.get_table( + table_data, + ['unit', 'activates', 'next'], + header=['unit', 'activates', 'next'], + sort_by_key='unit', + ) def get_systemd_units(cmd):