From fc4020b477bb2783c6d29d724878579b3e452ebb Mon Sep 17 00:00:00 2001 From: vvitkov Date: Wed, 31 Oct 2018 16:10:49 +0200 Subject: [PATCH] old nagios checks --- .../nagios/check-wifi-interface-up.sh | 61 ++++++++++++ .../custom-scripts/nagios/check_rtmp.sh | 95 +++++++++++++++++++ .../custom-scripts/nagios/count-streams.sh | 31 ++++++ 3 files changed, 187 insertions(+) create mode 100644 monitoring/custom-scripts/nagios/check-wifi-interface-up.sh create mode 100644 monitoring/custom-scripts/nagios/check_rtmp.sh create mode 100644 monitoring/custom-scripts/nagios/count-streams.sh diff --git a/monitoring/custom-scripts/nagios/check-wifi-interface-up.sh b/monitoring/custom-scripts/nagios/check-wifi-interface-up.sh new file mode 100644 index 0000000..53fbd00 --- /dev/null +++ b/monitoring/custom-scripts/nagios/check-wifi-interface-up.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Simple script to check if remote wifi if is up +# +# 2016.10.20 - Initial version +# +# copyright: 2016 Vladimir Vitkov + +# helpers +E_OK=0 +E_WARNING="1" +E_CRITICAL="2" +E_UNKNOWN="3" + +_community=${1} +_hostname=${2} +_interface=${3} + +# Sanity check +if [ $# -ne 3 ]; then + echo "UNKNOWN: Missing parameters $0 " + exit ${E_UNKNOWN} +fi + +function find_oid() { + # oids + # .1.3.6.1.2.1.2.2.1.2 - IF-MIB::ifDescr + _oid=$( + snmpwalk \ + -v2c \ + -c ${_community} \ + -On \ + -m '' \ + -t 1 \ + -r 5 \ + -Oqn \ + ${_hostname} \ + .1.3.6.1.2.1.2.2.1.2 | \ + egrep ${_interface} | \ + awk '{print $1}' + ) + + echo ${_oid} +} + +function check_status() { + # lets have the id please + _id=$(echo ${1} | awk -F'.' '{print $NF}') + # oids + # .1.3.6.1.2.1.2.2.1.8 - IF-MIB::ifOperStatus + /usr/lib/nagios/plugins/check_snmp \ + -H ${_hostname} \ + -P 2c \ + -C ${_community} \ + -c 1 \ + -o .1.3.6.1.2.1.2.2.1.8.${_id} + + exit $? +} +OID=`find_oid` +check_status ${OID} \ No newline at end of file diff --git a/monitoring/custom-scripts/nagios/check_rtmp.sh b/monitoring/custom-scripts/nagios/check_rtmp.sh new file mode 100644 index 0000000..025c848 --- /dev/null +++ b/monitoring/custom-scripts/nagios/check_rtmp.sh @@ -0,0 +1,95 @@ +#!/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 -t " + 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 \ No newline at end of file diff --git a/monitoring/custom-scripts/nagios/count-streams.sh b/monitoring/custom-scripts/nagios/count-streams.sh new file mode 100644 index 0000000..7118ff0 --- /dev/null +++ b/monitoring/custom-scripts/nagios/count-streams.sh @@ -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 \ No newline at end of file