Projet

Général

Profil

Révision 40366a4c

ID40366a4c1ecd6447546a065b3d73354e1d3c137f
Parent 6b28a1ba
Enfant b247f8f2

Ajouté par Wilco de Boer il y a plus de 4 ans

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.

Voir les différences:

plugins/debian/debsecan_
143 143
fi
144 144

  
145 145
ALL=$(debsecan --suite "${SUITE}" 2> /dev/null)
146
REMOTE=$(echo "$ALL" | grep -w 'remotely')
147
NONREMOTE=$(echo "$ALL" | grep -wv 'remotely')
146
REMOTE=$(printf "$ALL" | grep -w 'remotely')
147
NONREMOTE=$(printf "$ALL" | grep -wv 'remotely')
148 148

  
149
HIGH=$(echo "${NONREMOTE}" | grep -w 'high urgency')
150
MEDIUM=$(echo "${NONREMOTE}" | grep -w 'medium urgency')
151
LOW=$(echo "${NONREMOTE}" | grep -w 'low urgency')
152
OTHER=$(echo "${NONREMOTE}" | grep -wv 'urgency')
153
FIXED=$(echo "${ALL}" | grep -w '(fixed')
149
HIGH=$(printf "${NONREMOTE}" | grep -w 'high urgency')
150
MEDIUM=$(printf "${NONREMOTE}" | grep -w 'medium urgency')
151
LOW=$(printf "${NONREMOTE}" | grep -w 'low urgency')
152
OTHER=$(printf "${NONREMOTE}" | grep -wv 'urgency')
153
FIXED=$(printf "${ALL}" | grep -w '(fixed')
154 154

  
155 155
# Arguments: Field offset to aggregate by
156 156
count_entries() {
......
160 160

  
161 161
case "${MODE}" in
162 162
	'cve')
163
		remote_count=$(echo "${REMOTE}" | count_entries "${FIELD}" | wc -l)
164
		high_count=$(echo "${HIGH}" | count_entries "${FIELD}" | wc -l)
165
		medium_count=$(echo "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
166
		low_count=$(echo "${LOW}" | count_entries "${FIELD}" | wc -l)
167
		other_count=$(echo "${OTHER}" | count_entries "${FIELD}" | wc -l)
168
		fixed_count=$(echo "${FIXED}" | count_entries "${FIELD}" | wc -l)
163
		remote_count=$(printf "${REMOTE}" | count_entries "${FIELD}" | wc -l)
164
		high_count=$(printf "${HIGH}" | count_entries "${FIELD}" | wc -l)
165
		medium_count=$(printf "${MEDIUM}" | count_entries "${FIELD}" | wc -l)
166
		low_count=$(printf "${LOW}" | count_entries "${FIELD}" | wc -l)
167
		other_count=$(printf "${OTHER}" | count_entries "${FIELD}" | wc -l)
168
		fixed_count=$(printf "${FIXED}" | count_entries "${FIELD}" | wc -l)
169 169
		;;
170 170
	'pkg' | *)
171
		remote_count=$(echo "${REMOTE}" | wc -l)
172
		high_count=$(echo "${HIGH}" | wc -l)
173
		medium_count=$(echo "${MEDIUM}" | wc -l)
174
		low_count=$(echo "${LOW}" | wc -l)
175
		other_count=$(echo "${OTHER}" | wc -l)
176
		fixed_count=$(echo "${FIXED}" | wc -l)
171
		remote_count=$(printf "${REMOTE}" | wc -l)
172
		high_count=$(printf "${HIGH}" | wc -l)
173
		medium_count=$(printf "${MEDIUM}" | wc -l)
174
		low_count=$(printf "${LOW}" | wc -l)
175
		other_count=$(printf "${OTHER}" | wc -l)
176
		fixed_count=$(printf "${FIXED}" | wc -l)
177 177
		;;
178 178
esac
179 179

  
......
181 181
CVECOUNTRE='s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/'
182 182

  
183 183
# shellcheck disable=SC2005 disable=SC2046
184
# The nested $(echo ...)s are needed to yet the newlines
184
# The nested $(echo ...)s are needed to yeet the newlines
185 185
cat <<EOF
186 186
remote.value $remote_count
187
remote.extinfo $(echo $(echo "${REMOTE}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
187
remote.extinfo $(echo $(printf "${REMOTE}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
188 188
high.value $high_count
189
high.extinfo $(echo $(echo "${HIGH}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
189
high.extinfo $(echo $(printf "${HIGH}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
190 190
medium.value $medium_count
191
medium.extinfo $(echo $(echo "${MEDIUM}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
191
medium.extinfo $(echo $(printf "${MEDIUM}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
192 192
low.value $low_count
193
low.extinfo $(echo $(echo "${LOW}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
193
low.extinfo $(echo $(printf "${LOW}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
194 194
other.value $other_count
195
other.extinfo $(echo $(echo "${OTHER}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
195
other.extinfo $(echo $(printf "${OTHER}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
196 196
fixed.value $fixed_count
197
fixed.extinfo $(echo $(echo "${FIXED}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
197
fixed.extinfo $(echo $(printf "${FIXED}" | count_entries "${FIELD}" | sort -nr | sed "${CVECOUNTRE}"))
198 198
EOF

Formats disponibles : Unified diff