fix logs bashism (#16461)
fix logs of ioping
Costa Tsaousis committed
Nov 22, 2023 at 22:36 UTC
e1b95a1db80501b48b60a1d5e889638185f94627
2 files changed
+19
-14
collectors/charts.d.plugin/charts.d.plugin.in
+2
-2
@@ -80,13 +80,13 @@ log() {
80
81
[[ -n "$level" && -n "$LOG_LEVEL" && "$level" -gt "$LOG_LEVEL" ]] && return
82
83
- systemd-cat-native --log-as-netdata <<EOFLOG
83
+ systemd-cat-native --log-as-netdata --newline="--NEWLINE--" <<EOFLOG
84
INVOCATION_ID=${NETDATA_INVOCATION_ID}
85
SYSLOG_IDENTIFIER=${PROGRAM_NAME}
86
PRIORITY=${level}
87
THREAD_TAG=charts.d.plugin
88
ND_LOG_SOURCE=collector
89
-MESSAGE=${MODULE_NAME}: ${*//[$'\r\n']}
89
+MESSAGE=${MODULE_NAME}: ${*//\\n/--NEWLINE--}
90
91
EOFLOG
92
# AN EMPTY LINE IS NEEDED ABOVE
collectors/ioping.plugin/ioping.plugin.in
+17
-12
@@ -154,13 +154,13 @@ log() {
154
155
[[ -n "$level" && -n "$LOG_LEVEL" && "$level" -gt "$LOG_LEVEL" ]] && return
156
157
- systemd-cat-native --log-as-netdata <<EOFLOG
157
+ systemd-cat-native --log-as-netdata --newline="--NEWLINE--" <<EOFLOG
158
INVOCATION_ID=${NETDATA_INVOCATION_ID}
159
SYSLOG_IDENTIFIER=${PROGRAM_NAME}
160
PRIORITY=${level}
161
THREAD_TAG=ioping.plugin
162
ND_LOG_SOURCE=collector
163
-MESSAGE=${MODULE_NAME}: ${*//[$'\r\n']}
163
+MESSAGE=${MODULE_NAME}: ${*//\\n/--NEWLINE--}
164
165
EOFLOG
166
# AN EMPTY LINE IS NEEDED ABOVE
@@ -178,12 +178,16 @@ error() {
178
log "$NDLP_ERR" "${@}"
179
}
180
181
-fatal() {
182
- log "$NDLP_ALERT" "${@}"
181
+disable() {
182
+ log "${@}"
183
echo "DISABLE"
184
exit 1
185
}
186
187
+fatal() {
188
+ disable "$NDLP_ALERT" "${@}"
189
+}
190
+
191
debug() {
192
log "$NDLP_DEBUG" "${@}"
193
}
@@ -233,35 +237,36 @@ ioping_opts="-T 1000000"
237
238
for CONFIG in "${NETDATA_STOCK_CONFIG_DIR}/${plugin}.conf" "${NETDATA_USER_CONFIG_DIR}/${plugin}.conf"; do
239
if [ -f "${CONFIG}" ]; then
236
- info "Loading config file '${CONFIG}'..."
240
+ debug "Loading config file '${CONFIG}'..."
241
source "${CONFIG}"
238
- [ $? -ne 0 ] && error "Failed to load config file '${CONFIG}'."
242
+ [ $? -ne 0 ] && warn "Failed to load config file '${CONFIG}'."
243
elif [[ $CONFIG =~ ^$NETDATA_USER_CONFIG_DIR ]]; then
240
- warning "Cannot find file '${CONFIG}'."
244
+ debug "Cannot find file '${CONFIG}'."
245
fi
246
done
247
248
if [ -z "${destination}" ]
249
then
246
- fatal "destination is not configured - nothing to do."
250
+ disable $NDLP_DEBUG "destination is not configured - nothing to do."
251
fi
252
253
if [ ! -f "${ioping}" ]
254
then
251
- fatal "ioping command is not found. Please set its full path in '${NETDATA_USER_CONFIG_DIR}/${plugin}.conf'"
255
+ disable $NDLP_ERR "ioping command is not found. Please set its full path in '${NETDATA_USER_CONFIG_DIR}/${plugin}.conf'"
256
fi
257
258
if [ ! -x "${ioping}" ]
259
then
256
- fatal "ioping command '${ioping}' is not executable - cannot proceed."
260
+ disable $NDLP_ERR "ioping command '${ioping}' is not executable - cannot proceed."
261
fi
262
263
# the ioping options we will use
264
options=( -N -i ${update_every} -s ${request_size} ${ioping_opts} ${destination} )
265
266
# execute ioping
263
-info "starting ioping: ${ioping} ${options[*]}"
267
+debug "starting ioping: ${ioping} ${options[*]}"
268
+
269
exec "${ioping}" "${options[@]}"
270
271
# if we cannot execute ioping, stop
267
-fatal "command '${ioping} ${options[*]}' failed to be executed (returned code $?)."
272
+error "command '${ioping} ${options[*]}' failed to be executed (returned code $?)."