From 558360c41219c96ab4d695d25ed382530b3df3ce Mon Sep 17 00:00:00 2001 From: "Kim B. Heino" Date: Tue, 6 Apr 2021 10:26:54 +0300 Subject: [PATCH] raid2: use perlpod and small fixes --- plugins/disk/raid2 | 61 +++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/plugins/disk/raid2 b/plugins/disk/raid2 index b3fd3e30..79460508 100755 --- a/plugins/disk/raid2 +++ b/plugins/disk/raid2 @@ -1,13 +1,36 @@ -#!/usr/bin/python3 -tt -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 -"""Munin plugin to monitor software and hardware RAID status and scrub status. +"""Munin plugin to monitor software and hardware RAID and scrub status. -Copyright 2014 Kim B. Heino, Foobar Oy -License GPLv2+ +=head1 NAME -#%# capabilities=autoconf -#%# family=auto +raid - monitor software and hardware RAID and scrub status + +=head1 APPLICABLE SYSTEMS + +Linux systems with mdraid, btrfs, cciss or megasasctl RAID. + +=head1 CONFIGURATION + +Following config is needed: + + [raid] + user root + +=head1 AUTHOR + +Kim B. Heino + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut """ import glob @@ -17,17 +40,11 @@ import subprocess import sys -def safename(variable): +def safename(name): """Return safe variable name.""" - if variable == '/': - return 'btrfs' - ret = [] - for letter in variable: - if letter.isalnum(): - ret.append(letter) - else: - ret.append('_') - return ''.join(ret) + if name == '/': + return 'root' + return ''.join(char.lower() if char.isalnum() else '_' for char in name) def run_binary(arg): @@ -82,7 +99,7 @@ def find_megasasctl(): return [] # Run binary - data = run_binary(['/usr/sbin/megasasctl', '-HB']) + data = run_binary([statexe, '-HB']) if data: status = 0 else: @@ -161,12 +178,6 @@ def find_devices(): return devices -def autoconf(): - """Print "yes" or "no".""" - status = 'yes' if find_devices() else 'no' - print(status) - - def config(devices): """Print plugin config.""" print('graph_title RAID and Scrub Status') @@ -189,7 +200,7 @@ def fetch(devices): if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'autoconf': - autoconf() + print('yes' if find_devices() else 'no (no RAID devices found)') elif len(sys.argv) > 1 and sys.argv[1] == 'config': config(find_devices()) else: