Added rudimentary arguments
This commit is contained in:
parent
0a1e1aadd8
commit
f3285bf0fe
1 changed files with 8 additions and 3 deletions
11
PyPass.py
11
PyPass.py
|
@ -16,13 +16,18 @@ Small script to request data from the portal pass.telekom.de and
|
||||||
submit it to InfluxDB
|
submit it to InfluxDB
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
import requests
|
import requests
|
||||||
from influxdb import InfluxDBClient
|
from influxdb import InfluxDBClient
|
||||||
|
|
||||||
REQUEST_API_URL = 'http://pass.telekom.de/api/service/generic/v1/status'
|
REQUEST_API_URL = 'http://pass.telekom.de/api/service/generic/v1/status'
|
||||||
REQUEST_HEADERS = {'User-Agent': 'Mozilla/4.0'}
|
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
|
# Send http request to telekom page and extract json response
|
||||||
response = requests.get(REQUEST_API_URL, headers=REQUEST_HEADERS)
|
response = requests.get(REQUEST_API_URL, headers=REQUEST_HEADERS)
|
||||||
|
@ -33,7 +38,7 @@ measurement = [
|
||||||
{
|
{
|
||||||
"measurement": "pass_telekom_de",
|
"measurement": "pass_telekom_de",
|
||||||
"tags": {
|
"tags": {
|
||||||
"host": HOST_NAME
|
"host": args.hostname
|
||||||
},
|
},
|
||||||
"fields": {
|
"fields": {
|
||||||
"initialVolume": respJson['initialVolume'],
|
"initialVolume": respJson['initialVolume'],
|
||||||
|
@ -45,5 +50,5 @@ measurement = [
|
||||||
]
|
]
|
||||||
|
|
||||||
# Send data to InfluxDB
|
# 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)
|
influx.write_points(measurement)
|
||||||
|
|
Loading…
Reference in a new issue