c509535a971105d071e2c39997ccf5b3a694ecc3
Benjamin Renard initial commit

Benjamin Renard authored 12 years ago

1) #!/bin/bash
2) #
3) # Nagios plugin to check Gnokii USB modem state
4) #
5) # Author : Benjamin Renard <brenard@easter-eggs.com>
6) # Date : Wed, 25 Jul 2012 18:33:33 +0200
7) #
8) 
9) # Path to gnokii binary (default : /usr/bin/gnokii)
10) GNOKII=/usr/bin/gnokii
11) 
12) # Path to gnokii config file (default : /etc/gnokiirc)
13) CONFIG=/etc/gnokiirc
14) 
15) 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\)/' )
16) if [ ! -n "$KEY" ]
17) then
18) 	echo "CRITICAL - USB key not detected"
19) 	exit 2
20) fi
21) 
22) PINSTATUS=$( $GNOKII --config $CONFIG --getsecuritycodestatus 2>/dev/null|grep "Security code status"|sed 's/Security code status: //' )
23) if [ "$PINSTATUS" == "waiting for PIN." ]
24) then
25) 	echo "CRITICAL - SIM Locked ! You have to unlocked SIM !"
26) 	exit 2
27) elif [ "$PINSTATUS" != "nothing to enter." ]
28) then
29) 	echo "UNKNOWN - PIN status unkwown : $PINSTATUS"
30) 	exit 3
31) fi
32) 
Benjamin Renard Add network code and cell id

Benjamin Renard authored 10 years ago

33) NETWORK_CODE=$( $GNOKII --config $CONFIG --getnetworkinfo  2> /dev/null|grep "^Network\s\+code\s\+:\s\+" |sed 's/^Network\s\+code\s\+:\s\+\([^(]*\).*$/\1/')
34) CELL_ID=$( $GNOKII --config $CONFIG --getnetworkinfo  2> /dev/null|grep "^Cell\s\+id\s\+:\s\+" | sed 's/Cell\s\+id\s\+:\s\+\(.*\)\s*$/\1/')
35) 
36) if [ "$NETWORK_CODE" == "" -o $( echo "$NETWORK_CODE"|grep -ic undefined ) -gt 0 ]
37) then  
38) 	# double check with Cell id
39)         if [ "$CELL_ID" == "" -o $( echo "$CELL_ID"|grep -ic "00000000") -gt 0 ]
40)         then
41)         	echo "CRITICAL - Not connected (Network code : $NETWORK_CODE / Cell id : $CELL_ID)"
42) 		exit 2
43)         fi
Benjamin Renard Added network check in nagi...

Benjamin Renard authored 11 years ago

44) fi
45) 
Benjamin Renard Add network code and cell id

Benjamin Renard authored 10 years ago

46) echo "OK - Key : $KEY - SIM Unlocked - Network code : $NETWORK_CODE / Cell id : $CELL_ID"