Skip to content

Commit

Permalink
about-me: Show systemd timers with next runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
markuslf committed Sep 1, 2023
1 parent bda4132 commit 4a9d8bb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions check-plugins/about-me/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 31 additions & 9 deletions check-plugins/about-me/about-me
Original file line number Diff line number Diff line change
Expand Up @@ -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.'

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4a9d8bb

Please sign in to comment.