I’ve been using Xymon (formerly known as “Hobbit”) for a long time. In most situations, I have Xymon running in a redundant configuration, with two or more instances of Xymon working together to monitor a network.
Even though Xymon works very well, a single change to the primary server’s configuration file (the “bb-hosts” file) means that you have to make the same change to all other ‘bb-hosts’ files in all other Xymon instances.
There are some creative ways to eliminate the drudgery of updating all these files any time a change to the primary file is necessary. One method, for example would be to have the master file exported via NFS to all the other Xymon server instances, and each of those instances would sym-link to that primary ‘bb-hosts’ file from their local mount of that NFS export.
I don’t like the NFS export idea, because if the primary server has a problem, and the NFS export is no longer available, all instances of Xymon would break – badly.
Instead, I’ve opted for automatically synchronizing the ‘bb-hosts’ file across all Xymon instances via the use of apache, cron, a sym-link, and a simple bash script.
Here’s how it works:
- On the primary Xymon instance, sym-link ‘/home/xymon/server/etc/bb-hosts’ to ‘/var/www/bb-hosts’.
- On the other instances of Xymon, run a bash script which grabs the primary server’s ‘bb-hosts’ via HTTP, which does some simple comparisons, and over-writes the local Xymon ‘bb-hosts’ if changes are detected.
- Automat this script with cron.
Perhaps the trickiest part of doing this is the actual script used to grab, compare, and over-write the ‘bb-hosts’ file for the other instances of Xymon. The script I’ve written below grabs the primary ‘bb-hosts’ file, and does a simple MD5 comparison with md5sum, and if it detects a change in the ‘bb-hosts’ file, it will send an e-mail to notify me that this change has occurred, along with details on what has changed.
Here’s the script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/bash REMOTE_BB_HOSTS="/tmp/bb-hosts" LOCAL_BB_HOSTS="/home/xymon/server/etc/bb-hosts" BB_HOSTS_DIFFS="/tmp/bb-hosts-diffs" wget http://somewebhost.domain.com/bb-hosts -qO "$REMOTE_BB_HOSTS" LOCAL_MD5=`md5sum $LOCAL_BB_HOSTS | cut -d " " -f 1` REMOTE_MD5=`md5sum $REMOTE_BB_HOSTS | cut -d " " -f 1` #echo "$LOCAL_MD5" #echo "$REMOTE_MD5" if [ "$LOCAL_MD5" != "$REMOTE_MD5" ]; then echo "Generated by $0" > $BB_HOSTS_DIFFS; diff $LOCAL_BB_HOSTS $REMOTE_BB_HOSTS >> $BB_HOSTS_DIFFS; cp $REMOTE_BB_HOSTS $LOCAL_BB_HOSTS; mail -s "Xymon: monitor-02 bb-hosts updated" firstname.lastname@example.org < $BB_HOSTS_DIFFS; fi
If you need a way to keep your Xymon ‘bb-hosts’ files in sync, something along the lines of the above script just may be what you’re looking for. If you’re currently accomplishing the same thing in an interesting way, please post a comment and let me know!