2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Plugin bacula_sd: fix type issues

This commit is contained in:
Lars Kruse 2018-03-27 04:46:21 +02:00
parent 04bf942748
commit e8dd273047

View File

@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
#
# #
# Munin Plugin to get storage device throughput for Bacula by parsing the bconsole # Munin Plugin to get storage device throughput for Bacula by parsing the bconsole
# output. # output.
@ -25,19 +25,19 @@
# config (required) # config (required)
# autoconf (optional - only used by munin-config) # autoconf (optional - only used by munin-config)
# #
#
# Magic markers (optional - only used by munin-config and some # Magic markers (optional - only used by munin-config and some
# installation scripts): # installation scripts):
# #
#%# family=contrib # #%# family=contrib
#%# capabilities=autoconf # #%# capabilities=autoconf
import subprocess import subprocess
import time
import sys import sys
import re import re
import os import os
def parse_devices(): def parse_devices():
""" Parse the bconsole output once to get the device names """ """ Parse the bconsole output once to get the device names """
@ -48,9 +48,9 @@ def parse_devices():
# Hold the line numbers for devices # Hold the line numbers for devices
dev_line = [] dev_line = []
input = stdout.split("\n") input_lines = stdout.split("\n")
for line, i in zip(input, range(0, len(input))): for line, i in zip(input_lines, range(0, len(input_lines))):
if line.startswith("Connecting to Storage daemon "): if line.startswith("Connecting to Storage daemon "):
hostname = line.split()[-1].split(":")[0] hostname = line.split()[-1].split(":")[0]
if line.startswith("Device \""): if line.startswith("Device \""):
@ -58,8 +58,8 @@ def parse_devices():
for pos in dev_line: for pos in dev_line:
# Get the device name # Get the device name
dev_name = input[pos].split()[1][1:-1] dev_name = input_lines[pos].split()[1][1:-1]
dev_dev = input[pos].split()[2][1:-1] dev_dev = input_lines[pos].split()[2][1:-1]
dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1) dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1)
dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0) dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0)
devs.append([dev_name, dev_dev, dev_dev_clean]) devs.append([dev_name, dev_dev, dev_dev_clean])
@ -77,22 +77,26 @@ def parse():
# Hold the line numbers for devices # Hold the line numbers for devices
dev_line = [] dev_line = []
input = stdout.split("\n") input_lines = stdout.split("\n")
for line, i in zip(input, range(0, len(input))): for line, i in zip(input_lines, range(0, len(input_lines))):
if line.startswith("Device \""): if line.startswith("Device \""):
dev_line.append(i) dev_line.append(i)
for pos in dev_line: for pos in dev_line:
# Get the device name # Get the device name
dev_dev = input[pos].split()[2][1:-1] dev_dev = input_lines[pos].split()[2][1:-1]
dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1) dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1)
dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0) dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0)
# Get the current bytes # Get the current bytes
if input[pos].endswith("is mounted with:"): if input_lines[pos].endswith("is mounted with:"):
bytes = long(input[pos+5].split()[1].split("=")[1].replace(",", "")) bytes_count_text = input_lines[pos+5].split()[1].split("=")[1].replace(",", "")
devstats.append([dev_dev, dev_dev_clean, bytes]) try:
bytes_count = long(bytes_count_text)
except NameError:
bytes_count = int(bytes_count_text)
devstats.append([dev_dev, dev_dev_clean, bytes_count])
else: else:
devstats.append([dev_dev, dev_dev_clean, 0]) devstats.append([dev_dev, dev_dev_clean, 0])
@ -101,40 +105,39 @@ def parse():
def print_config(): def print_config():
hostname, devstats = parse_devices() hostname, devstats = parse_devices()
print "graph_title Bacula Storage Daemon throughput" print("graph_title Bacula Storage Daemon throughput")
print "graph_vlabel bytes per ${graph_period}" print("graph_vlabel bytes per ${graph_period}")
print "graph_args --base 1024 -l 0" print("graph_args --base 1024 -l 0")
print "graph_scale yes" print("graph_scale yes")
print "graph_info Bacula Storage Daemon througput measurement based on written bytes. This may be somewhat inacurate whenever a tape is changed." print("graph_info Bacula Storage Daemon througput measurement based on written bytes. "
print "graph_category backup" "This may be somewhat inacurate whenever a tape is changed.")
print "graph_order", print("graph_category backup")
print("graph_order", " ".join([dev[2] for dev in devstats]))
print()
if (os.getenv("report_hostname") is not None
and (os.getenv("report_hostname").upper() in ["YES", "TRUE", "1", "Y"])):
print("host_name", hostname)
for dev in devstats: for dev in devstats:
print dev[2], print("%s.label %s" % (dev[2], dev[1]))
print print("%s.type DERIVE" % (dev[2]))
if os.getenv("report_hostname") is not None and \ print("%s.min 0" % (dev[2]))
os.getenv("report_hostname").upper() in ["YES", "TRUE", "1", "Y"]: # print("%s.max %s" % (dev[2], str(1024*1024*1024*16)))
print "host_name", hostname # print("%s.cdef up,8,*" (dev[2]))
for dev in devstats:
print "%s.label %s" % (dev[2], dev[1])
print "%s.type DERIVE" % (dev[2])
print "%s.min 0" % (dev[2])
# print "%s.max %s" % (dev[2], str(1024*1024*1024*16))
# print "%s.cdef up,8,*" (dev[2])
sys.exit(0) sys.exit(0)
if "config" in sys.argv[1:]: if "config" in sys.argv[1:]:
print_config() print_config()
elif "autoconf" in sys.argv[1:]: elif "autoconf" in sys.argv[1:]:
for dir in os.getenv("PATH").split(":"): for directory in os.getenv("PATH").split(":"):
for root, dirs, files in os.walk(dir): for root, dirs, files in os.walk(directory):
if "bconsole" in files: if "bconsole" in files:
print "yes" print("yes")
sys.exit(0)
print("no")
sys.exit(0) sys.exit(0)
print "no"
sys.exit(1)
elif "suggest" in sys.argv[1:]: elif "suggest" in sys.argv[1:]:
sys.exit(1) sys.exit(1)
else: else:
for dev in parse(): for dev in parse():
print "%s.value %s" % (dev[1], dev[2]) print("%s.value %s" % (dev[1], dev[2]))