Munin huawei b525

Iš Žinynas.
Jump to navigation Jump to search

Bibliotekų sudiegimas[keisti]

apt install python-pip python-requests python-xmltodict
pip install huawei_lte

Munin pluginas[keisti]

FIXME

rrdtool grafikas[keisti]

Hauaweib525-rrdtool.png

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# (c) 2020 e1z0 (https://github.com/e1z0)
# only for python2 at the time, huh :|
import os
import time
import argparse as ap
import rrdtool
import huawei_lte.router as lte
import huawei_lte.xmlobjects as xmlobjects
from huawei_lte.errors import RouterError
import xmltodict
import re

# SOME SETTINGS
device = '192.168.1.1'
username = 'admin'
password = 'passwordasso'
html_dir = '/var/www/html/huawei/'
# SETTINGS END



def ReturnStat():
 try:
   router = lte.B525Router(device)
   router.login(username=username, password=password) #Throws RouterError on a login error
   resp = router.device.signal
   doc = xmltodict.parse(resp)
   router.logout()
 except:
   print "Currently routers seems to be busy!"
   exit(1)
 return doc['response']

def FixOutput(ina):
 outa = re.sub('[^0-9-]','', ina)
 return str(outa)

def Initialize():
 print ("I should do some initialization here")
 ret = rrdtool.create("huawei.rrd", "--step", "60",
 "DS:rsrp:GAUGE:120:-200:0",
 "DS:rsrq:GAUGE:120:-200:0",
 "RRA:AVERAGE:0.5:1:2880",
 "RRA:MAX:0.5:1:2880",
 "RRA:AVERAGE:0.5:10:144",
 "RRA:MAX:0.5:10:144")

def UpdateRRD():
 print ("Updating rrdtool database")
 data = ReturnStat()
 ret = rrdtool.update('huawei.rrd', 'N:%s:%s' %(FixOutput(data['rsrp']), FixOutput(data['rsrq'])));

def JustRead():
 obj = ReturnStat()
 print "Reference Signal Received Power: "+FixOutput(obj['rsrp'])
 print "Reference Signal Received Quality: "+FixOutput(obj['rsrq'])
 print "Signal to Interference & Noise Ratio: "+FixOutput(obj['sinr'])

def Graph():
 print ("Generating graphs")
 for sched in ['daily' , 'weekly', 'monthly']:
    if sched == 'weekly':
        period = 'w'
    elif sched == 'daily':
        period = 'd'
    elif sched == 'monthly':
        period = 'm'
    ret = rrdtool.graph( html_dir+"metrics-%s.png" %(sched), "--start", "-1%s" %(period), "--vertical-label=Huawei B525 4G",
         '--watermark=Signal Strength',
         "-h 200",
         "-w 600",
         "--right-axis=0.1:0",
	 "--right-axis-label=rsrq",
         "DEF:rsrp=huawei.rrd:rsrp:AVERAGE",
         "DEF:rsrq=huawei.rrd:rsrq:AVERAGE",
	 "CDEF:rsrqScaled=rsrq,10,*",
         "AREA:rsrp#54EC48CC",
         "LINE1:rsrp#24BC14:rsrp",
         "AREA:rsrqScaled#48C4EC",
         "LINE1:rsrqScaled#1598C3:rsrq",
         "GPRINT:rsrp:AVERAGE:Ø rsrp\:%1.0lf dB\t",
    	 "GPRINT:rsrq:AVERAGE:Ø rsrq\:%1.0lf dB\t",
    	 "GPRINT:rsrp:LAST:last rsrp\:%1.0lf dB\t",
    	 "GPRINT:rsrq:LAST:last rsrq\:%1.0lf dB\t")

os.chdir(os.path.dirname(__file__))
parser = ap.ArgumentParser(description="Show huawei b525 modem signal strengths")
parser.add_argument('--initialize', help='Initialize rrdtool database file',action='store_true')
parser.add_argument('--graph', help='Write cool graph',action='store_true')
parser.add_argument('--update', help='Update RRD database',action='store_true')
args = parser.parse_args()
if args.graph is True:
 Graph()
elif args.update is True:
 UpdateRRD()
elif args.initialize is True:
 Initialize()
else:
 JustRead()


Originalus b525 repozitorius[keisti]