mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51: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:
parent
6b28a1ba21
commit
40366a4c1e
1 changed files with 26 additions and 26 deletions
|
@ -143,14 +143,14 @@ EOF_
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ALL=$(debsecan --suite "${SUITE}" 2> /dev/null)
|
ALL=$(debsecan --suite "${SUITE}" 2> /dev/null)
|
||||||
REMOTE=$(echo "$ALL" | grep -w 'remotely')
|
REMOTE=$(printf "$ALL" | grep -w 'remotely')
|
||||||
NONREMOTE=$(echo "$ALL" | grep -wv 'remotely')
|
NONREMOTE=$(printf "$ALL" | grep -wv 'remotely')
|
||||||
|
|
||||||
HIGH=$(echo "${NONREMOTE}" | grep -w 'high urgency')
|
HIGH=$(printf "${NONREMOTE}" | grep -w 'high urgency')
|
||||||
MEDIUM=$(echo "${NONREMOTE}" | grep -w 'medium urgency')
|
MEDIUM=$(printf "${NONREMOTE}" | grep -w 'medium urgency')
|
||||||
LOW=$(echo "${NONREMOTE}" | grep -w 'low urgency')
|
LOW=$(printf "${NONREMOTE}" | grep -w 'low urgency')
|
||||||
OTHER=$(echo "${NONREMOTE}" | grep -wv 'urgency')
|
OTHER=$(printf "${NONREMOTE}" | grep -wv 'urgency')
|
||||||
FIXED=$(echo "${ALL}" | grep -w '(fixed')
|
FIXED=$(printf "${ALL}" | grep -w '(fixed')
|
||||||
|
|
||||||
# Arguments: Field offset to aggregate by
|
# Arguments: Field offset to aggregate by
|
||||||
count_entries() {
|
count_entries() {
|
||||||
|
@ -160,20 +160,20 @@ count_entries() {
|
||||||
|
|
||||||
case "${MODE}" in
|
case "${MODE}" in
|
||||||
'cve')
|
'cve')
|
||||||
remote_count=$(echo "${REMOTE}" | count_entries "${FIELD}" | wc -l)
|
remote_count=$(printf "${REMOTE}" | count_entries "${FIELD}" | wc -l)
|
||||||
high_count=$(echo "${HIGH}" | count_entries "${FIELD}" | wc -l)
|
high_count=$(printf "${HIGH}" | count_entries "${FIELD}" | wc -l)
|
||||||
medium_count=$(echo "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
|
medium_count=$(printf "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
|
||||||
low_count=$(echo "${LOW}" | count_entries "${FIELD}" | wc -l)
|
low_count=$(printf "${LOW}" | count_entries "${FIELD}" | wc -l)
|
||||||
other_count=$(echo "${OTHER}" | count_entries "${FIELD}" | wc -l)
|
other_count=$(printf "${OTHER}" | count_entries "${FIELD}" | wc -l)
|
||||||
fixed_count=$(echo "${FIXED}" | count_entries "${FIELD}" | wc -l)
|
fixed_count=$(printf "${FIXED}" | count_entries "${FIELD}" | wc -l)
|
||||||
;;
|
;;
|
||||||
'pkg' | *)
|
'pkg' | *)
|
||||||
remote_count=$(echo "${REMOTE}" | wc -l)
|
remote_count=$(printf "${REMOTE}" | wc -l)
|
||||||
high_count=$(echo "${HIGH}" | wc -l)
|
high_count=$(printf "${HIGH}" | wc -l)
|
||||||
medium_count=$(echo "${MEDIUM}" | wc -l)
|
medium_count=$(printf "${MEDIUM}" | wc -l)
|
||||||
low_count=$(echo "${LOW}" | wc -l)
|
low_count=$(printf "${LOW}" | wc -l)
|
||||||
other_count=$(echo "${OTHER}" | wc -l)
|
other_count=$(printf "${OTHER}" | wc -l)
|
||||||
fixed_count=$(echo "${FIXED}" | wc -l)
|
fixed_count=$(printf "${FIXED}" | wc -l)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -181,18 +181,18 @@ esac
|
||||||
CVECOUNTRE='s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/'
|
CVECOUNTRE='s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/'
|
||||||
|
|
||||||
# shellcheck disable=SC2005 disable=SC2046
|
# 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
|
cat <<EOF
|
||||||
remote.value $remote_count
|
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.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.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.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.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.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
|
EOF
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue