Skip to content

Commit

Permalink
Merge pull request #3 from hfox/master
Browse files Browse the repository at this point in the history
Pull request
  • Loading branch information
mattribbins committed Mar 22, 2018
2 parents c10fd11 + 155f68f commit 5531ff8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 57 deletions.
118 changes: 62 additions & 56 deletions icecast2_all 100644 → 100755
@@ -1,5 +1,5 @@
#! /usr/bin/python
# -*- coding: iso-8859-1 -*-
#! /usr/bin/python3
# -*- mode: python; coding: utf-8-unix; -*-

# IceCast2 stats plugin for Munin
# Author: Matt Ribbins (mattyribbo.co.uk)
Expand Down Expand Up @@ -27,14 +27,16 @@
#################
# Configuration #
#################
import os
# Hostname of Icecast server
# Just canonical name, no http:// nor ending /, include port number if required
host = "localhost:8000"
host = os.getenv('ice2host','localhost:8000')
# inset some descriptive name, to distinguish server on multiple plugin instances
host_desc = "My icecast server"
# Username and password to the administration panel
username = "admin"
password = "changemenow"
username = os.getenv('ice2user','admin')
password = os.getenv('ice2pass','hackme')


#######################
# Magic happens below #
Expand All @@ -45,61 +47,65 @@ from xml.dom import minidom

host = "http://" + host + "/admin/stats"


def munin_print(u):
sys.stdout.buffer.write((u+"\n").encode('ascii','replace'))

def ic2xml():
# Get the XML with all the stats,
req = requests.get(host, auth=(username, password))
# Get the XML with all the stats,
req = requests.get(host, auth=(username, password))

xmldoc = minidom.parseString(req.text)
xmldoc = xmldoc.firstChild
xmldoc = minidom.parseString(req.text)
xmldoc = xmldoc.firstChild

total_listeners = xmldoc.getElementsByTagName("listeners")[0].firstChild.nodeValue
total_sources = xmldoc.getElementsByTagName("sources")[0].firstChild.nodeValue
total_listeners = xmldoc.getElementsByTagName("listeners")[0].firstChild.nodeValue
total_sources = xmldoc.getElementsByTagName("sources")[0].firstChild.nodeValue

sources = xmldoc.getElementsByTagName("source")
sourcelist = {}
for source in sources:
if len(source.childNodes) <= 3:
continue
mount = source.getAttribute("mount")
listeners = source.getElementsByTagName("listeners")[0].firstChild.nodeValue
name = source.getElementsByTagName("server_name")[0].firstChild.nodeValue
mount = mount.replace("-", "_").replace(".", "_")
sourcelist[mount[1:]] = (listeners, name)
sources = xmldoc.getElementsByTagName("source")
sourcelist = {}
for source in sources:
if len(source.childNodes) <= 3:
continue
mount = source.getAttribute("mount")
listeners = source.getElementsByTagName("listeners")[0].firstChild.nodeValue
name = source.getElementsByTagName("server_name")[0].firstChild.nodeValue
mount = mount.replace("-", "_").replace(".", "_")
sourcelist[mount[1:]] = (listeners, name)

if len(sys.argv) > 1:
if sys.argv[1] == "autoconf":
print("yes")
elif sys.argv[1] == "dump":
print(req.text)
elif len(sys.argv) == 1 or sys.argv[1] != "config":
print(("totallisteners.value" + total_listeners))
print(("totalsources.value " + total_sources))
sourcesort = list(sourcelist.keys())
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
print((source + ".value " + listeners))
elif sys.argv[1] == "config":
print ("graph_title Total number of listeners on " + host_desc)
print ("graph_vlabel listeners")
print ("graph_category Icecast")
print ("totallisteners.label Total number of listeners")
print ("totalsources.label Totalt number of sources")
sourcesort = list(sourcelist.keys())
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
print((source + ".label /" + source))
else:
print((sys.argv[1]))
else:
print(("totallisteners.value " + total_listeners))
print(("totalsources.value " + total_sources))
sourcesort = list(sourcelist.keys())
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
print((source + ".value " + listeners))
if len(sys.argv) > 1:
if sys.argv[1] == "autoconf":
print("yes")
elif sys.argv[1] == "dump":
print(req.text)
elif len(sys.argv) == 1 or sys.argv[1] != "config":
print(("totallisteners.value" + total_listeners))
print(("totalsources.value " + total_sources))
sourcesort = list(sourcelist.keys())
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
munin_print((source + ".value " + listeners))
elif sys.argv[1] == "config":
print ("graph_title Total number of listeners on " + host_desc)
print ("graph_vlabel listeners")
print ("graph_category Icecast")
print ("totallisteners.label Total number of listeners")
print ("totalsources.label Totalt number of sources")
sourcesort = list(sourcelist.keys())
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
munin_print((source + ".label " + source))
else:
print((sys.argv[1]))
else:
print(("totallisteners.value " + total_listeners))
print(("totalsources.value " + total_sources))
sourcesort = list(sourcelist.keys())
sourcesort.sort()
for source in sourcesort:
listeners, name = sourcelist[source]
munin_print((source + ".value " + listeners))

if __name__ == "__main__":
ic2xml()
ic2xml()
3 changes: 2 additions & 1 deletion readme.md
Expand Up @@ -16,7 +16,8 @@ How to use
----------
1. Copy icecast2_all to plugins directory (/usr/share/munin/plugins/ or /usr/lib/munin/plugins/)
2. Set executable flag on file ($ chmod +x /usr/lib/munin/plugins/icecast2_all)
3. Edit icecast2_all configuration (host, username, password)
3. Edit munin-node environment configuration ice2{host, user, pass}
3.5. Else, edit icecast2_all configuration (host, username, password)
4. Symlink to munin live plugins folder ($ ln -s /usr/share/munin/plugins/icecast2_all /etc/munin/plugins/icecast2_all)
5. Restart munin-node ($ /etc/rc.d/munin-node restart)
6. Graphs should start to appear.
Expand Down

0 comments on commit 5531ff8

Please sign in to comment.