+

Add network code and cell id

Benjamin Renard [2014-02-12 17:37:48]
Add network code and cell id
Filename
check_gnokii
diff --git a/check_gnokii b/check_gnokii
index f08a24e..2bcd003 100755
--- a/check_gnokii
+++ b/check_gnokii
@@ -30,12 +30,18 @@ then
 	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
+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 : $NETWORK"
+echo "OK - Key : $KEY - SIM Unlocked - Network code : $NETWORK_CODE / Cell id : $CELL_ID"
 exit 0
ViewGit