1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Correctly handle empty lists

Using `echo` adds an enter to empty lists, which gets seen as one entry and is sent to Munin as such. Using `printf` prevents this.
This commit is contained in:
Wilco de Boer 2021-05-18 15:26:54 +02:00 committed by GitHub
parent 6b28a1ba21
commit 40366a4c1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -143,14 +143,14 @@ EOF_
fi
ALL=$(debsecan --suite "${SUITE}" 2> /dev/null)
REMOTE=$(echo "$ALL" | grep -w 'remotely')
NONREMOTE=$(echo "$ALL" | grep -wv 'remotely')
REMOTE=$(printf "$ALL" | grep -w 'remotely')
NONREMOTE=$(printf "$ALL" | grep -wv 'remotely')
HIGH=$(echo "${NONREMOTE}" | grep -w 'high urgency')
MEDIUM=$(echo "${NONREMOTE}" | grep -w 'medium urgency')
LOW=$(echo "${NONREMOTE}" | grep -w 'low urgency')
OTHER=$(echo "${NONREMOTE}" | grep -wv 'urgency')
FIXED=$(echo "${ALL}" | grep -w '(fixed')
HIGH=$(printf "${NONREMOTE}" | grep -w 'high urgency')
MEDIUM=$(printf "${NONREMOTE}" | grep -w 'medium urgency')
LOW=$(printf "${NONREMOTE}" | grep -w 'low urgency')
OTHER=$(printf "${NONREMOTE}" | grep -wv 'urgency')
FIXED=$(printf "${ALL}" | grep -w '(fixed')
# Arguments: Field offset to aggregate by
count_entries() {
@ -160,20 +160,20 @@ count_entries() {
case "${MODE}" in
'cve')
remote_count=$(echo "${REMOTE}" | count_entries "${FIELD}" | wc -l)
high_count=$(echo "${HIGH}" | count_entries "${FIELD}" | wc -l)
medium_count=$(echo "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
low_count=$(echo "${LOW}" | count_entries "${FIELD}" | wc -l)
other_count=$(echo "${OTHER}" | count_entries "${FIELD}" | wc -l)
fixed_count=$(echo "${FIXED}" | count_entries "${FIELD}" | wc -l)
remote_count=$(printf "${REMOTE}" | count_entries "${FIELD}" | wc -l)
high_count=$(printf "${HIGH}" | count_entries "${FIELD}" | wc -l)
medium_count=$(printf "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
low_count=$(printf "${LOW}" | count_entries "${FIELD}" | wc -l)
other_count=$(printf "${OTHER}" | count_entries "${FIELD}" | wc -l)
fixed_count=$(printf "${FIXED}" | count_entries "${FIELD}" | wc -l)
;;
'pkg' | *)
remote_count=$(echo "${REMOTE}" | wc -l)
high_count=$(echo "${HIGH}" | wc -l)
medium_count=$(echo "${MEDIUM}" | wc -l)
low_count=$(echo "${LOW}" | wc -l)
other_count=$(echo "${OTHER}" | wc -l)
fixed_count=$(echo "${FIXED}" | wc -l)
remote_count=$(printf "${REMOTE}" | wc -l)
high_count=$(printf "${HIGH}" | wc -l)
medium_count=$(printf "${MEDIUM}" | wc -l)
low_count=$(printf "${LOW}" | wc -l)
other_count=$(printf "${OTHER}" | wc -l)
fixed_count=$(printf "${FIXED}" | wc -l)
;;
esac
@ -181,18 +181,18 @@ esac
CVECOUNTRE='s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/'
# shellcheck disable=SC2005 disable=SC2046
# The nested $(echo ...)s are needed to yet the newlines
# The nested $(echo ...)s are needed to yeet the newlines
cat <<EOF
remote.value $remote_count
remote.extinfo $(echo $(echo "${REMOTE}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
remote.extinfo $(echo $(printf "${REMOTE}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
high.value $high_count
high.extinfo $(echo $(echo "${HIGH}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
high.extinfo $(echo $(printf "${HIGH}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
medium.value $medium_count
medium.extinfo $(echo $(echo "${MEDIUM}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
medium.extinfo $(echo $(printf "${MEDIUM}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
low.value $low_count
low.extinfo $(echo $(echo "${LOW}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
low.extinfo $(echo $(printf "${LOW}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
other.value $other_count
other.extinfo $(echo $(echo "${OTHER}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
other.extinfo $(echo $(printf "${OTHER}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
fixed.value $fixed_count
fixed.extinfo $(echo $(echo "${FIXED}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
fixed.extinfo $(echo $(printf "${FIXED}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
EOF