Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 89 lines (69 sloc) 3.42 KB
#!/usr/bin/env python
import argparse, requests
from influxdb import InfluxDBClient
import os, time, json
from pprint import pprint
WAIT_TIME = 60 # seconds
def main(host='localhost', port=8086):
user = 'admin'
password = 'admin'
dbname = 'beastcraft'
dbclient = InfluxDBClient(host, port, user, password, dbname)
host = '172.17.0.1'
url = 'http://%s/goform/goform_get_cmd_process' % host
query_strings = [{'multi_data': 1,
'isTest': 'false',
'sms_received_flag_flag': 0,
'sts_received_flag_flag': 0,
'cmd': 'modem_main_state,pin_status,loginfo,new_version_state,current_upgrade_state,is_mandatory,sms_received_flag,sts_received_flag,signalbar,network_type,network_provider,ppp_status,EX_SSID1,ex_wifi_status,EX_wifi_profile,m_ssid_enable,sms_unread_num,RadioOff,simcard_roam,lan_ipaddr,station_mac,battery_charging,battery_vol_percent,battery_pers,spn_display_flag,plmn_display_flag,spn_name_data,spn_b1_flag,spn_b2_flag,realtime_tx_bytes,realtime_rx_bytes,realtime_time,realtime_tx_thrpt,realtime_rx_thrpt,monthly_rx_bytes,monthly_tx_bytes,monthly_time,date_month,data_volume_limit_switch,data_volume_limit_size,data_volume_alert_percent,data_volume_limit_unit,roam_setting_option,upg_roam_switch,hplmn'},
{'isTest': 'false',
'cmd': 'ConnectionMode'}]
hdrs = {'Referer': 'http://%s/' % host}
while True:
try:
for query_string in query_strings:
r = requests.get(url,
params=query_string,
headers=hdrs)
res = json.loads(r.text, strict=False)
for k,v in res.iteritems():
try:
res[k] = float(v)
except ValueError:
pass
try:
res[k] = int(v)
except ValueError:
pass
l = []
for measurement, value in res.iteritems():
t = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
if not value: continue
json_body = {
"measurement": measurement,
"tags": {
"modem": host,
},
"time": t,
"fields": {
"value": value
}
}
l.append(json_body)
print("Write points: {0}".format(l))
dbclient.write_points(l)
time.sleep(WAIT_TIME)
except Exception, e:
print '%s retrieving modem stats, retrying in %d seconds' % (repr(e), WAIT_TIME)
time.sleep(WAIT_TIME)
def parse_args():
parser = argparse.ArgumentParser(
description='example code to play with InfluxDB')
parser.add_argument('--host', type=str, required=False, default='localhost',
help='hostname of InfluxDB http API')
parser.add_argument('--port', type=int, required=False, default=8086,
help='port of InfluxDB http API')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
main(host=args.host, port=args.port)