[hobbit] Comma-separated lists of hostnames, etc. in hobbit-alerts.cfg is not documented

jm54601 at yahoo.com jm54601 at yahoo.com
Wed Oct 15 18:04:15 CEST 2008


Here's a script I used to convert bbwarnrules.cfg to hobbit-alerts.cfg.  It's far from perfect, but might help you save some labor.  We also used host groups and page groups fairly extensively in bbwarnsetup.cfg.  This script merges both.

#!/bin/bash
# Converts bbwarnrules.cfg to hobbit-alerts.cfg format
# TO DO: DAY and TIME
#BBWR=/usr/local/bb/etc/bbwarnrules.cfg
#BBWS=/usr/local/bb/etc/bbwarnsetup.cfg
BBWR=bbwarnrules.cfg
BBWS=bbwarnsetup.cfg
OUT1=/tmp/HGA.`date +%s`
HG='hg-'
DHG='$hg-'
PG='pg-'
DPG='$pg-'
#for i in `grep ^hg- $BBWR|tr ' ' '+'`
for i in `cat $BBWR | tr ' ' '+'`
do
if [[ $i == [h][g]* ]]
then
# HOST=`echo $i | tr '+' ' ' | awk -F\; '{print $1}'| sed -e s/$HG/$DHG/g`
HGA=`echo $i | awk -F\; '{print $1}'`
if [[ $HGA == *[+]* ]]
then
# echo handle multiple hostgroups
echo -n HOST=
for yy in `echo $HGA | tr '+' ' '`
do
grep -w $yy $BBWS|awk -F: '{print $2}' >> $OUT1
done
for xx in `cat $OUT1`
do
echo -n $xx,
done | sed s/.$//
rm $OUT1
else
grep -w $HGA $BBWS | awk -F: '{print $2}' | tr ' ' ',' | sed -e s/,/HOST=/
fi
EXHOST=`echo $i | tr '+' ' ' | awk -F\; '{print $2}'| sed -e s/$HG/$DHG/g`
# SERVICE=`echo $i | tr '+' ',' | tr '*' 'x' | awk -F\; '{print $3}' | sed -e s/fping/conn/g`
SERVICE=`echo $i | tr '+' ',' | awk -F\; '{print $3}' | sed -e s/fping/conn/g`
EXSERVICE=`echo $i | tr '+' ',' | awk -F\; '{print $4}'`
DAY=`echo $i | tr '+' ',' | awk -F\; '{print $5}'`
TIME=`echo $i | tr '+' ',' | awk -F\; '{print $6}'`
MAIL=`echo $i | tr '+' ' ' | awk -F\; '{print $7}'`
if [[ $EXHOST != "" ]]
then
echo -n " EXHOST=%$EXHOST"
fi
echo -n " SERVICE=$SERVICE"
if [[ $EXSERVICE != "" ]]
then
echo -n " EXSERVICE=$EXSERVICE"
fi
if [[ $DAY == \* && $TIME == \* ]]
then
true
else
echo -n " TIME=$DAY:$TIME" | tr '-' ':'
fi
echo " RECOVERED"
for m in $MAIL
do
case $m in
ext*)
SCR=`echo " SCRIPT /usr/local/hobbit/server/ext/pg/$m REMEDY" | sed -e s/ext-//g | sed -e s/-tokin//g | sed -e s/\:\~/+DURATION\>/g | tr '+' ' '`
echo -n " "
echo $SCR | awk '{print $1" "$2" "$4" "$3}'
;;
pg-*)
echo " MAIL $m" | sed -e s/$PG/$DPG/g | sed -e s/\:\~/+DURATION\>/g | tr '+' ' '
;;
*)
echo " MAIL $m" | sed -e s/\:\~/+DURATION\>/g | tr '+' ' '
;;
esac
done
echo
elif [[ $i != \#* && $i != \*DC* && $i != notify* && $i != \* && $i != unmatched* && $i != \!* ]]
then
HOST=`echo $i | tr '+' ' ' | awk -F\; '{print $1}'`
EXHOST=`echo $i | tr '+' ' ' | awk -F\; '{print $2}'`
SERVICE=`echo $i | tr '+' ',' | awk -F\; '{print $3}' | sed -e s/fping/conn/g`
EXSERVICE=`echo $i | tr '+' ',' | awk -F\; '{print $4}'`
MAIL=`echo $i | tr '+' ' ' | awk -F\; '{print $7}'`
echo -n "HOST=$HOST" | tr ' ' ','
if [[ $EXHOST != "" ]]
then
echo -n " EXHOST=$EXHOST"
fi
echo -n " SERVICE=$SERVICE"
if [[ $EXSERVICE != "" ]]
then
echo -n " EXSERVICE=$EXSERVICE"
fi
if [[ $DAY == \* && $TIME == \* ]]
then
true
else
echo -n " TIME=$DAY:$TIME" | tr '-' ':'
fi
echo " RECOVERED"
for m in $MAIL
do
case $m in
ext*)
#echo " SCRIPT /usr/local/hobbit/server/ext/pg/$m REMEDY"| sed -e s/ext-//g | sed -e s/-tokin//g | sed -e s/\:\~/+DURATION\>/g | tr '+' ' '
SCR=`echo "SCRIPT /usr/local/hobbit/server/ext/pg/$m REMEDY" | sed -e s/ext-//g | sed -e s/-tokin//g | sed -e s/\:\~/+DURATION\>/g | tr '+' ' '`
echo -n " "
echo $SCR| awk '{print $1" "$2" "$4" "$3}'
;;
pg-*)
echo " MAIL $m" | sed -e s/$PG/$DPG/g | sed -e s/\:\~/+DURATION\>/g | tr '+' ' '
;;
*)
echo " MAIL $m" | sed -e s/\:\~/+DURATION\>/g | tr '+' ' '
;;
esac
done
echo
elif [[ $i == \#* ]]
then
echo $i | tr '+' ' '
else
echo -n '#FIX THIS#'
echo $i | tr '+' ' '
fi
done




 




________________________________
From: spa at syntec.co.uk
To: hobbit at hswn.dk
Date: Wed, 15 Oct 2008 16:25:16 +0100
Subject: RE: [hobbit] Comma-separated lists of hostnames, etc. in hobbit-alerts.cfg is not documented


Thanks for the suggestion.  I'll certainly give that some thought.  Comma-separated is just the easiest when it comes to converting my existing bbwarnrules.cfg file as I can just select the hosts and replace spaces with commas.  Going forward I had thought of using macros, but I'll look at PAGEs too.
 
SebA


________________________________
From: jm54601 at yahoo.com [mailto:jm54601 at yahoo.com] 
Sent: 15 October 2008 16:03
To: hobbit at hswn.dk
Subject: Re: [hobbit] Comma-separated lists of hostnames, etc. in hobbit-alerts.cfg is not documented


I struggled with the same thing through a lot of trial and error.  On a related note, I highly recommend trying to get away from using a comma separated list as it's a nightmare to maintain.  I'm working toward using the PAGE token, where a list of hosts on a given page alerts a group, so you're effectively grouping your hosts based on the support team responsible.  There will still be exceptions, but if you can generalize alerts so all the hosts on a given page can alert the same way, you'll save time and avoid the possibility of a host not having an alert configured.  Just my 2 cents.


 


----- Original Message ----
From: SebA <spa at syntec.co.uk>
To: hobbit at hswn.dk
Sent: Wednesday, October 15, 2008 7:43:35 AM
Subject: [hobbit] Comma-separated lists of hostnames, etc. in hobbit-alerts.cfg is not documented

Comma-separated lists of hostnames in hobbit-alerts.cfg is not documented, so maybe we could add something like this (taken from  http://hobbitmon.sourceforge.net/docs/man5/hobbit-clients.cfg.5.html) to http://hobbitmon.sourceforge.net/docs/man5/hobbit-alerts.cfg.5.html:
        HOST=targetstring Rule matching a host by the hostname.  "targetstring"
        is either a comma-separated list of hostnames (from the bb-hosts file),
        "*"  to  indicate "all hosts", or a Perl-compatible regular expression.
        E.g.  "HOST=dns.foo.com,www.foo.com"  identifies  two  specific  hosts;
        "HOST=%www.*.foo.com  EXHOST=www-test.foo.com" matches all hosts with a
        name beginning with "www", except the "www-test" host. 
Adding an example that used the comma-separated syntax to http://hobbitmon.sourceforge.net/docs/hobbit-alerts.htmland hobbit-alerts.cfg (sample) files would also be good.
And, actually, maybe something to say that the comma-separated syntax can be used in all XXX= places (except, presumably, REPEAT) and also for the recipient.  One really shouldn't have to work this basic stuff out using:
$ ./bin/bbcmd hobbitd_alert --test 
! 
We definitely need some more complex examples.  Maybe someone who has a complex and varied hobbit-alerts.cfg can post some sanitized examples that someone can commit to SVN?
Many thanks, 
SebA 


________________________________
Want to do more with Windows Live? Learn “10 hidden secrets” from Jamie. Learn Now 


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20081015/9c16c20d/attachment.html>


More information about the Xymon mailing list