From c3d5e109c00ba949a493f8b628e7cbc04a20f35b Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 3 Sep 2016 21:04:25 +1000 Subject: [PATCH 1/4] [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 2/4] [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 3/4] [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 6d4da015de5d02f3b294321687b72d6bdb918dd6 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Sat, 29 Oct 2016 17:43:40 +1100 Subject: [PATCH 4/4] [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