1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Plugin icecast2_: fix code style issues reported by flake8

This commit is contained in:
Lars Kruse 2019-08-14 00:29:57 +02:00
parent c466adc4d3
commit ab3a583756
2 changed files with 91 additions and 85 deletions

View file

@ -1,6 +1,12 @@
#! /usr/bin/python
# -*- coding: iso-8859-1 -*-
import os
import sys
import urllib2
from xml.dom import minidom
# Hostname of Icecast server
# Just canonical name, no http:// nor ending /
host = "foo.bar.com"
@ -21,14 +27,13 @@ oggbitrates = [56, 128, 172]
# well the total number of listeners for any configured stream.
# For each stream with multiple bitrates, create one
# icecast2_streamname
# If the name contains a "-" exchange it with a "_", and the script will change it back for you. This is to satisfy internal requirements of Munin.
# If the name contains a "-" exchange it with a "_", and the script will change it back for you.
# This is to satisfy internal requirements of Munin.
# For each streamname, the plugin will check for the configured bitrates
# Expecting the mountpoints to be on the form of
# /streamname_<bitrate> for mp3
# /streamname_<bitrate>.ogg for Ogg/Vorbis
import urllib2, os.path, time, sys
from xml.dom import minidom
def hent_XML():
auth_handler = urllib2.HTTPBasicAuthHandler()
@ -45,11 +50,11 @@ def hent_XML():
xmldoc = minidom.parseString(xml)
xmldoc = xmldoc.firstChild
#Totalt antall lyttere
# Totalt antall lyttere
total_lyttere = xmldoc.getElementsByTagName("clients")[0].firstChild.nodeValue
#Totalt antall kilder
# Totalt antall kilder
total_kilder = xmldoc.getElementsByTagName("sources")[0].firstChild.nodeValue
#Status for enkelt strøm
# Status for enkelt strøm
sources = xmldoc.getElementsByTagName("source")
sourcelist = {}
for source in sources:
@ -76,7 +81,7 @@ def hent_XML():
for file in filelist:
if file.find("icecast2_") != -1:
channelname = file[len("icecast2_"):]
if channelname != "total" and chanlist.has_key(channelname) != 1:
if channelname != "total" and channelname not in chanlist:
chanlist[channelname] = 0
chanlist = chanlist.keys()
chanlist.sort()
@ -103,11 +108,13 @@ def hent_XML():
print "graph_vlabel lyttere"
print "graph_category streaming"
for bitrate in mp3bitrates:
print "%s_%s.label %s-%s" % (sourcename, bitrate, "/" + sourcename.replace("_", "-"), bitrate)
print "%s_%s.label %s-%s" % (sourcename, bitrate,
"/" + sourcename.replace("_", "-"), bitrate)
sumstring += "%s_%s " % (sourcename, bitrate)
print "%s_%s.critical -0.5:" % (sourcename, bitrate)
for bitrate in oggbitrates:
print "%s_%s_ogg.label %s-%s.ogg" % (sourcename, bitrate, "/" + sourcename.replace("_", "-"), bitrate)
print "%s_%s_ogg.label %s-%s.ogg" % (sourcename, bitrate,
"/" + sourcename.replace("_", "-"), bitrate)
print "%s_%s_ogg.critical -0.5:" % (sourcename, bitrate)
sumstring += "%s_%s_ogg " % (sourcename, bitrate)
print "%slyttere.label Totalt antall lyttere" % sourcename
@ -121,26 +128,26 @@ def hent_XML():
for file in filelist:
if file.find("icecast2_") != -1:
channelname = file[len("icecast2_"):]
if channelname != "total" and statslist.has_key(channelname) != 1:
if channelname != "total" and channelname not in statslist:
statslist[channelname] = 0
for source in sourcelist:
listeners, name = sourcelist[source]
if not statslist.has_key(source[:source.rfind("_")]):
if source[:source.rfind("_")] not in statslist:
statslist[source[:source.rfind("_")]] = 0
statslist[source[:source.rfind("_")]] += int(listeners)
for stat in statslist:
print "%s.value %s" % (stat, statslist[stat])
else:
for bitrate in mp3bitrates:
if sourcelist.has_key("%s_%s" % (sourcename, bitrate)):
if ("%s_%s" % (sourcename, bitrate)) in sourcelist:
listeners = sourcelist["%s_%s" % (sourcename, bitrate)][0]
print listeners
else:
listeners = -1
print "%s_%s.value %s" % (sourcename, bitrate, listeners)
for bitrate in oggbitrates:
if sourcelist.has_key("%s_%s.ogg" % (sourcename, bitrate)):
if ("%s_%s.ogg" % (sourcename, bitrate)) in sourcelist:
listeners = sourcelist["%s_%s.ogg" % (sourcename, bitrate)][0]
else:
listeners = -1

View file

@ -157,7 +157,6 @@ plugins/http/wget_page
plugins/i2p/i2p_
plugins/icecast/icecast_
plugins/icecast/icecast2
plugins/icecast/icecast2_
plugins/icecast/icecast2_all
plugins/icecast/icecast2_stats_
plugins/imapproxy/imapproxy_multi