Projects > Opengear Cell Signal Report

Description

Simple Python script that connects to a list of Opengear devices and returns their cell signal properties. A small reference guide is included to help make sense of the values.

#Script created by Brian Winning Jr. please feel free to modify to fit your particular needs.
from __future__ import print_function	#Imports print module from future, for python3 print syntax in pre3 versions.
import sys, paramiko	#Imports paramiko module that enables us to open SSH connections.
import smtplib	#Imports smtplib module that enables us to open an smtp connection and send mail.
#Device List, the script will connect to these devices.
opengears = ["device1.yourdomain.com","device2.yourdomain.com","device3.yourdomain.com","device4.yourdomain.com","device5.yourdomain.com","device6.yourdomain.com","device7.yourdomain.com","device8.yourdomain.com","device9.yourdomain.com","device10.yourdomain.com","device11.yourdomain.com"]
#Use test group to test changes by updating hostname under client.connect and for loop
testgroup = ["dev-device1.yourdomain.com", "dev-device2.yourdomain.com","dev-device3.yourdomain.com"]
print("Opengear Cell Signal Report\n")	#Opening statement the user will see when this script is first run.
print("This program will check and report on the cell signal of all opengear devices.\n")	#A brief description about the script to the user
print('Please allow a few minutes while the following devices are checked:\n') #Further information for the user on what to expect while the script is running and what devices will be checked.
for opengear in opengears:	#For loop used to print list of all devices in the list
	print(opengear)	#Prints device named as listed in list opengears
print("")	#empty space before next line.
clientport = 22		#The port that SSH is available on for the Opengear devices.
clienttimeout = 3	#This timeout determines how long the script waits for a device to respond before moving onto the next device in the list.
clientuser = 'root' #User needs to be root to access cellctl commands
clientpass = 'Your Password'	#Your Opengear root user password.
client = paramiko.SSHClient()	#Loads Paramiko
client.load_system_host_keys()	#loads system SSH host keys into scripts for use
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())	#Adds any new devices in the list or change of SSH host keys to the users hosts file if they are not already present. This is needed if your have not connected to the devices from the host where the script is being run before.
for opengear1 in opengears:	#For loop that is used to connect to all of the devices, this helps keep the script simple and short. All the below commands until the indentation ends will be repeated for each device in the list.
	try:	#starts capture for error handling.
		client.connect(hostname = opengear1, username = clientuser,password = clientpass, port = clientport, timeout = clienttimeout)	#makes the initial connection to the devices and specifies the parameters we set above in the script.
		stdin, stdout, stderr = client.exec_command('cellctl -is | grep signal-lte-rssi')	#Executes the command in quotations on the device and writes to the variable stdout
		stdin1, stdout1, stderr1 = client.exec_command('cellctl -is | grep signal-lte-rsrq') #Executes the command in quotations on the device and writes to the variable stdout1
		stdin2, stdout2, stderr2 = client.exec_command('cellctl -is | grep signal-lte-rsrp') #Executes the command in quotations on the device and writes to the variable stdout2
		stdin3, stdout3, stderr3 = client.exec_command('cellctl -is | grep signal-lte-snr')	#Executes the command in quotations on the device and writes to the variable stdout3
		output = stdout.readlines()		##Writes all lines in stdout variable to output
		output1 = stdout1.readlines()	#Writes all lines in stdout1 variable to output1
		output2 = stdout2.readlines()	#Writes all lines in stdout2 variable to output2
		output3 = stdout3.readlines()	#Writes all lines in stdout3 variable to output3
		print("#################################################################")	#Text seperator in the script for cosmetic reasons.
		print("" ,opengear1, "cellular signal:")										#Prints Opengear devices name followed by cellular signal.
		print("#################################################################\n")	#Text seperator in the script for cosmetic reasons.	
		print("RSSI Values Explained: Poor <-85, Fair -75 to -85, Good -65 to -75, Excellent >-65")
		print("RSRQ Values Explained: Poor <-11, Fair -6 to -10, Good -6 to -10, > Excellent > -5")
		print("RSRP Values Explained: Poor <-112, Fair -103 to -111, Good -85 to -102, Excellent >-84")
		print("SNR Values Explained: Poor <7, Fair 7 to 10, Good 10 to 12.5, Excellent >12.5\n")
		print (''.join(output)) #Joins the several strings of output captured in the output variable into one.
		print (''.join(output1))	#Joins the several strings of output captured in the output1 variable into one.
		print (''.join(output2))	#Joins the several strings of output captured in the output2 variable into one.
		print (''.join(output3))	#Joins the several strings of output captured in the output3 variable into one.

	except paramiko.SSHException:	#Specifies Specific Error Condition
		print("Connection Failed")	#Prints to screen user-friendly error message
		pass 		#Take No Action
		continue 	#Specifies Loop Should Continue to Next List Item Despite Error
	except paramiko.SSHException, socket.timeout:	#Specifies Specific Error Condition
		print("Socket Timeout - Script Will Continue")	#Prints to screen user-friendly error message
		pass 		#Take No Action
		continue 	#Specifies Loop Should Continue to Next List Item Despite Error
	except paramiko.SSHException, socket.error:		#Specifies Specific Error Condition
		print("Socket Error - Script Will Continue")	#Prints to screen user-friendly error message
		pass 			#Take No Action
		continue 		##Specifies Loop Should Continue to Next List Item Despite Error
	except Exception:	#Specifies Error Condition
		print(str(opengear1) + " will be skipped undefined Error - Script Will Continue\n")	#Prints to screen user-friendly error message
		pass 		#Take No Action
		continue 	#Specifies Loop Should Continue to Next List Item Despite Error

for opengear2 in opengears:	#For loop that loops through the entire list of Opengear devices and issues a client.close(), to close out each device session.
	client.close()	#Closes SSH connection

Features

  • Connects to list of Opengear devices and polls values from cellctl command.
  • Prints out values to screen with reference guide.
  • Reports on 4G LTE Signal

Download




Download Verification:
  • SHA-512:9b940b6ed1476d4020a2462fcbc526e3e63e0b2a31f90fb446cc8bba08da3cd1c5d4d786d47ea787d24bb76373251d143cdabe441c05a3c2b003b3a9b7d199b8
  • SHA-256:0cee6a16ee6b7e0d08fe98a9496bc1ecb1224c9ce172518969e2cc25b1fb45f9
  • SHA-1:d35291ba335d8c2ffd0e1ada5a810a59fe295775
  • MD5:fa6589d9c588f3c476f47ecb996183e3

  • Version 1.0: First public release, November 3rd 2018.

Licensing

Copyright 2018 Brian Winning Jr

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.