Fork Me on GitHub

Fusion by Peter

my little presence on the web

Nagios notifications using notify-send

I use Nagios to monitor our group workstations. The Nagios server runs on my desktop, and I can the status of all the machines via a web-page served locally. By default, Nagios can send notifications for status changes via email, but this requires running a mail server, and who has time for that. What I’d like to do is to use libnotify to send a small pop-up notification. notify-send is very simple to use:

notify-send "Message title" "Message body"

However, there’s a small snag: nagios runs as its own user, you can’t use notify-send to send messages to other users, even on the same computer. There are various solutions for sending yourself messages from scripts running under cron, but I’ve not found a robust solution to sending another user on the same machine a notification. They all involve grabbing, or saving, the dbus information necessary to use notify-send. Unfortunately, that dbus information is (at least on my system) viewable only by the user in question.

Well, the trick is to combine the solutions for the cron scripts with sudo. Here is the script I use to grab the dbus info and send a notification:

export DISPLAY=:0
export $(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep kwin)/environ )
/usr/bin/notify-send "$1" "$2"

I then set a rule in the sudoers file to enable nagios to run this script as me:

nagios ALL=(<username>) NOPASSWD: SETENV: /path/to/script

Then in /usr/local/nagios/etc/objects/commands.cfg add:

# 'notify-host-by-notify' command definition
define command{
	command_name	notify-host-by-notify
	command_line	sudo -u <username> /path/to/script "Nagios: $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" "Host: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"

# 'notify-service-by-notify' command definition
define command{
	command_name	notify-service-by-notify
	command_line	sudo -u <username> /path/to/script "Nagios $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" "Service: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n"

Finally, I changed the generic-contact template in /usr/local/nagios/etc/objects/templates.cfg to use the two notify commands instead of the default notify-X-by-email.

Posted on

Graphing Fortran Projects

Currently, I am refactoring the code that I work on and I wanted to see how the different modules depend on each other. Doxygen generates graphs of how individual functions and routines call each other, which is pretty nifty, but it doesn’t seem to do it for the modules. Looking into how doxygen generates these graphs, I found out it uses the graphviz package, in particular dot.

Dot is a very simple language used to describe graphs. Wikipedia has some nice examples.

I wrote a short python function to crudely extract the module dependencies from my code and put them into a dot graph:

Writing the output of this function to a file and running dot on it produces lovely images like this:

messy graph

…I’m not sure if my refactoring is making it better or worse.

Posted on

Finding variables across a project

Quite often, I want to find a variable across the whole project I’m working on. I have progressed through a few different methods of doing so. When I was new to emacs and ran it in a terminal, I would flick to another tab in my terminal and just run grep.

Then I learnt about grep -n, which also displays the line numbers. I could then flick back to my emacs session and M-g M-g to go to that line. This is a bit of a pain, as I had to keep switching between tabs to find the next search result.

This year, I started using emacs in its gui, as I was mostly working locally, rather than on remote machines. Now I had to switch between emacs and my terminal, which was getting annoying. I discovered the wonders of M-x eshell - a terminal inside emacs! Using grep from eshell opens a new buffer with the grep results. From this buffer, you can use n and p to move between search results, which automatically displays the relevant section in a different buffer.

Then this week I came across M-x occur (shortcut: M-s o). This searches the current buffer for a regexp and displays the results in a new buffer. You can search across multiple buffers with M-x multi-occur, however you have to specify each buffer manually. A better command is M-x multi-occur-in-matching-buffers, which searches buffers that match a regexp.

So here is how I’ve started searching for variables across projects:

  1. First, I open all the project files (C-x C-f *.[fF]90, for example)
  2. Run M-x multi-occur-in-matching-buffers with the first argument as an elisp regexp (e.g. .*\.[fF]90)
  3. Switch to the *Occur* buffer and run M-x next-error-follow-minor-mode (this can actually be toggled with C-c C-f, same as in compilation-mode)
  4. Use C-n and C-p to move between search results, displaying the result in a different window

Posted on

Building a blog

I have made various short-lived websites over the years, using sundry template sites - geocities and their ilk. This one was built using a bunch of free tools and templates too, but it’s the only one where I have actually laid down money for a domain name. In getting this one off the ground, I have learnt how little I actually knew about hosting a site. is hosted on GitHub Pages, the domain name came from Vidahost, and the backend is done in Jekyll (which in turn is written in Ruby).

Messing about with projects on GitHub, I discovered that projects can have their own website, hosted on GitHub, very simply. In fact, users can have their own pages too. I had been thinking for some time about having some little space on the web to put little snippets of code, and so on. At the same time, I had also been thinking about getting a slightly more professional personal email address. This seemed like the perfect spur to action, so I started a new project on GitHub with the name “” (ZedThree being my GitHub username). A project named like this becomes your user page, accessible from

The next step was to get my own domain name. As all variations on my name were already taken, I decided to go with something related to my job - a researcher in fusion. There are two steps to actually using this domain name as the url for the GitHub user-page. This first is to put the domain name into a file named CNAME in the repo. This tells GitHub to serve your pages from that domain, instead of Next, you need to point your domain name to GitHub’s servers. This is done using a nameserver. Nameservers translate the natural-language domain name into a numeric IP address. Your registrar might provide a nameserver; if not, there are free ones available.

Well, it took me a while to actually finish writing this post. I guess I’ve not got into the habit yet.

Posted on


I finally got round to converting the Github Pages Merlot theme into a Jekyll theme, and so I have finally commenced my blog! The idea behind this blog is for it to be a place where I can share useful bits of python, emacs, Fortran, etc. that I have picked up; and moreover, a place where I can dump all those useful bits so I can find them later! I also intend to write some posts about my work and the various half-finished github projects I’ve started (case in point: this Jekyll theme).

I’m going to attempt to force myself to update this site pretty often, which means just getting on and writing posts and publishing them, so I imagine the first few will be fairly scrappy.

First up, how I created this site…

Posted on