+

Last commit for check_gnokii: c509535a971105d071e2c39997ccf5b3a694ecc3

Add network code and cell id

Benjamin Renard [2014-02-12 17:37:48]
Add network code and cell id
#!/bin/bash
#
# Nagios plugin to check Gnokii USB modem state
#
# Author : Benjamin Renard <brenard@easter-eggs.com>
# 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_CODE=$( $GNOKII --config $CONFIG --getnetworkinfo  2> /dev/null|grep "^Network\s\+code\s\+:\s\+" |sed 's/^Network\s\+code\s\+:\s\+\([^(]*\).*$/\1/')
CELL_ID=$( $GNOKII --config $CONFIG --getnetworkinfo  2> /dev/null|grep "^Cell\s\+id\s\+:\s\+" | sed 's/Cell\s\+id\s\+:\s\+\(.*\)\s*$/\1/')

if [ "$NETWORK_CODE" == "" -o $( echo "$NETWORK_CODE"|grep -ic undefined ) -gt 0 ]
then
	# double check with Cell id
        if [ "$CELL_ID" == "" -o $( echo "$CELL_ID"|grep -ic "00000000") -gt 0 ]
        then
        	echo "CRITICAL - Not connected (Network code : $NETWORK_CODE / Cell id : $CELL_ID)"
		exit 2
        fi
fi

echo "OK - Key : $KEY - SIM Unlocked - Network code : $NETWORK_CODE / Cell id : $CELL_ID"
exit 0
ViewGit