From d1ca98563bdba70cc2736d25f5fe2387c1550e4e Mon Sep 17 00:00:00 2001 From: Nicolas Casar Gonzalez Date: Tue, 14 Jun 2016 15:23:56 -0300 Subject: [PATCH 01/34] Fix for pymongo > 3.0 and connection support of MongoClient only https://api.mongodb.com/python/current/changelog.html#mongoclient-changes --- plugins/mongodb/mongo_lag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mongodb/mongo_lag b/plugins/mongodb/mongo_lag index b70837fc..a54c0f50 100755 --- a/plugins/mongodb/mongo_lag +++ b/plugins/mongodb/mongo_lag @@ -25,7 +25,7 @@ import pymongo def _get_members(): host = os.environ.get('host', '127.0.0.1') port = os.environ.get('port', 27017) - conn = pymongo.Connection(host,port) + conn = pymongo.MongoClient(host,port) repl_status = conn.admin.command("replSetGetStatus") members = {} From 887063d53c434cdfd07f516ebcba88477899cae5 Mon Sep 17 00:00:00 2001 From: Nico Casar Gonzalez Date: Wed, 15 Jun 2016 00:28:38 -0300 Subject: [PATCH 02/34] Fix for pymongo > 3.0 and connection support of MongoClient https://api.mongodb.com/python/current/changelog.html#mongoclient-changes --- plugins/mongodb/mongo_collection_ | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/mongodb/mongo_collection_ b/plugins/mongodb/mongo_collection_ index baea31ae..a0b73653 100644 --- a/plugins/mongodb/mongo_collection_ +++ b/plugins/mongodb/mongo_collection_ @@ -1,4 +1,4 @@ -#!/usr/bin/env /usr/local/bin/python2 +#!/usr/bin/env python # -*- coding: utf-8 -*- # vim: set sts=4 sw=4 encoding=utf-8 @@ -33,7 +33,7 @@ #%# capabilities=suggest autoconf -from pymongo import Connection +import pymongo from operator import itemgetter settings_host = '127.0.0.1' @@ -50,6 +50,7 @@ typeIndex['collcount']['title'] = 'per collection document count' typeIndex['collcount']['yaxis'] = 'documents' typeIndex['collcount']['base'] = '1000' typeIndex['collcount']['scale'] = '--logarithmic -l1' +typeIndex['collcount']['category'] = 'MongoDB' typeIndex['collsize'] = {} typeIndex['collsize']['index'] = 'size' @@ -57,6 +58,7 @@ typeIndex['collsize']['title'] = 'per collection data size' typeIndex['collsize']['yaxis'] = 'Byte' typeIndex['collsize']['base'] = '1024' typeIndex['collsize']['scale'] = '--logarithmic -l1 --units=si' +typeIndex['collsize']['category'] = 'MongoDB' typeIndex['avgsize'] = {} typeIndex['avgsize']['index'] = 'avgObjSize' @@ -64,6 +66,7 @@ typeIndex['avgsize']['title'] = 'average object size' typeIndex['avgsize']['yaxis'] = 'Byte' typeIndex['avgsize']['base'] = '1024' typeIndex['avgsize']['scale'] = '--logarithmic --units=si' +typeIndex['avgsize']['category'] = 'MongoDB' typeIndex['storage'] = {} typeIndex['storage']['index'] = 'storageSize' @@ -71,6 +74,7 @@ typeIndex['storage']['title'] = 'per collection storage size' typeIndex['storage']['yaxis'] = 'Byte' typeIndex['storage']['base'] = '1024' typeIndex['storage']['scale'] = '--logarithmic -l1 --units=si' +typeIndex['storage']['category'] = 'MongoDB' typeIndex['indexsize'] = {} typeIndex['indexsize']['index'] = 'totalIndexSize' @@ -78,11 +82,11 @@ typeIndex['indexsize']['title'] = 'per collection index size' typeIndex['indexsize']['yaxis'] = 'Byte' typeIndex['indexsize']['base'] = '1024' typeIndex['indexsize']['scale'] = '--logarithmic -l 1 --units=si' - +typeIndex['indexsize']['category'] = 'MongoDB' def getCollstats(graphtype): - con = Connection(settings_host, int(settings_port), slave_okay=True) + con = pymongo.MongoClient(settings_host, int(settings_port)) if settings_user: db = con['admin'] @@ -106,7 +110,7 @@ def getCollstats(graphtype): stats_tmp[collname]['value'] += long(stats[typeIndex[graphtype]['index']]) - con.disconnect() + con.close() for collname, item in sorted(stats_tmp.items()): yield ("%s" % collname, item['value'], item['dbname']) From 160bd2f034dd4b3cd8a5c9f2deea476254adb067 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sun, 14 Aug 2016 22:19:37 +1000 Subject: [PATCH 03/34] Add systemmd plugin counting units in each state Signed-off-by: Olivier Mehani --- plugins/system/systemd | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100755 plugins/system/systemd diff --git a/plugins/system/systemd b/plugins/system/systemd new file mode 100755 index 00000000..810c3b07 --- /dev/null +++ b/plugins/system/systemd @@ -0,0 +1,109 @@ +#!/bin/sh +# -*- sh -*- + +: << =cut + +=head1 NAME + +systemd - Plugin to monitor systemd units state + +=head1 APPLICABLE SYSTEMS + +Linux systems with systemd installed. + +=head1 CONFIGURATION + +None needed. + +=head1 AUTHOR + +Olivier Mehani + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=cut + +states="active \ + reloading \ + inactive \ + failed \ + activating \ + deactivating" +autoconf() { + which systemctl >/dev/null && \ + systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)" +} + +suggest() { + echo "units" +} + +config () { + case $1 in + "units") + cat << EOF +graph_title Systemd units state +graph_args -l 0 +graph_category system +graph_scale no +graph_vlabel units +EOF +for state in $states; do + echo "$state.label $state" + echo "$state.draw AREASTACK" + if [ $state = failed ]; then + echo "$state.warning 1" + echo "$state.critical 10" + fi +done + ;; + "*") + echo "$0: unknown mode '$1'" >&2 + exit 1 + esac +} + +fetch () { + case $1 in + "units") + tmp=`mktemp -t munin-systemd.XXXXXX` + systemctl --no-pager --no-legend --all | awk '{print $1, $3}' > $tmp + for state in \ + $states ; do + echo -n "$state.value " + grep $state$ $tmp | wc -l + echo -n "$state.extinfo " + echo $(grep $state$ $tmp | cut -d " " -f 1) + done + rm $tmp + ;; + "*") + echo "$0: unknown mode '$1'" >&2 + exit 1 + esac +} + +# mode=`echo $0 | sed 's/.*_//'` +mode=units + +case $1 in + "autoconf") + autoconf + ;; + "suggest") + suggest + ;; + "config") + config $mode + ;; + *) + fetch $mode + ;; +esac From 9121b90ee0baff9c88739c68b01bf6c4ed1fa22e Mon Sep 17 00:00:00 2001 From: Nico Casar Gonzalez Date: Thu, 18 Aug 2016 19:27:04 -0300 Subject: [PATCH 04/34] added mongodb URI for configuration defining settings_mongodb_uri will override settings_host and settings_port --- plugins/mongodb/mongo_collection_ | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/mongodb/mongo_collection_ b/plugins/mongodb/mongo_collection_ index a0b73653..67024d19 100644 --- a/plugins/mongodb/mongo_collection_ +++ b/plugins/mongodb/mongo_collection_ @@ -38,6 +38,8 @@ from operator import itemgetter settings_host = '127.0.0.1' settings_port = 27017 +# mongodb_uri will override host and port +settings_mongodb_uri = '' settings_db = 'mydb' settings_user = '' settings_password = '' @@ -86,7 +88,10 @@ typeIndex['indexsize']['category'] = 'MongoDB' def getCollstats(graphtype): - con = pymongo.MongoClient(settings_host, int(settings_port)) + if settings_mongodb_uri: + con = pymongo.MongoClient(settings_mongodb_uri) + else: + con = pymongo.MongoClient(settings_host, int(settings_port)) if settings_user: db = con['admin'] From 4a206ac9fde652787ba0fcafb15e54e9481aabab Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 3 Sep 2016 14:09:37 +1000 Subject: [PATCH 05/34] [deborphan] New plugin counting orphaned packages in all sections Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 plugins/system/deborphan diff --git a/plugins/system/deborphan b/plugins/system/deborphan new file mode 100755 index 00000000..19eafee2 --- /dev/null +++ b/plugins/system/deborphan @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Plugin to monitor the number of orphaned packages on the +# system (using deborphan). Might work on section distib, who knows... +# +# Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02 +# +# Olivie Mehani +# +# Licence : GPLv2 +# +#%# family=auto +#%# capabilities=autoconf + +# Auto enable if we have deborphan only +if [ "$1" = "autoconf" ] ; then + if [ -x /usr/bin/deborphan ]; then + echo yes + else + echo no + fi + exit 0 +fi + +# Fail if we don't have deborphan +if [ ! -x /usr/bin/deborphan ]; then + exit 1 +fi + +OUT=`mktemp -t deborphan.XXXXXX` +deborphan --show-section --guess-all | sed 's/\//_/' | sort > ${OUT} + +CATEGORIES="$(sed 's/ .*//' ${OUT} | uniq)" + +if [ "$1" = "config" ]; then + cat < ${TMP} + echo "${cat}.value `cat ${TMP} | wc -l`" + echo "${cat}.extinfo `echo $(cat ${TMP})`" + rm ${TMP} + done +fi + +rm -f ${OUT} From c3d5e109c00ba949a493f8b628e7cbc04a20f35b Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 3 Sep 2016 21:04:25 +1000 Subject: [PATCH 06/34] [file_length_] A versatile plugin to count the lines in specified files Signed-off-by: Olivier Mehani --- plugins/system/file_length_ | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 plugins/system/file_length_ diff --git a/plugins/system/file_length_ b/plugins/system/file_length_ new file mode 100755 index 00000000..7aff3e5e --- /dev/null +++ b/plugins/system/file_length_ @@ -0,0 +1,63 @@ +#!/bin/bash + +: << =cut + +=head1 NAME + +file_length_ - Plugin to monitor the length of specified files + +Useful for things such as lists (white, black, user, ...). + +=head1 CONFIGURATION + + [file_length_IDENTIFIER] + env.files FILEPATHGLOB1 FILEPATHGLOB2 ... + env.category DEFAULTS_TO_system + env.title OPTIONAL_TITLE + +=head1 AUTHOR + +Olivier Mehani (based on disk/log_sizes) + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf suggest + +=cut + +#NAME=`echo $0 | sed 's/.*_//'` +NAME=${0#*_} +TITLE=${title:-File lengths for $NAME} +CATEGORY=${category:-system} + +FILES=${files:-/var/log/messages} +FILES=$(echo $(ls $FILES)) + +if [ "$1" = "config" ] ; then + cat < Date: Sun, 4 Sep 2016 14:15:20 +1000 Subject: [PATCH 07/34] [file_length_] Add logarithmic option Signed-off-by: Olivier Mehani --- plugins/system/file_length_ | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/system/file_length_ b/plugins/system/file_length_ index 7aff3e5e..27a30c10 100755 --- a/plugins/system/file_length_ +++ b/plugins/system/file_length_ @@ -14,6 +14,7 @@ Useful for things such as lists (white, black, user, ...). env.files FILEPATHGLOB1 FILEPATHGLOB2 ... env.category DEFAULTS_TO_system env.title OPTIONAL_TITLE + env.logarithmic 1 =head1 AUTHOR @@ -38,13 +39,19 @@ CATEGORY=${category:-system} FILES=${files:-/var/log/messages} FILES=$(echo $(ls $FILES)) + if [ "$1" = "config" ] ; then + if [ ${logarithmic} = 1 ]; then + graph_args="-o" + else + graph_args="-l 0" + fi cat < Date: Wed, 7 Sep 2016 14:57:49 +1000 Subject: [PATCH 08/34] [file_length_] Remove incorrect markers Signed-off-by: Olivier Mehani --- plugins/system/file_length_ | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/system/file_length_ b/plugins/system/file_length_ index 27a30c10..a0e94480 100755 --- a/plugins/system/file_length_ +++ b/plugins/system/file_length_ @@ -24,11 +24,6 @@ Olivier Mehani (based on disk/log_sizes) GPLv2 -=head1 MAGIC MARKERS - - #%# family=auto - #%# capabilities=autoconf suggest - =cut #NAME=`echo $0 | sed 's/.*_//'` From 7f2ae83eb6b1c9f457b9c652101a01542b66693e Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Mon, 3 Oct 2016 18:29:40 +0200 Subject: [PATCH 09/34] systemd: don't print out empty extinfo lines This fixes warnings like this in munin-update.log: [WARNING] 4 lines had errors while 8 lines were correct (33. 33%) in data from 'fetch systemd' --- plugins/system/systemd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/system/systemd b/plugins/system/systemd index 810c3b07..1f06fa8d 100755 --- a/plugins/system/systemd +++ b/plugins/system/systemd @@ -79,8 +79,10 @@ fetch () { $states ; do echo -n "$state.value " grep $state$ $tmp | wc -l - echo -n "$state.extinfo " - echo $(grep $state$ $tmp | cut -d " " -f 1) + extinfo=`grep $state$ $tmp | cut -d " " -f 1` + if [ "$extinfo" ]; then + echo "$state.extinfo" $extinfo + fi done rm $tmp ;; From 114016b46110cfcf6cfd5ac838b831dac7319a1d Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Mon, 17 Oct 2016 20:08:06 +1100 Subject: [PATCH 10/34] [systemd] Warn on the first failed service Signed-off-by: Olivier Mehani --- plugins/system/systemd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/systemd b/plugins/system/systemd index 810c3b07..b12b7cc6 100755 --- a/plugins/system/systemd +++ b/plugins/system/systemd @@ -59,7 +59,7 @@ for state in $states; do echo "$state.label $state" echo "$state.draw AREASTACK" if [ $state = failed ]; then - echo "$state.warning 1" + echo "$state.warning 0" echo "$state.critical 10" fi done From ef80db4bc1a4967722bdb34ebfb9fd34b33bdee3 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Tue, 25 Oct 2016 21:21:24 +1100 Subject: [PATCH 11/34] [systemd] Remove half-baked suggest Signed-off-by: Olivier Mehani --- plugins/system/systemd | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/plugins/system/systemd b/plugins/system/systemd index 40f388d5..cb0f183d 100755 --- a/plugins/system/systemd +++ b/plugins/system/systemd @@ -17,7 +17,7 @@ None needed. =head1 AUTHOR -Olivier Mehani +Olivier Mehani =head1 LICENSE @@ -26,7 +26,7 @@ GPLv2 =head1 MAGIC MARKERS #%# family=auto - #%# capabilities=autoconf suggest + #%# capabilities=autoconf =cut @@ -41,33 +41,22 @@ autoconf() { systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)" } -suggest() { - echo "units" -} - config () { - case $1 in - "units") - cat << EOF + cat << EOF graph_title Systemd units state graph_args -l 0 graph_category system graph_scale no graph_vlabel units EOF -for state in $states; do - echo "$state.label $state" - echo "$state.draw AREASTACK" - if [ $state = failed ]; then - echo "$state.warning 0" - echo "$state.critical 10" - fi -done - ;; - "*") - echo "$0: unknown mode '$1'" >&2 - exit 1 - esac + for state in $states; do + echo "$state.label $state" + echo "$state.draw AREASTACK" + if [ $state = failed ]; then + echo "$state.warning 0" + echo "$state.critical 10" + fi + done } fetch () { @@ -99,9 +88,6 @@ case $1 in "autoconf") autoconf ;; - "suggest") - suggest - ;; "config") config $mode ;; From b31b861f1c2917945bb77c3495a4971cb4e2f7f5 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Thu, 27 Oct 2016 22:25:27 +1100 Subject: [PATCH 12/34] [systemd_units] Rename, remove unused mode logic and cleanup syntax Signed-off-by: Olivier Mehani --- plugins/system/{systemd => systemd_units} | 40 +++++++++-------------- 1 file changed, 15 insertions(+), 25 deletions(-) rename plugins/system/{systemd => systemd_units} (64%) diff --git a/plugins/system/systemd b/plugins/system/systemd_units similarity index 64% rename from plugins/system/systemd rename to plugins/system/systemd_units index cb0f183d..4f9ec61c 100755 --- a/plugins/system/systemd +++ b/plugins/system/systemd_units @@ -52,7 +52,7 @@ EOF for state in $states; do echo "$state.label $state" echo "$state.draw AREASTACK" - if [ $state = failed ]; then + if [ "$state" = "failed" ]; then echo "$state.warning 0" echo "$state.critical 10" fi @@ -60,38 +60,28 @@ EOF } fetch () { - case $1 in - "units") - tmp=`mktemp -t munin-systemd.XXXXXX` - systemctl --no-pager --no-legend --all | awk '{print $1, $3}' > $tmp - for state in \ - $states ; do - echo -n "$state.value " - grep $state$ $tmp | wc -l - extinfo=`grep $state$ $tmp | cut -d " " -f 1` - if [ "$extinfo" ]; then - echo "$state.extinfo" $extinfo - fi - done - rm $tmp - ;; - "*") - echo "$0: unknown mode '$1'" >&2 - exit 1 - esac + tmp=$(mktemp -t munin-systemd_units.XXXXXX) + trap "rm \"$tmp\"" EXIT + systemctl --no-pager --no-legend --all | awk '{print $1, $3}' > "$tmp" + for state in \ + $states ; do + echo -n "$state.value " + grep -c "$state$" "$tmp" + extinfo=$(grep "$state$" "$tmp" | cut -d " " -f 1) + if [ -n "$extinfo" ]; then + echo "$state.extinfo" $extinfo + fi +done } -# mode=`echo $0 | sed 's/.*_//'` -mode=units - case $1 in "autoconf") autoconf ;; "config") - config $mode + config ;; *) - fetch $mode + fetch ;; esac From a2f1592fe5a1dd286d2ea31f9842c25ac3b280fc Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:49:03 +0200 Subject: [PATCH 13/34] systemd_units: avoid use of temporary file --- plugins/system/systemd_units | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index 4f9ec61c..34563fd3 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -60,14 +60,12 @@ EOF } fetch () { - tmp=$(mktemp -t munin-systemd_units.XXXXXX) - trap "rm \"$tmp\"" EXIT - systemctl --no-pager --no-legend --all | awk '{print $1, $3}' > "$tmp" + tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}') for state in \ $states ; do echo -n "$state.value " - grep -c "$state$" "$tmp" - extinfo=$(grep "$state$" "$tmp" | cut -d " " -f 1) + echo "$tmp" | grep -c "$state$" + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) if [ -n "$extinfo" ]; then echo "$state.extinfo" $extinfo fi From a9476f50fdbe656f601c9616112f2ea3f8b5d7a7 Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:51:33 +0200 Subject: [PATCH 14/34] systemd_units: fix indent --- plugins/system/systemd_units | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index 34563fd3..dd336dd7 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -61,15 +61,14 @@ EOF fetch () { tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}') - for state in \ - $states ; do - echo -n "$state.value " - echo "$tmp" | grep -c "$state$" - extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) - if [ -n "$extinfo" ]; then - echo "$state.extinfo" $extinfo - fi -done + for state in $states ; do + echo -n "$state.value " + echo "$tmp" | grep -c "$state$" + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) + if [ -n "$extinfo" ]; then + echo "$state.extinfo" $extinfo + fi + done } case $1 in From adc00722860487e663915617caeb60c4388e061d Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:52:30 +0200 Subject: [PATCH 15/34] systemd_units: avoid use of echo -n flag --- plugins/system/systemd_units | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index dd336dd7..0a55adc5 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -62,8 +62,8 @@ EOF fetch () { tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}') for state in $states ; do - echo -n "$state.value " - echo "$tmp" | grep -c "$state$" + count=$(echo "$tmp" | grep -c "$state$") + echo "$state.value $count" extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) if [ -n "$extinfo" ]; then echo "$state.extinfo" $extinfo From 38835f7a62111ebdbc3ea91a47ee2174e7d225f6 Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 17:54:01 +0200 Subject: [PATCH 16/34] systemd_units: add doublequote around $extinfo --- plugins/system/systemd_units | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index 0a55adc5..e7f3960f 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -64,9 +64,9 @@ fetch () { for state in $states ; do count=$(echo "$tmp" | grep -c "$state$") echo "$state.value $count" - extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1) + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr -d '\n') if [ -n "$extinfo" ]; then - echo "$state.extinfo" $extinfo + echo "$state.extinfo" "$extinfo" fi done } From d888c31d1d9ce2a997bc43e0d90baad31e6a0c7c Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Thu, 27 Oct 2016 18:19:16 +0200 Subject: [PATCH 17/34] systemd_units: fix use of tr --- plugins/system/systemd_units | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/systemd_units b/plugins/system/systemd_units index e7f3960f..33e59115 100755 --- a/plugins/system/systemd_units +++ b/plugins/system/systemd_units @@ -64,7 +64,7 @@ fetch () { for state in $states ; do count=$(echo "$tmp" | grep -c "$state$") echo "$state.value $count" - extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr -d '\n') + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ') if [ -n "$extinfo" ]; then echo "$state.extinfo" "$extinfo" fi From 50c13da584f1ab77c1727ff029734e5a6af8b0df Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Thu, 4 Aug 2016 12:09:06 +0200 Subject: [PATCH 18/34] [udp-statistics] rename 'errors' field, add more fields --- plugins/network/udp-statistics | 47 ++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/plugins/network/udp-statistics b/plugins/network/udp-statistics index 5a3e78a8..aad671e2 100755 --- a/plugins/network/udp-statistics +++ b/plugins/network/udp-statistics @@ -16,25 +16,50 @@ graph_title UDP Statistics graph_args --base 1000 -l 0 graph_vlabel Packets/\${graph_period} graph_category network -received.label Received -received.draw AREA -received.type DERIVE -received.min 0 -errors.label Errors -errors.draw LINE1 -errors.type DERIVE -errors.min 0 sent.label Sent sent.draw LINE1 sent.type DERIVE sent.min 0 +received.label Received +received.draw AREA +received.type DERIVE +received.min 0 +unknown_ports.label In Unknown Port +unknown_ports.draw LINE1 +unknown_ports.type DERIVE +unknown_ports.min 0 +receive_buffer_errors.label Receive Buffer Errors +receive_buffer_errors.draw LINE1 +receive_buffer_errors.type DERIVE +receive_buffer_errors.min 0 +send_buffer_errors.label Send Buffer Errors +send_buffer_errors.draw LINE1 +send_buffer_errors.type DERIVE +send_buffer_errors.min 0 +in_csum_errors.label In CSUM Errors +in_csum_errors.draw LINE1 +in_csum_errors.type DERIVE +in_csum_errors.min 0 +ignored_multis.label In Ignored Multis +ignored_multis.draw LINE1 +ignored_multis.type DERIVE +ignored_multis.min 0 +receive_errors.label Receive Errors +receive_errors.draw LINE1 +receive_errors.type DERIVE +receive_errors.min 0 EOM exit 0; } } -@netstat = qx{/bin/netstat -us | awk '/packets sent/ \{ print "sent.value " \$1 \} +@netstat = qx{/bin/netstat -us | grep -A8 '^Udp:' | awk '/packets sent/ \{ print "sent.value " \$1 \} /packets received/ \{ print "received.value " \$1 \} - /packet receive errors/ \{ print "errors.value " \$1 \}'}; + /packets to unknown port received/ \{ print "unknown_ports.value " \$1 \} + /receive buffer errors/ \{ print "receive_buffer_errors.value " \$1 \} + /send buffer errors/ \{ print "send_buffer_errors.value " \$1 \} + /InCsumErrors/ \{ print "in_csum_errors.value " \$2 \} + /IgnoredMulti/ \{ print "ignored_multis.value " \$2 \} + /packet receive errors/ \{ print "receive_errors.value " \$1 \}'}; -print @netstat; \ No newline at end of file +print @netstat; From 5cfc73c3c8b5efede38bb60710caa3b2bfe3beaa Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 29 Oct 2016 16:08:19 +1100 Subject: [PATCH 19/34] [deborphan] Cleanup and add POD doc Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 71 ++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/plugins/system/deborphan b/plugins/system/deborphan index 19eafee2..e063de53 100755 --- a/plugins/system/deborphan +++ b/plugins/system/deborphan @@ -1,36 +1,57 @@ #!/bin/bash -# -# Plugin to monitor the number of orphaned packages on the -# system (using deborphan). Might work on section distib, who knows... -# -# Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02 -# -# Olivie Mehani -# -# Licence : GPLv2 -# -#%# family=auto -#%# capabilities=autoconf + +: << =cut + +=head1 NAME + +deborphan - Monitor orphaned Debian packages + +=head1 APPLICABLE SYSTEMS + +Debian-ish systems with deborphan installed. + +=head1 CONFIGURATION + +None needed. + +=head1 AUTHOR + +Olivier Mehani +Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02 + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut # Auto enable if we have deborphan only if [ "$1" = "autoconf" ] ; then - if [ -x /usr/bin/deborphan ]; then + if which deborphan >/dev/null; then echo yes else - echo no + echo "no (deborphan is missing)" fi exit 0 fi # Fail if we don't have deborphan -if [ ! -x /usr/bin/deborphan ]; then +if ! which deborphan >/dev/null; then + echo "deborphan is missing" >&2 exit 1 fi -OUT=`mktemp -t deborphan.XXXXXX` -deborphan --show-section --guess-all | sed 's/\//_/' | sort > ${OUT} +OUT=$(mktemp -t munin-deborphan.XXXXXX) +TMPFILES=$OUT +trap 'rm -f $TMPFILES' EXIT +deborphan --show-section --guess-all | sed 's/\//_/' | sort > "${OUT}" -CATEGORIES="$(sed 's/ .*//' ${OUT} | uniq)" +CATEGORIES="$(awk '{print $1}' "${OUT}" | uniq)" if [ "$1" = "config" ]; then cat < ${TMP} - echo "${cat}.value `cat ${TMP} | wc -l`" - echo "${cat}.extinfo `echo $(cat ${TMP})`" - rm ${TMP} + TMP=$(mktemp -t munin-deborphan.XXXXXX) + TMPFILES="${TMPFILES} $TMP" + sed -n "s/${cat} \+//p" "${OUT}" > "${TMP}" + echo "${cat}.value $(wc -l < "${TMP}")" + # shellcheck disable=SC2005 disable=SC2046 + # echo is not useless here: we want everything on one line + echo "${cat}.extinfo $(echo $(cat "${TMP}"))" done fi - -rm -f ${OUT} From 6d4da015de5d02f3b294321687b72d6bdb918dd6 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 29 Oct 2016 17:43:40 +1100 Subject: [PATCH 20/34] [file_length_] Cleanup and shellcheck Signed-off-by: Olivier Mehani --- plugins/system/file_length_ | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/plugins/system/file_length_ b/plugins/system/file_length_ index a0e94480..f5269584 100755 --- a/plugins/system/file_length_ +++ b/plugins/system/file_length_ @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh : << =cut @@ -18,25 +18,35 @@ Useful for things such as lists (white, black, user, ...). =head1 AUTHOR -Olivier Mehani (based on disk/log_sizes) +Olivier Mehani (based on disk/log_sizes) =head1 LICENSE GPLv2 +=head1 MAGIC MARKERS + + #%# family=manual + =cut -#NAME=`echo $0 | sed 's/.*_//'` -NAME=${0#*_} +# needs shellcheck -x /usr/share/munin/plugins/plugin.sh +# shellcheck source=/usr/share/munin/plugins/plugin.sh +. "$MUNIN_LIBDIR/plugins/plugin.sh" + +NAME=$(echo "$0" | sed 's/.*_//') TITLE=${title:-File lengths for $NAME} CATEGORY=${category:-system} FILES=${files:-/var/log/messages} -FILES=$(echo $(ls $FILES)) +# we want globbing to happen here +# shellcheck disable=SC2116 disable=SC2086 +FILES=$(echo $FILES) if [ "$1" = "config" ] ; then - if [ ${logarithmic} = 1 ]; then + # shellcheck disable=SC2154 + if [ "${logarithmic}" = "1" ]; then graph_args="-o" else graph_args="-l 0" @@ -50,16 +60,15 @@ graph_vlabel length (lines) EOF for F in $FILES; do - MF=`echo $F | sed 's/[-\/\.]/_/g'` - echo "$MF.label ${F##*/}" + MF=$(clean_fieldname "$F") + BF=$(basename "$F") + echo "$MF.label ${BF}" done else for F in $FILES; do - MF=`echo $F | sed 's/[-\/\.]/_/g'` - echo -n "$MF.value " - cat $F | wc -l - echo -n "$MF.extinfo " - stat --printf="%sB\n" $F + MF=$(echo "$F" | sed 's/[-\/\.]/_/g') + echo "$MF.value $(wc -l < "$F")" + echo "$MF.extinfo $(stat --printf="%sB\n" "$F")" done fi From 17fcfc3736f72ebfaa0b4df12f674c444435490e Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 02:24:55 +0100 Subject: [PATCH 21/34] Rewrited Plugin --- plugins/mail/postfix_stats | 121 +++++++++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 32 deletions(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index 7a2bcd5b..f0690c96 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -3,6 +3,15 @@ # Plugin to show Postfix statistics - needs pflogsumm # # Contributed by David Obando (david@cryptix.de) - 16.04.2007 +# Rewrited by Cristian Deluxe (me@cristiandeluxe.com) - 02.11.2016 +# +# +# Example config for Ubuntu (You need: apt-get install pflogsumm) +# +# [postfix_stats] +# env.logfile /var/log/syslog +# env.logfile2 /var/log/syslog.1 +# env.pflogsumm pflogsumm # # # Magic markers - optional - used by installation scripts and @@ -12,41 +21,89 @@ #%# capabilities=autoconf #set -xv +SYS_LOG=${logfile:-/var/log/syslog} +SYS_LOG2=${logfile2:-/var/log/syslog.0} +PFLOGSUMM=${pflogsumm:-pflogsumm.pl} -case $1 in - config) - cat <<'EOF' -system.type COUNTER -graph_title Postfix statistics -graph_vlabel Postfix statistics -graph_category Mail -graph_total Total -received.label received -delivered.label delivered -forwarded.label forwarded -deferred.label deferred -bounced.label bounced -rejected.label rejected -held.label held -discarded.label discarded -EOF - exit 0;; -esac +# +# Autoconf Section +# +if [ "$1" = "autoconf" ]; then + # Try to find pflogsumm with default name + PFLOG_EXIST=$(command -v pflogsumm.pl) + # Try to find pflogsumm without any extension + if [[ -z "${PFLOG_EXIST}" ]] + then + PFLOG_EXIST=$(command -v pflogsumm) + fi -TMP=`mktemp /tmp/tmp.XXXXXXXX` -pflogsumm.pl --smtpd_stats -d today /var/log/syslog /var/log/syslog.0 | head -n 15 > $TMP + if [[ -z "${PFLOG_EXIST}" ]] + then + echo "no"; + else + echo "yes" + fi + exit 0; +fi -cat < Date: Wed, 2 Nov 2016 04:04:47 +0100 Subject: [PATCH 22/34] Remove whitespaces from result --- plugins/mail/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index f0690c96..a6349347 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -81,7 +81,7 @@ TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}" "${SYS_LOG # Return -1 if any error occurs # parseValue() { - TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+') + TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | sed 's: ::g') if [[ -z "${TMP_RETURN}" ]] then echo -1 From 918602cd00a1faf9e622f2a6f8a65c5596aeb03c Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 04:53:27 +0100 Subject: [PATCH 23/34] Use simple quotes and better graph config --- plugins/mail/postfix_stats | 82 +++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index a6349347..d7f5d049 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -28,7 +28,7 @@ PFLOGSUMM=${pflogsumm:-pflogsumm.pl} # # Autoconf Section # -if [ "$1" = "autoconf" ]; then +if [ "$1" = 'autoconf' ]; then # Try to find pflogsumm with default name PFLOG_EXIST=$(command -v pflogsumm.pl) @@ -40,9 +40,9 @@ if [ "$1" = "autoconf" ]; then if [[ -z "${PFLOG_EXIST}" ]] then - echo "no"; + echo 'no'; else - echo "yes" + echo 'yes' fi exit 0; fi @@ -50,20 +50,36 @@ fi # # Config Section # -if [ "$1" = "config" ]; then - echo "system.type COUNTER" - echo "graph_title Postfix statistics" - echo "graph_vlabel Postfix statistics" - echo "graph_category Mail" - echo "graph_total Total" - echo "received.label received" - echo "delivered.label delivered" - echo "forwarded.label forwarded" - echo "deferred.label deferred" - echo "bounced.label bounced" - echo "rejected.label rejected" - echo "held.label held" - echo "discarded.label discarded" +if [ "$1" = 'config' ]; then + echo 'graph_title Postfix statistics' + echo 'graph_vlabel Postfix statistics' + echo 'graph_category mail' + echo 'graph_scale no' + echo 'graph_total Total' + echo 'received.label received' + echo 'received.type DERIVE' + echo 'received.min 0' + echo 'delivered.label delivered' + echo 'delivered.type DERIVE' + echo 'delivered.min 0' + echo 'forwarded.label forwarded' + echo 'forwarded.type DERIVE' + echo 'forwarded.min 0' + echo 'deferred.label deferred' + echo 'deferred.type DERIVE' + echo 'deferred.min 0' + echo 'bounced.label bounced' + echo 'bounced.type DERIVE' + echo 'bounced.min 0' + echo 'rejected.label rejected' + echo 'rejected.type DERIVE' + echo 'rejected.min 0' + echo 'held.label held' + echo 'held.type DERIVE' + echo 'held.min 0' + echo 'discarded.label discarded' + echo 'discarded.type DERIVE' + echo 'discarded.min 0' exit 0; fi @@ -91,19 +107,19 @@ parseValue() { } # Print results -printf "received.value " -parseValue "received" -printf "delivered.value " -parseValue "delivered" -printf "forwarded.value " -parseValue "forwarded" -printf "deferred.value " -parseValue "deferred" -printf "bounced.value " -parseValue "bounced" -printf "rejected.value " -parseValue "rejected" -printf "held.value " -parseValue "held" -printf "discarded.value " -parseValue "discarded" +printf 'received.value ' +parseValue 'received' +printf 'delivered.value ' +parseValue 'delivered' +printf 'forwarded.value ' +parseValue 'forwarded' +printf 'deferred.value ' +parseValue 'deferred' +printf 'bounced.value ' +parseValue 'bounced' +printf 'rejected.value ' +parseValue 'rejected' +printf 'held.value ' +parseValue 'held' +printf 'discarded.value ' +parseValue 'discarded' From e75132a7693f4166d64913e2fdaf0a66b07af18b Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 05:03:01 +0100 Subject: [PATCH 24/34] change spaces for tabs (code indent) --- plugins/mail/postfix_stats | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index d7f5d049..76ea7cd7 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -57,29 +57,29 @@ if [ "$1" = 'config' ]; then echo 'graph_scale no' echo 'graph_total Total' echo 'received.label received' - echo 'received.type DERIVE' - echo 'received.min 0' + echo 'received.type DERIVE' + echo 'received.min 0' echo 'delivered.label delivered' - echo 'delivered.type DERIVE' - echo 'delivered.min 0' + echo 'delivered.type DERIVE' + echo 'delivered.min 0' echo 'forwarded.label forwarded' - echo 'forwarded.type DERIVE' - echo 'forwarded.min 0' + echo 'forwarded.type DERIVE' + echo 'forwarded.min 0' echo 'deferred.label deferred' - echo 'deferred.type DERIVE' - echo 'deferred.min 0' + echo 'deferred.type DERIVE' + echo 'deferred.min 0' echo 'bounced.label bounced' - echo 'bounced.type DERIVE' - echo 'bounced.min 0' + echo 'bounced.type DERIVE' + echo 'bounced.min 0' echo 'rejected.label rejected' - echo 'rejected.type DERIVE' - echo 'rejected.min 0' + echo 'rejected.type DERIVE' + echo 'rejected.min 0' echo 'held.label held' - echo 'held.type DERIVE' - echo 'held.min 0' + echo 'held.type DERIVE' + echo 'held.min 0' echo 'discarded.label discarded' - echo 'discarded.type DERIVE' - echo 'discarded.min 0' + echo 'discarded.type DERIVE' + echo 'discarded.min 0' exit 0; fi From 9eb4cc1f01f953b89934caf4e80a441f2a707fa2 Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 05:07:45 +0100 Subject: [PATCH 25/34] =?UTF-8?q?Chenged=20family=20to=20=E2=80=9Ccontrib?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mail/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index 76ea7cd7..d495d002 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -17,7 +17,7 @@ # Magic markers - optional - used by installation scripts and # munin-config: # -#%# family=manual +#%# family=contrib #%# capabilities=autoconf #set -xv From 8e2025a9b932b540260710d5c637bccd47e2eb56 Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 06:34:57 +0100 Subject: [PATCH 26/34] changed graph_period to minute (more appropiated) --- plugins/mail/postfix_stats | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index d495d002..9f56db34 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -55,6 +55,7 @@ if [ "$1" = 'config' ]; then echo 'graph_vlabel Postfix statistics' echo 'graph_category mail' echo 'graph_scale no' + echo 'graph_period minute' echo 'graph_total Total' echo 'received.label received' echo 'received.type DERIVE' From 48ab33220e594d41e7d13a7b75f7b92f7612fd72 Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 06:59:07 +0100 Subject: [PATCH 27/34] no duplicated code, area graph, only first result --- plugins/mail/postfix_stats | 62 ++++++++++++-------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index 9f56db34..97473a74 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -25,6 +25,9 @@ SYS_LOG=${logfile:-/var/log/syslog} SYS_LOG2=${logfile2:-/var/log/syslog.0} PFLOGSUMM=${pflogsumm:-pflogsumm.pl} +# Fields (Array to avoid code duplication) +declare -a FIELDS_ARR=("received" "delivered" "forwarded" "deferred" "bounced" "rejected" "held" "discarded") + # # Autoconf Section # @@ -57,31 +60,17 @@ if [ "$1" = 'config' ]; then echo 'graph_scale no' echo 'graph_period minute' echo 'graph_total Total' - echo 'received.label received' - echo 'received.type DERIVE' - echo 'received.min 0' - echo 'delivered.label delivered' - echo 'delivered.type DERIVE' - echo 'delivered.min 0' - echo 'forwarded.label forwarded' - echo 'forwarded.type DERIVE' - echo 'forwarded.min 0' - echo 'deferred.label deferred' - echo 'deferred.type DERIVE' - echo 'deferred.min 0' - echo 'bounced.label bounced' - echo 'bounced.type DERIVE' - echo 'bounced.min 0' - echo 'rejected.label rejected' - echo 'rejected.type DERIVE' - echo 'rejected.min 0' - echo 'held.label held' - echo 'held.type DERIVE' - echo 'held.min 0' - echo 'discarded.label discarded' - echo 'discarded.type DERIVE' - echo 'discarded.min 0' - exit 0; + + # Generate config for each field + for i in "${FIELDS_ARR[@]}" + do + echo "${i}.label ${i}" + echo "${i}.type DERIVE" + echo "${i}.min 0" + echo "${i}.draw AREA" + done + + exit 0 fi # @@ -98,7 +87,7 @@ TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}" "${SYS_LOG # Return -1 if any error occurs # parseValue() { - TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | sed 's: ::g') + TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g') if [[ -z "${TMP_RETURN}" ]] then echo -1 @@ -108,19 +97,8 @@ parseValue() { } # Print results -printf 'received.value ' -parseValue 'received' -printf 'delivered.value ' -parseValue 'delivered' -printf 'forwarded.value ' -parseValue 'forwarded' -printf 'deferred.value ' -parseValue 'deferred' -printf 'bounced.value ' -parseValue 'bounced' -printf 'rejected.value ' -parseValue 'rejected' -printf 'held.value ' -parseValue 'held' -printf 'discarded.value ' -parseValue 'discarded' +for i in "${FIELDS_ARR[@]}" +do + printf "${i}.value " + parseValue "${i}" +done From ce23bdde592d3c43b8ff8b45e592cc5fc938c8f2 Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 07:00:45 +0100 Subject: [PATCH 28/34] Changed draw mode to STACK --- plugins/mail/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index 97473a74..afb508fe 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -67,7 +67,7 @@ if [ "$1" = 'config' ]; then echo "${i}.label ${i}" echo "${i}.type DERIVE" echo "${i}.min 0" - echo "${i}.draw AREA" + echo "${i}.draw STACK" done exit 0 From 87a6a775b35fe31a4887497059c908e4efe8b8f6 Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Wed, 2 Nov 2016 07:06:36 +0100 Subject: [PATCH 29/34] draw mode changed to AREASTACK --- plugins/mail/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index afb508fe..d21fd78e 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -67,7 +67,7 @@ if [ "$1" = 'config' ]; then echo "${i}.label ${i}" echo "${i}.type DERIVE" echo "${i}.min 0" - echo "${i}.draw STACK" + echo "${i}.draw AREASTACK" done exit 0 From d1d668f6bc3b58172951f44bd8dbd4317a30194f Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Fri, 4 Nov 2016 05:11:19 +0100 Subject: [PATCH 30/34] Strict SH script, thanks to sumpfralle --- plugins/mail/postfix_stats | 121 ++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 48 deletions(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index d21fd78e..6cfd1bef 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -1,53 +1,81 @@ #!/bin/sh -# -# Plugin to show Postfix statistics - needs pflogsumm -# -# Contributed by David Obando (david@cryptix.de) - 16.04.2007 -# Rewrited by Cristian Deluxe (me@cristiandeluxe.com) - 02.11.2016 -# -# -# Example config for Ubuntu (You need: apt-get install pflogsumm) -# -# [postfix_stats] -# env.logfile /var/log/syslog -# env.logfile2 /var/log/syslog.1 -# env.pflogsumm pflogsumm -# -# -# Magic markers - optional - used by installation scripts and -# munin-config: -# -#%# family=contrib -#%# capabilities=autoconf +# -*- sh -*- + +: <<=cut + +=head1 NAME + +postfix_stats - Munin plugin to monitor postfix statistics. + +=head1 APPLICABLE SYSTEMS + +Any system where pflogsumm script can be executed. + +=head1 CONFIGURATION + +There is no default configuration. This is an example config for Ubuntu: + + [postfix_stats] + env.logfiles /var/log/syslog /var/log/syslog.1 + env.pflogsumm pflogsumm + +env.logfiles contains space separated syslog logfiles, usually current log +and previous log. You can add more log files if you want, but this can +increase the time required to parse it. + +env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if are manually +downloaded and installed or pflogsumm if are installed by apt-get. + +=head1 INTERPRETATION + +This plugin adds up the RSS of all processes matching the +regex given as the process name, as reported by ps. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=head1 VERSION + 0.2 plugin completely rewritten + 0.1 first release. + +=head1 BUGS + +None known + +=head1 AUTHOR + +Originally: David Obando (david@cryptix.de) +Modified by: github.com/cristiandeluxe +Thanks to: sumpfralle + +=head1 LICENSE + +GPLv2 + +=cut #set -xv -SYS_LOG=${logfile:-/var/log/syslog} -SYS_LOG2=${logfile2:-/var/log/syslog.0} -PFLOGSUMM=${pflogsumm:-pflogsumm.pl} +SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}" +PFLOGSUMM="${pflogsum}" +[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)" -# Fields (Array to avoid code duplication) -declare -a FIELDS_ARR=("received" "delivered" "forwarded" "deferred" "bounced" "rejected" "held" "discarded") +# Fields (Array to avoid code duplication) must be space separated +FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded" # # Autoconf Section # if [ "$1" = 'autoconf' ]; then - # Try to find pflogsumm with default name - PFLOG_EXIST=$(command -v pflogsumm.pl) - - # Try to find pflogsumm without any extension - if [[ -z "${PFLOG_EXIST}" ]] + # Check if pflogsumm exist + if [ -z "${PFLOGSUMM}" ] then - PFLOG_EXIST=$(command -v pflogsumm) - fi - - if [[ -z "${PFLOG_EXIST}" ]] - then - echo 'no'; + echo 'no (pflogsum not found in your system)' else echo 'yes' fi - exit 0; + exit 0 fi # @@ -62,8 +90,7 @@ if [ "$1" = 'config' ]; then echo 'graph_total Total' # Generate config for each field - for i in "${FIELDS_ARR[@]}" - do + for i in $FIELDS_ARR; do echo "${i}.label ${i}" echo "${i}.type DERIVE" echo "${i}.min 0" @@ -78,27 +105,25 @@ fi # # Variable to store the pflogsumm result. -TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}" "${SYS_LOG2}") +TMP_RAW=$(eval "${PFLOGSUMM} -d today --detail 0 --zero-fill ${SYS_LOG}") # Parse value from Raw result # # Return digit if regex are parsed correctly # -# Return -1 if any error occurs +# Return U (undefined) if any error occurs # parseValue() { - TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g') - if [[ -z "${TMP_RETURN}" ]] - then - echo -1 + local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g') + if [ -z "${TMP_RETURN}" ]; then + echo 'U' else echo "${TMP_RETURN}" fi } # Print results -for i in "${FIELDS_ARR[@]}" -do - printf "${i}.value " +for i in $FIELDS_ARR; do + printf "%s.value " "${i}" parseValue "${i}" done From daf5b94a07cf6043417e00f04d3ff3715a8e9cdb Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Fri, 4 Nov 2016 10:33:14 +0100 Subject: [PATCH 31/34] =?UTF-8?q?Sellcheck=20disables=20and=20=E2=80=9Ceva?= =?UTF-8?q?l=E2=80=9D=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mail/postfix_stats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index 6cfd1bef..6e3a3a3e 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -58,6 +58,8 @@ GPLv2 #set -xv SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}" + +# shellcheck disable=SC2154 PFLOGSUMM="${pflogsum}" [ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)" @@ -105,7 +107,8 @@ fi # # Variable to store the pflogsumm result. -TMP_RAW=$(eval "${PFLOGSUMM} -d today --detail 0 --zero-fill ${SYS_LOG}") +# shellcheck disable=SC2086 +TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${SYS_LOG}) # Parse value from Raw result # @@ -114,6 +117,7 @@ TMP_RAW=$(eval "${PFLOGSUMM} -d today --detail 0 --zero-fill ${SYS_LOG}") # Return U (undefined) if any error occurs # parseValue() { + # shellcheck disable=SC2155 local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g') if [ -z "${TMP_RETURN}" ]; then echo 'U' From 156f0d840e3f7f256bb3a86a6b5ffec64c34e8a6 Mon Sep 17 00:00:00 2001 From: Cristian Deluxe Date: Fri, 4 Nov 2016 10:48:06 +0100 Subject: [PATCH 32/34] Small language fixes --- plugins/mail/postfix_stats | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index 6e3a3a3e..d3e5ae91 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -13,23 +13,25 @@ Any system where pflogsumm script can be executed. =head1 CONFIGURATION -There is no default configuration. This is an example config for Ubuntu: +There is no default configuration. This is an example config for Ubuntu: [postfix_stats] env.logfiles /var/log/syslog /var/log/syslog.1 env.pflogsumm pflogsumm env.logfiles contains space separated syslog logfiles, usually current log -and previous log. You can add more log files if you want, but this can -increase the time required to parse it. +and previous log. You can add more log files if you want, but this may +increase the time required for analysis. -env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if are manually -downloaded and installed or pflogsumm if are installed by apt-get. +env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually +downloaded and installed, or "pflogsumm" if it was installed by a package +manager (like apt-get). =head1 INTERPRETATION -This plugin adds up the RSS of all processes matching the -regex given as the process name, as reported by ps. +This plugin displays the messages: received, delivered, rejected... +Average per minute is made and it shows the total message count. +It is useful to know the load and messages being processed. =head1 MAGIC MARKERS From ddbb4782ecb7d82e13e0fecd389f6dabde3acb9d Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 5 Nov 2016 21:48:55 +1100 Subject: [PATCH 33/34] [deborphan] Don't use tempfiles, and other fixes Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/plugins/system/deborphan b/plugins/system/deborphan index e063de53..0fe38591 100755 --- a/plugins/system/deborphan +++ b/plugins/system/deborphan @@ -30,6 +30,9 @@ GPLv2 =cut +# shellcheck disable=SC1090 +. "$MUNIN_LIBDIR/plugins/plugin.sh" + # Auto enable if we have deborphan only if [ "$1" = "autoconf" ] ; then if which deborphan >/dev/null; then @@ -46,12 +49,9 @@ if ! which deborphan >/dev/null; then exit 1 fi -OUT=$(mktemp -t munin-deborphan.XXXXXX) -TMPFILES=$OUT -trap 'rm -f $TMPFILES' EXIT -deborphan --show-section --guess-all | sed 's/\//_/' | sort > "${OUT}" +OUT=$(deborphan --show-section --guess-all | sort) -CATEGORIES="$(awk '{print $1}' "${OUT}" | uniq)" +CATEGORIES="$(echo "${OUT}" | awk '{print $1}' | uniq)" if [ "$1" = "config" ]; then cat < "${TMP}" - echo "${cat}.value $(wc -l < "${TMP}")" - # shellcheck disable=SC2005 disable=SC2046 - # echo is not useless here: we want everything on one line - echo "${cat}.extinfo $(echo $(cat "${TMP}"))" + for CAT in ${CATEGORIES}; do + CATFIELD=$(clean_fieldname "${CAT}") + CATDATA=$(echo "${OUT}" | sed -n "s#${CAT} \+##p") + echo "${CATFIELD}.value $(echo "${CATDATA}" | wc -l)" + echo "${CATFIELD}.extinfo $(echo "${CATDATA}" | tr '\n' ' ')" done fi From 000c97ccece6cd644f642085cbda1dc40ae35742 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 5 Nov 2016 21:51:10 +1100 Subject: [PATCH 34/34] [deborphan] No longer dependent on bashisms Signed-off-by: Olivier Mehani --- plugins/system/deborphan | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/deborphan b/plugins/system/deborphan index 0fe38591..10d5ac44 100755 --- a/plugins/system/deborphan +++ b/plugins/system/deborphan @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh : << =cut