How to get notifications if a SystemD unit fails

Oooh, this is pretty useful, thanks! But that’s only per-unit, right? So I’d need to make sure I add that to all units, if I want to be notified every time.

Yeah, it’s per unit.

1 Like

Sorry for the late reply, I’m reading all this only now

yeah it’s a scriptinator problem, when it’s placed in the tray I’m unable to change the tooltip, because instead of asking to the plasmoid for the tooltip core, it uses the metadata.desktop “Comment” value as a tooltip, and I don’t know how to change it. Placed on the desktop or on the panel (should) work fine

glad you managed to solve this!

1 Like

I’ve been using this for a few weeks, and it did notify me many times that a systemd service failed. Probably this could be packaged into an individual widget and uploaded to the KDE store. :smile:

3 Likes

Awesome! It could be also cool to keep on the git repo an “examples.md” file with a bunch of configuration with different use cases! If you want to, I can create the file and then you can send a push request, or just write here the whole configuration so that I can copy it on github (this would be easier to maintain than multiple slightly different plasmoids, although users could find them more easily it they were separate and working out of the box)

1 Like

I have similar requirements to monitor various background jobs and other things that occur behind the scenes.

The approach I took is to write something that monitors the journal, filters for events I’m interested in (or rejects what I’m not interested in) and then forwards them as FreeDesktop notifications, which KDE then displays as notifications.

It’s a python/Qt script, not specific to KDE:

https://github.com/digitaltrails/jouno

I generalized into a journal viewer, but originally the idea was just to do the forwarding (when I started I couldn’t find a log viewer I was quite happy with).

1 Like

This is quite useful. Thanks!

I managed to get it work by:

  1. In “Ignore Filters”, add a rule with an empty pattern, so it ignores everything in journal by default.
  2. In “Match Filters”, add a rule with the following pattern: 'PRIORITY=[01234]'.*'_COMM=systemd'. And tick the checkbox before the pattern (enable regexp). This watches for all warnings and more severe from systemd .
  3. (optional) Add a rule with the pattern: 'PRIORITY=[0123]' (and regexp on) to watch for errors from all sources.
  4. Click the Apply button. Now systemd service errors will send a notification.

(Unsure if this is the intended way to use it.)

Also, I think this can be an easier method for background processes to send notifications. Yes, you can call notify-send. But you can also write to syslog or stdout containing a certain keyword, and have jouno watching for that keyword.

Yes, this is one of the two main ways I thought it could be useful: ignore everything, then only match the things that are of interest, such as the daily backups.

The other way to use it is to allow everything and add lots of ignore filters. This would be useful for those with a general interest in what’s happening in the background. Unless the ignore-filters are quite general, more will have to be added when a new Plasma/KDE gets released, there is often a whole bunch of new diagnostic warnings come along with it. It’s probably easy to do as you have done and default to ignore.

Exactly so, in the past I used to add notify-send to scripts. I even wrote a notify-desktop bash-script that can can run in cron or systemd-timers and find the X11/wayland DBUS session bus to raise notifications. As you pointed out, I came to realise it was easier to log to syslog, add myself to the systemd-journal group, and have something on my desktop (jouno) monitor the journal.

Running something in the desktop-session also removes the issue of how to find the DBUS session bus and how to get permission to write to it (more difficult in Wayland), so it obsoletes my notify-desktop gist.