icecast2influx/icecast2influx.py
2020-04-10 21:15:58 +02:00

38 lines
No EOL
1.1 KiB
Python
Executable file

#!/usr/bin/python3
# preso in parte da qui https://raw.githubusercontent.com/munin-monitoring/contrib/master/plugins/icecast/icecast2_stats_
import datetime
import json
import os
import urllib.request
status_url = "http://stream.radiospore.oziosi.org:8000/status-json.xsl"
def _get_json_statistics():
with urllib.request.urlopen(status_url) as conn:
json_body = conn.read()
return json.loads(json_body.decode("utf-8"))
def get_sources():
sources = []
for source in _get_json_statistics()["icestats"]["source"]:
path_name = source["listenurl"].split("/")[-1]
sources.append({"name": path_name,"listeners": source["listeners"]})
try:
source.append({"title": source["title"]})
except:
pass
#"duration_days": get_iso8601_age_days(source["stream_start_iso8601"])
sources.sort(key=lambda item: item["name"])
return sources
def get_server_uptime_days():
return get_iso8601_age_days(_get_json_statistics()["icestats"]["server_start_iso8601"])
if __name__ == "__main__":
print(get_sources())