#!/bin/bash # # Nagios plugin to check Gnokii USB modem state # # Author : Benjamin Renard # Date : Wed, 25 Jul 2012 18:33:33 +0200 # # Path to gnokii binary (default : /usr/bin/gnokii) GNOKII=/usr/bin/gnokii # Path to gnokii config file (default : /etc/gnokiirc) CONFIG=/etc/gnokiirc KEY=$( $GNOKII --config $CONFIG --identify 2>/dev/null|tr '\n' " "|grep IMEI|sed 's/IMEI *: \([0-9]*\) Manufacturer *: \(.*\) Model *: \(.*\) Product name.*Revision.*/\2 \3 \(IMEI \: \1\)/' ) if [ ! -n "$KEY" ] then echo "CRITICAL - USB key not detected" exit 2 fi PINSTATUS=$( $GNOKII --config $CONFIG --getsecuritycodestatus 2>/dev/null|grep "Security code status"|sed 's/Security code status: //' ) if [ "$PINSTATUS" == "waiting for PIN." ] then echo "CRITICAL - SIM Locked ! You have to unlocked SIM !" exit 2 elif [ "$PINSTATUS" != "nothing to enter." ] then echo "UNKNOWN - PIN status unkwown : $PINSTATUS" exit 3 fi NETWORK=$( $GNOKII --config $CONFIG --monitor once 2> /dev/null|grep ^Network|sed 's/^Network: \([^(]*\).*$/\1/' ) if [ "$NETWORK" == "" -o $( echo "$NETWORK"|grep -ic unknown ) -gt 0 ] then echo "CRITICAL - Not connected (Network : $NETWORK)" exit 2 fi echo "OK - Key : $KEY - SIM Unlocked - Network : $NETWORK" exit 0