[mythtv-users] What lessons can I learn from this?

David Snider david at davidsnider.org
Tue Jun 18 19:54:04 UTC 2013


I have a couple scripts that I run through nagios, one to check the tuners, the other for guide days…  I believe I originally got them from somewhere online, but modified for my use.    I have them plugged into Nagios as commands…  how to set that up is an exercise for the reader.. :D  Super simple scripts with little to no error checking/handling… but it works for me.

#######Check Tuners Script
# cat nagios_check_mythtv.sh 
#!/bin/bash 
# This script will check the http status page for mythtv and look for Tuner Status
# the following command line arguments:
# -E Encoder Name i.e. "Encoder 2"
# -L Locality i.e local or remote
# -H Host the encoder lives on

#Usage function
function Usage()
{
	printf "Usage: %s: [-E Encoder, i.e. 1] [-L encoder location, i.e. "local" or "remote"] [-H host]\n" $0
	exit 3
}

#Setup the command line options
EFLAG=
ENCODER=
LFLAG=
LOCALITY=
HFLAG=
HOST=
while getopts E:L:H: name
do
	case $name in
	E)	EFLAG=1
		ENCODER="$OPTARG";;
	L)	LFLAG=1
		LOCALITY="$OPTARG";;
	H)	HFLAG=1
		HOST="$OPTARG";;
	?)	Usage;;
	esac
done
shift $(($OPTIND - 1))

#Make sure we have all the options parsed that we need
if [ -z $EFLAG ]
then
	echo "No Encoder Specified"
	Usage
fi

if [ -z $LFLAG ]
then
	echo "No Locality specified"
	Usage
fi

if [ -z $HOST ]
then
	echo "No Host specified"
	Usage
fi

#Get the output and store it in a variable
out=$(/usr/bin/wget http://mythhost/mythweb/status --user mythuser --password mythpass -O - -q|\
	/usr/bin/html2text|\
	egrep "Encoder $ENCODER .* is $LOCALITY on $HOST" |\
	cut -f1 -d\<) 

#Do the Nagios checks
rc=0
echo $out | egrep -q "is recording|is not recording|is watching Live TV"
if [ "$?" -ne 0 ]
then
	mesg="Tuner Status Invalid: "
	rc=2
	echo "$mesg" "$out"
else
	mesg="Tuner OK: "
	rc=0
	echo "$mesg" "$out"
fi
exit $rc

#####Check how many days are in the guide
#######Check Tuners Script


# cat nagios_check_mythtv_guide.sh 
#!/bin/bash 
#Usage function
function Usage()
{
	printf "Usage: %s: \n" $0
	exit 3
}

#Get the output and store it in a variable
out=$(/usr/bin/wget http://mythhost/mythweb/status --user mythuser --password mythpass -O - -q|\
	/usr/bin/html2text|\
	egrep "guide data .* \(.*\)" |\
	cut -f2 -d\(|\
	cut -f1 -d\)|\
	sed 's/ days//g') 

#Do the Nagios checks
rc=0
if [ "$out" -gt 11 ]
then
	mesg="Gude Data OK: $out days"
	rc=0
	echo "$mesg"
else
	mesg="Guide Data is Critical: $out days"
	rc=2
	echo "$mesg"
fi
exit $rc


On Jun 18, 2013, at 7:48 AM, Tom Lichti <tom at redpepperracing.com> wrote:

> 
> On Tue, Jun 18, 2013 at 8:31 AM, Simon Hobson <linux at thehobsons.co.uk> wrote:
> LAUKENS Niels wrote:
> >Although this is getting off-topic, for the record: Nagios can accept
> >"alerts" from pretty much anywhere. Either use "send_nsca", or write
> >directly to the "external command file" with your updated information.
> 
> Indeed. Plus, for active monitoring, if you can write a script to do it, Nagios can monitor it. In essence, the monitoring side of Nagios is just calling scripts and processing the response code (OK, Warning, Critical, Unknown). So pretty well all you need to do is write a script (optionally taking some parameters), and have it spit out a one-line result - whatever goes inside is up to you and can be as simple or complex as you like/need/can cope with.
> 
> Though I have to agree with an easrlier comment - it's a bit heavyweight, and has a fairly steep learning curve until you get your head round it.
> 
> 
> Yeah, unfortunately (fortunately?) I have a *lot* of experience with it. I originally started using it when it was still called Netsaint (circa 2000) . Now I am a slave to HP... :)
> 
> Anyway, if I get some time I'll try and take a look at the plugin and see what it does, it could be relatively easy to port to a newer version of MythTV.
> 
> Tom 
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at mythtv.org
> http://www.mythtv.org/mailman/listinfo/mythtv-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mythtv.org/pipermail/mythtv-users/attachments/20130618/65bcfc75/attachment-0001.html>


More information about the mythtv-users mailing list