Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 conversion #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 68 additions & 63 deletions aaisp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import json
import os
import sys
import urllib
import json
from urllib.request import urlopen


def main():
username = os.environ.get("aaispuser")
password = os.environ.get("aaisppass")
if username is None or password is None:
print "Username and/or password not provided"
print("Username and/or password not provided")
sys.exit(1)
post_params = "control_login=%s&control_password=%s" % (username, password)
url = "https://chaos2.aa.net.uk/broadband/info"
response = urllib.urlopen(url, data=post_params)
response = urlopen(url, data=post_params.encode('utf-8'))
data = json.loads(response.read())
services = get_services(data=data)
if len(sys.argv) == 2:
Expand All @@ -23,84 +24,87 @@ def main():
fetch(services=services)
sys.exit(0)


def config(services):
print ""
print("")
if len([s for s in services if "quota_monthly" in s]) > 1:
print ""
print "multigraph quota_combined"
print "graph_title AAISP Quota remaining - All lines"
print "graph_category broadband"
print "graph_vlabel Data remaining"
for key, service in services.iteritems():
print("")
print("multigraph quota_combined")
print("graph_title AAISP Quota remaining - All lines")
print("graph_category broadband")
print("graph_vlabel Data remaining")
for key, service in services.items():
if "quota_monthly" in service:
print "quota_%s.label %s" % (key, service["title"])
print("quota_%s.label %s" % (key, service["title"]))
if len(services) > 1:
print ""
print "multigraph syncrate_downstream_combined"
print "graph_title AAISP Sync downstream - All lines"
print "graph_category broadband"
print "graph_vlabel Rate"
for key, service in services.iteritems():
print "downstream_%s.label %s" % (key, service["title"])
print ""
print "multigraph syncrate_upstream_combined"
print "graph_title AAISP Sync upstream - All lines"
print "graph_category broadband"
print "graph_vlabel Rate"
for key, service in services.iteritems():
print "upstream_%s.label %s" % (key, service["title"])
print("")
print("multigraph syncrate_downstream_combined")
print("graph_title AAISP Sync downstream - All lines")
print("graph_category broadband")
print("graph_vlabel Rate")
for key, service in services.items():
print("downstream_%s.label %s" % (key, service["title"]))
print("")
print("multigraph syncrate_upstream_combined")
print("graph_title AAISP Sync upstream - All lines")
print("graph_category broadband")
print("graph_vlabel Rate")
for key, service in services.items():
print("upstream_%s.label %s" % (key, service["title"]))

for key, service in services.iteritems():
for key, service in services.items():
if "quota_monthly" in service:
print ""
print "multigraph quota_%s" % (key)
print "graph_title AAISP Quota - %s" % (service["title"])
print "graph_category broadband"
print "graph_vlabel Data"
print "quota.label Quota"
print "remaining.label Remaining"
print ""
print "multigraph syncrate_%s" % (key)
print "graph_title AAISP Sync - %s" % (service["title"])
print "graph_category broadband"
print "graph_vlabel Rate"
print "downstream.label Downstream"
print "upstream.label Upstream"
print("")
print("multigraph quota_%s" % (key))
print("graph_title AAISP Quota - %s" % (service["title"]))
print("graph_category broadband")
print("graph_vlabel Data")
print("quota.label Quota")
print("remaining.label Remaining")
print("")
print("multigraph syncrate_%s" % (key))
print("graph_title AAISP Sync - %s" % (service["title"]))
print("graph_category broadband")
print("graph_vlabel Rate")
print("downstream.label Downstream")
print("upstream.label Upstream")


def fetch(services):
if len([s for s in services if "quota_monthly" in s]) > 1:
print ""
print "multigraph quota_combined"
for key, service in services.iteritems():
print("")
print("multigraph quota_combined")
for key, service in services.items():
if "quota_monthly" in service:
remaining = int(service["quota_remaining"])
print "quota_%s.value %s" % (key, remaining)
print("quota_%s.value %s" % (key, remaining))
if len(services) > 1:
print ""
print "multigraph syncrate_downstream_combined"
for key, service in services.iteritems():
print("")
print("multigraph syncrate_downstream_combined")
for key, service in services.items():
downstream = int(service["tx_rate"])
print "downstream_%s.value %s" % (key, downstream)
print ""
print "multigraph syncrate_upstream_combined"
for key, service in services.iteritems():
print("downstream_%s.value %s" % (key, downstream))
print("")
print("multigraph syncrate_upstream_combined")
for key, service in services.items():
upstream = int(service["rx_rate"])
print "upstream_%s.value %s" % (key, upstream)
print("upstream_%s.value %s" % (key, upstream))

for key, service in services.iteritems():
for key, service in services.items():
if "quota_monthly" in service:
print ""
print "multigraph quota_%s" % (key)
print("")
print("multigraph quota_%s" % (key))
monthly = int(service["quota_monthly"])
remaining = int(service["quota_remaining"])
print "quota.value %s" % (monthly)
print "remaining.value %s" % (remaining)
print ""
print "multigraph syncrate_%s" % (key)
print("quota.value %s" % (monthly))
print("remaining.value %s" % (remaining))
print("")
print("multigraph syncrate_%s" % (key))
upstream = int(service["rx_rate"])
downstream = int(service["tx_rate"])
print "upstream.value %s" % (upstream)
print "downstream.value %s" % (downstream)
print("upstream.value %s" % (upstream))
print("downstream.value %s" % (downstream))


def get_services(data):
services = {}
Expand All @@ -114,5 +118,6 @@ def get_services(data):
services[service["value"]]["title"] = service["title"]
return services


if __name__ == "__main__":
main()