Added rudimentary arguments

This commit is contained in:
Nis Wechselberg 2018-12-09 16:30:01 +01:00
parent 0a1e1aadd8
commit f3285bf0fe

View file

@ -16,13 +16,18 @@ Small script to request data from the portal pass.telekom.de and
submit it to InfluxDB
"""
import argparse
import requests
from influxdb import InfluxDBClient
REQUEST_API_URL = 'http://pass.telekom.de/api/service/generic/v1/status'
REQUEST_HEADERS = {'User-Agent': 'Mozilla/4.0'}
HOST_NAME = "Neutestorf-RasPi"
parser = argparse.ArgumentParser()
parser.add_argument("hostname", help="Hostname of this machine")
parser.add_argument("influxHost", help="Hostname/IP of the InfluxDB machine")
parser.add_argument("database", help="Name of the database to write to")
args = parser.parse_args()
# Send http request to telekom page and extract json response
response = requests.get(REQUEST_API_URL, headers=REQUEST_HEADERS)
@ -33,7 +38,7 @@ measurement = [
{
"measurement": "pass_telekom_de",
"tags": {
"host": HOST_NAME
"host": args.hostname
},
"fields": {
"initialVolume": respJson['initialVolume'],
@ -45,5 +50,5 @@ measurement = [
]
# Send data to InfluxDB
influx = InfluxDBClient(host='10.91.12.10', database='network')
influx = InfluxDBClient(host=args.influxHost, database=args.database)
influx.write_points(measurement)