From jonescr@cisco.com Wed Jun 24 08:17:14 2026 From: jonescr@cisco.com To: xymon@xymon.com Subject: contchk.sh (submission) Date: Wed, 30 Jan 2008 11:22:05 -0700 Message-ID: <47A0C04D.1050903@cisco.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4367526153331808635==" --===============4367526153331808635== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The past week I've been trying to share any of the hobbit ext scripts that I wrote. Here's another, contchk.sh. I initially created it because Hobbits content check does not follow "302 Redirect" response codes, and I also had a need to check a URL which was expecting a certain referrer. I remembered I was using this script when I saw Gary Baluha's urlplus.pl. Incidentally, I cannot use urlplus, as it makes use of bbhostgrep, which I discovered fails if your bb-host entries are too long. contchk.sh is a fairly short bash script which makes use of curl. You can optionally specify a referrer to spoof. For most folks, Garys script is probably best to use, as it has more enhanced error messages and such. If anything, it's interesting to see different ways multiple people tackle a problem :) Note: besides the script itself (which should reside in $BBHOME/ext), you will need to add this to your $BBHOME/etc/hobbitlaunch.cfg: [contchk] ENVFILE /home/monitor/server/etc/hobbitserver.cfg NEEDS hobbitd CMD $BBHOME/ext/contchk.sh LOGFILE $BBSERVERLOGS/contchk.log INTERVAL 5m -Charles #!/bin/bash # contchk.sh written by Charles Jones (blazer0x at gmail.com) 6/6/2007 # This script is designed to perform a content check on a URL and report the # status to a Hobbit server. # # This script was created because Hobbits built-in content check functionality # does not follow 302 redirects. # # The script parses out a "contchk" tag in the bb-hosts file. The proper # syntax is: contchk;URL;REFERRER;CHECKSTRING # # Note that CHECKSTRING cannot contain spaces so you must use regular # expression metacharacters, so use something like string.with.spaces BBHTAG=contchk # Name of the tag in bb-hosts COLUMN=cont # Column display name in Hobbit CURL=/usr/bin/curl # Location of curl binary CURLOPTS="--connect-timeout 30 -m 30 -s -L -b cookiejar" # Curl options # Note: using grep because bbhostgrep fails on long lines grep $BBHTAG $BBHOME/etc/bb-hosts | while read L do set $L # To get one line of output from bbhostgrep HOSTIP="$1" MACHINEDOTS="$2" MACHINE=`echo $2 | $SED -e's/\./,/g'` CHECKURL=`echo $4 | awk -F";" '{print $2}'` # Parse out the check URL REFERRER=`echo $4 | awk -F";" '{print $3}'` # Parse out the referrer string if [ "" != "$REFERRER" ]; then REFERRER="-e $REFERRER" fi CHECKSTRING=`echo $4 | awk -F";" '{print $4}'` # Parse out the check string $CURL $CURLOPTS $REFERRER $CHECKURL |grep -q "$CHECKSTRING" status=$? # Save greps return status if [ 0 -eq $status ]; then # grep returns 0 if it found something COLOR=green MSG="String \"$CHECKSTRING\" was found in $CHECKURL" $BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date` Content Check OK ${MSG} " else # grep didn't find anything COLOR=red MSG="String \"$CHECKSTRING\" was NOT FOUND in $CHECKURL" $BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date` Content Check FAILED ${MSG} " fi done exit 0 --===============4367526153331808635==-- From gumby3203@gmail.com Wed Jun 24 08:17:14 2026 From: gumby3203@gmail.com To: xymon@xymon.com Subject: [hobbit] contchk.sh (submission) Date: Thu, 31 Jan 2008 11:35:51 -0500 Message-ID: <29f517690801310835i4696d199o4df5c2d0d4b6931e@mail.gmail.com> In-Reply-To: <47A0C04D.1050903@cisco.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2906329626867385512==" --===============2906329626867385512== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On Jan 30, 2008 1:22 PM, Charles Jones wrote: > ...I remembered I was using this script when I saw Gary > Baluha's urlplus.pl. > > Incidentally, I cannot use urlplus, as it makes use of bbhostgrep, which > I discovered fails if your bb-host entries are too long. > Hmm, I haven't run into bb-host entries that long. Can you give an example of one of them? I'd be interested in seeing if my script can be tweaked to work around that issue. Incidentally, I'm working on another release of urlplus that adds form submission checking, as well as being able to handle multiple-step form submissions (submit something to one webpage, check the result and submit on that new webpage, etc). I'm also cleaning up the commenting and rearranging a few things in the code to make it easier to modify (including a hard-coded value that I moved to a user-modifiable constant. --===============2906329626867385512==--