nagios3 - custom check scripts
This commit is contained in:
parent
e0ae25569a
commit
014416ba10
|
@ -0,0 +1,96 @@
|
|||
#!/bin/sh
|
||||
# FILE: "check_rtmp"
|
||||
# DESCRIPTION:nagios plugin for checking rtmp streams.
|
||||
# REQUIRES: rtmpdump (http://rtmpdump.mplayerhq.hu/)
|
||||
# AUTHOR: Toni Comerma
|
||||
# DATE: jan-2013
|
||||
# $Id:$
|
||||
#
|
||||
|
||||
PROGNAME=`readlink -f $0`
|
||||
PROGPATH=`echo $PROGNAME | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
|
||||
REVISION=`echo '$Revision: .2 $' | sed -e 's/[^0-9.]//g'`
|
||||
|
||||
RTMPDUMP=`which rtmpdump`
|
||||
|
||||
print_usage() {
|
||||
echo "Usage:"
|
||||
echo " $PROGNAME -u <url> -t <timeout> "
|
||||
echo " $PROGNAME -h "
|
||||
|
||||
|
||||
}
|
||||
|
||||
print_help() {
|
||||
print_revision $PROGNAME $REVISION
|
||||
echo ""
|
||||
print_usage
|
||||
|
||||
echo "Comprova l'estat d'un stream RTMP"
|
||||
echo ""
|
||||
echo "Opcions:"
|
||||
echo " -u URL a testejar Exemple: rtmp://server/app/streamName"
|
||||
echo " -t Temps a monitoritzar"
|
||||
echo ""
|
||||
exit $STATE_UNKNOWN
|
||||
}
|
||||
|
||||
|
||||
|
||||
STATE_OK=0
|
||||
STATE_WARNING=1
|
||||
STATE_CRITICAL=2
|
||||
STATE_UNKNOWN=3
|
||||
|
||||
URL=""
|
||||
TIMEOUT=2
|
||||
|
||||
# Proces de parametres
|
||||
while getopts ":u:t:h" Option
|
||||
do
|
||||
case $Option in
|
||||
u ) URL=$OPTARG;;
|
||||
t ) TIMEOUT=$OPTARG;;
|
||||
h ) print_help;;
|
||||
* ) echo "unimplemented option";;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! $URL ] ; then
|
||||
echo " Error - No URL was specified."
|
||||
echo ""
|
||||
print_help
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Construir noms de fitxers temporals
|
||||
NAME=`echo $URL | sed -e s/[^A-Za-z0-9.]/_/g`
|
||||
ERR=/tmp/check_rtmp_err_$NAME.tmp
|
||||
|
||||
# Testejant
|
||||
( $RTMPDUMP -m 4 --live -r $URL --stop $TIMEOUT > /dev/null 2> $ERR ) & sleep 5; kill $! 2> /dev/null
|
||||
status=$?
|
||||
|
||||
|
||||
# Retorn de resultats
|
||||
CONNECTA=`grep "INFO: Connected" $ERR`
|
||||
|
||||
if [ -z "$CONNECTA" ]
|
||||
then
|
||||
echo "CRITICAL - Cannot connect to the stream: $URL"
|
||||
exit $STATE_CRITICAL
|
||||
else
|
||||
ERROR=`grep "INFO: Metadata:" $ERR`
|
||||
if [ ! -z "$ERROR" ]
|
||||
then
|
||||
echo "OK - stream is normal: $URL"
|
||||
exit $STATE_OK
|
||||
fi
|
||||
echo "CRITICAL - Stream is not broadcasting: $URL"
|
||||
exit $STATE_CRITICAL
|
||||
fi
|
||||
|
||||
echo "UNKNOWN - Unknown output from stream check. Manual check is advised"
|
||||
exit $STATE_UNKNOWN
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# count streams in rtmp
|
||||
|
||||
# get stream count
|
||||
stream_count=`curl -sfq -m1 http://stream.openfest.org/stats | xsltproc /usr/local/bin/count-streams.xsl -`
|
||||
|
||||
_warn=${1:-3}
|
||||
_crit=${2:-6}
|
||||
|
||||
|
||||
_res='3'
|
||||
_data='UNKNOWN - something shitty happened'
|
||||
|
||||
if [ $stream_count -ge $_crit ] ; then
|
||||
_data="OK - stream count $stream_count"
|
||||
_res=0
|
||||
fi
|
||||
|
||||
if [ $stream_count -ge $_crit -a $stream_count -le $_warn ] ; then
|
||||
_data="WARN - stream count $stream_count, less than expected. Min $_crit, needed $_warn"
|
||||
_res=1
|
||||
fi
|
||||
|
||||
if [ $stream_count -lt $_crit ] ; then
|
||||
_data="CRITICAL - Streams lower than $_crit"
|
||||
_res=2
|
||||
fi
|
||||
|
||||
echo $_data
|
||||
exit $_res
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||
<xsl:output method="text" />
|
||||
<xsl:template match="/">
|
||||
<xsl:value-of select="count(/rtmp/server/application/live/stream)"/>
|
||||
</xsl:template>
|
||||
</xsl:transform>
|
Loading…
Reference in New Issue