Skip to content

Commit 325857e

Browse files
thiagoftsmcakrit
authored andcommitted
Common pattern for web and alarms together with two bug fixes (netdata#6783)
* script_pattern: Fix script and bring pattern This commit fixes the error given by shellckeck on stress.sh and brings a pattern for the other scripts, no less important its given the possibility to change the url from outside of the scripts * script_pattern: shellcheke Correct the request.sh after to change it to avoid warning errors from shellchecker * script_pattern: Remove of garbage value With this PR I am removing the garbage value of a script * script_pattern: Restore color These 3 scripts changed in this commit was not restoring the terminal color, this commit fixes this
1 parent 7de804a commit 325857e

4 files changed

Lines changed: 82 additions & 66 deletions

File tree

‎tests/acls/acl.sh.in‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ NETDATA_VARLIB_DIR="/var/lib/netdata"
88
RED='\033[0;31m'
99
GREEN='\033[0;32m'
1010
YELLOW='\033[0;43m'
11+
NOCOLOR='\033[0m'
1112

1213
#change the previous acl file and with a new
1314
#and store it on a new file
1415
change_file(){
1516
sed "s/$1/$2/g" netdata.cfg > "$4"
1617
}
1718

19+
NETDATAPID=""
20+
1821
change_ssl_file(){
1922
KEYROW="ssl key = $3/key.pem"
2023
CERTROW="ssl certificate = $3/cert.pem"
@@ -35,24 +38,24 @@ run_acl_tests() {
3538

3639
TOT=$(grep -c "HTTP/1.1 301" log_*.txt | cut -d: -f2| grep -c 1)
3740
if [ "$TOT" -ne "$4" ]; then
38-
echo -e "${RED}I got a wrong number of redirects($TOT) when SSL is activated, It was expected $4"
41+
echo -e "${RED}I got a wrong number of redirects($TOT) when SSL is activated, It was expected $4 ${NOCOLOR}"
3942
rm log_* netdata.conf.test* netdata.txt health.csv index.html badge.csv tmp* key.pem cert.pem info.txt
40-
killall netdata
43+
kill $NETDATAPID
4144
exit 1
4245
elif [ "$TOT" -eq "$4" ] && [ "$4" -ne "0" ]; then
43-
echo -e "${YELLOW}I got the correct number of redirects($4) when SSL is activated and I try to access with HTTP."
46+
echo -e "${YELLOW}I got the correct number of redirects($4) when SSL is activated and I try to access with HTTP. ${NOCOLOR}"
4447
return
4548
fi
4649

4750
TOT=$(grep -c "HTTP/1.1 200 OK" log_* | cut -d: -f2| grep -c 1)
4851
if [ "$TOT" -ne "$3" ]; then
49-
echo -e "${RED}I got a wrong number of \"200 OK\" from the queries, it was expected $3."
50-
killall netdata
52+
echo -e "${RED}I got a wrong number of \"200 OK\" from the queries, it was expected $3. ${NOCOLOR}"
53+
kill $NETDATAPID
5154
rm log_* netdata.conf.test* netdata.txt health.csv index.html badge.csv tmp* key.pem cert.pem info.txt
5255
exit 1
5356
fi
5457

55-
echo -e "${GREEN}ACLs were applied correctly"
58+
echo -e "${GREEN}ACLs were applied correctly ${NOCOLOR}"
5659
}
5760

5861
CONF=$(grep "bind" netdata.cfg)
@@ -69,12 +72,14 @@ else
6972
fi
7073

7174
change_file "$CONF" " bind to = *" "$CWD" "netdata.conf.test0"
72-
netdata -c "netdata.conf.test0"
75+
netdata -c "netdata.conf.test0" -D &
76+
NETDATAPID=$!
7377
run_acl_tests $TOKEN "$BASICURL:19999" 5 0
74-
killall netdata
78+
kill $NETDATAPID
7579

7680
change_ssl_file "$CONF" " bind to = *=dashboard|registry|badges|management|netdata.conf *:20000=dashboard|registry|badges|management *:20001=dashboard|registry|netdata.conf^SSL=optional *:20002=dashboard|registry" "$CWD" "netdata.conf.test1"
77-
netdata -c "netdata.conf.test1"
81+
netdata -c "netdata.conf.test1" -D &
82+
NETDATAPID=$!
7883
run_acl_tests $TOKEN "$BASICURL:19999" 5 5
7984
run_acl_tests $TOKEN "$BASICURLS:19999" 5 0
8085

@@ -86,10 +91,11 @@ run_acl_tests $TOKEN "$BASICURLS:20001" 4 0
8691

8792
run_acl_tests $TOKEN "$BASICURL:20002" 3 5
8893
run_acl_tests $TOKEN "$BASICURLS:20002" 3 0
89-
killall netdata
94+
kill $NETDATAPID
9095

9196
change_ssl_file "$CONF" " bind to = *=dashboard|registry|badges|management|netdata.conf *:20000=dashboard|registry|badges|management *:20001=dashboard|registry|netdata.conf^SSL=force *:20002=dashboard|registry" "$CWD" "netdata.conf.test2"
92-
netdata -c "netdata.conf.test2"
97+
netdata -c "netdata.conf.test2" -D &
98+
NETDATAPID=$!
9399
run_acl_tests $TOKEN "$BASICURL:19999" 5 5
94100
run_acl_tests $TOKEN "$BASICURLS:19999" 5 0
95101

@@ -101,10 +107,11 @@ run_acl_tests $TOKEN "$BASICURLS:20001" 4 0
101107

102108
run_acl_tests $TOKEN "$BASICURL:20002" 3 5
103109
run_acl_tests $TOKEN "$BASICURLS:20002" 3 0
104-
killall netdata
110+
kill $NETDATAPID
105111

106112
change_ssl_file "$CONF" " bind to = *=dashboard|registry|badges|management|netdata.conf *:20000=dashboard|registry|badges|management^SSL=optional *:20001=dashboard|registry|netdata.conf^SSL=force" "$CWD" "netdata.conf.test3"
107-
netdata -c "netdata.conf.test3"
113+
netdata -c "netdata.conf.test3" -D &
114+
NETDATAPID=$!
108115
run_acl_tests $TOKEN "$BASICURL:19999" 5 5
109116
run_acl_tests $TOKEN "$BASICURLS:19999" 5 0
110117

@@ -113,7 +120,7 @@ run_acl_tests $TOKEN "$BASICURLS:20000" 4 0
113120

114121
run_acl_tests $TOKEN "$BASICURL:20001" 4 5
115122
run_acl_tests $TOKEN "$BASICURLS:20001" 4 0
116-
killall netdata
123+
kill $NETDATAPID
117124

118125
rm log_* netdata.conf.test* netdata.txt health.csv index.html badge.csv tmp* key.pem cert.pem info.txt
119-
echo "All the tests were successful"
126+
echo "All the tests were successful ${NOCOLOR}"

‎tests/alarm_repetition/alarm.sh.in‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ HEALTHDIR="@configdir_POST@/health.d/"
77
OUTDIR="workdir/"
88

99
#url to do download
10-
MURL="http://localhost:19999/api/v1/alarms?active"
10+
QUERY="/api/v1/alarms?active"
11+
MURL="http://localhost:19999$QUERY"
1112

1213
#error messages
1314
RED='\033[0;31m'
@@ -35,24 +36,26 @@ netdata_test_download() {
3536
grep "HTTP/1.1 200 OK" "$1" 2>/dev/null 1>/dev/null
3637
TEST="$?"
3738
if [ "$TEST" -ne "0" ]; then
38-
echo -e "${RED} Error to get the alarms"
39-
killall netdata
39+
echo -e "${RED} Error to get the alarms. ${NOCOLOR}"
40+
kill "$5"
41+
rm "$HEALTHDIR/ram.conf"
4042
exit 1
4143
fi
4244

4345
COUNT=$(grep -w "\"last_repeat\":" "$2" | grep -c "$OPT" "\"0\"")
4446
if [ "$COUNT" -eq "0" ]; then
45-
echo -e "${RED} Netdata gave an unexpected result when alarm repetition is $4"
46-
killall netdata
47+
echo -e "${RED} Netdata gave an unexpected result when alarm repetition is $4 ${NOCOLOR}"
48+
killall "$5"
49+
rm "$HEALTHDIR/ram.conf"
4750
exit 1
4851
fi
4952

50-
echo -e "${GREEN} I got the expected result"
53+
echo -e "${GREEN} I got the expected result ${NOCOLOR}"
5154
}
5255

5356
get_the_logs() {
5457
curl -v -k --create-dirs -o "$OUTDIR/$1.out" "$MURL" 2> "$OUTDIR/$1.err"
55-
netdata_test_download "$OUTDIR/$1.err" "$OUTDIR/$1.out" "$2" "$3"
58+
netdata_test_download "$OUTDIR/$1.err" "$OUTDIR/$1.out" "$2" "$3" "$4"
5659
}
5760

5861
process_data() {
@@ -61,14 +64,14 @@ process_data() {
6164
NETDATAPID=$!
6265
echo -e "${NOCOLOR}Sleeping during $SEC seconds to create alarm entries"
6366
sleep $SEC
64-
get_the_logs "$1" "$2" "$3"
67+
get_the_logs "$1" "$2" "$3" "$NETDATAPID"
6568
kill $NETDATAPID
6669
}
6770

6871
mkdir "$OUTDIR"
6972
CREATEDIR="$?"
7073
if [ "$CREATEDIR" -ne "0" ]; then
71-
echo -e "${RED}Cannot create the output directory, it already exists. The test will overwrite previous results."
74+
echo -e "${RED}Cannot create the output directory, it already exists. The test will overwrite previous results. ${NOCOLOR}"
7275
fi
7376

7477
change_alarm_file "./0" "ram_without_repetition.conf" "$HEALTHDIR/ram.conf"
@@ -81,6 +84,6 @@ cp -a netdata.conf_with_repetition netdata.conf
8184
process_data "ram_with" "I" "activated."
8285
rm netdata.conf
8386

84-
echo -e "${GREEN} all the tests were sucessful"
87+
echo -e "${GREEN} all the tests were sucessful ${NOCOLOR}"
8588
rm "$HEALTHDIR/ram.conf"
8689
rm -rf $OUTDIR

‎tests/stress.sh‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ then
88
fi
99

1010
# set the host to connect to
11-
if [ ! -z "$1" ]
11+
if [ -n "$1" ]
1212
then
1313
host="$1"
1414
else
@@ -17,17 +17,17 @@ fi
1717
echo "using netdata server at: $host"
1818

1919
# shellcheck disable=SC2207 disable=SC1117
20-
charts=($(curl "$host/netdata.conf" 2>/dev/null | grep "^\[" | cut -d '[' -f 2 | cut -d ']' -f 1 | grep -v ^global$ | grep -v "^plugin" | sort -u))
20+
charts=($(curl -k "$host/netdata.conf" 2>/dev/null | grep "^\[" | cut -d '[' -f 2 | cut -d ']' -f 1 | grep -v ^global$ | grep -v "^plugin" | sort -u))
2121
if [ "${#charts[@]}" -eq 0 ]
2222
then
2323
echo "Cannot download charts from server: $host"
2424
exit 1
2525
fi
2626

27-
update_every="$(curl "$host/netdata.conf" 2>/dev/null | grep "update every = " | head -n 1 | cut -d '=' -f 2)"
27+
update_every="$(curl -k "$host/netdata.conf" 2>/dev/null | grep "update every = " | head -n 1 | cut -d '=' -f 2)"
2828
[ $(( update_every + 1 - 1)) -eq 0 ] && update_every=1
2929

30-
entries="$(curl "$host/netdata.conf" 2>/dev/null | grep "history = " | head -n 1 | cut -d '=' -f 2)"
30+
entries="$(curl -k "$host/netdata.conf" 2>/dev/null | grep "history = " | head -n 1 | cut -d '=' -f 2)"
3131
[ $(( entries + 1 - 1)) -eq 0 ] && entries=3600
3232

3333
# to compare equal things, set the entries to 3600 max
@@ -55,7 +55,7 @@ trap cleanup EXIT
5555

5656
while true
5757
do
58-
echo "curl --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >"$file"
58+
echo "curl -k --compressed --keepalive-time 120 --header \"Connection: keep-alive\" \\" >"$file"
5959
# shellcheck disable=SC2034
6060
for x in {1..100}
6161
do

‎tests/urls/request.sh.in‎

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ OUTDIR="tests"
1818
OUTEDIR="encoded_tests"
1919
OUTOPTDIR="options"
2020
ERRDIR="etests"
21+
NOCOLOR='\033[0'
22+
RED='\033[0;31m'
23+
GREEN='\033[0;32m'
2124

2225
################################################################################################
2326
#### ####
@@ -27,7 +30,7 @@ ERRDIR="etests"
2730

2831
# Print error message and close script
2932
netdata_print_error(){
30-
echo "Closing due error \"$1\" code \"$2\""
33+
echo "${RED} Closing due error \"$1\" code \"$2\" ${NOCOLOR}"
3134
exit 1
3235
}
3336

@@ -200,36 +203,40 @@ netdata_download_allmetrics() {
200203
}
201204

202205

203-
################################################################################################
206+
####################################################
204207
#### ####
205-
#### MAIN ROUTINE ####
208+
#### MAIN ROUTINE ####
206209
#### ####
207-
################################################################################################
210+
####################################################
208211
MURL="http://127.0.0.1:19999"
209212

213+
if [ -n "$1" ]; then
214+
MURL="$1"
215+
fi
216+
210217
netdata_create_directory $OUTDIR
211218
netdata_create_directory $OUTEDIR
212219
netdata_create_directory $OUTOPTDIR
213220
netdata_create_directory $ERRDIR
214221

215-
wget --no-check-certificate --execute="robots = off" --mirror --convert-links --no-parent $MURL
222+
wget --no-check-certificate --execute="robots = off" --mirror --convert-links --no-parent "$MURL"
216223
TEST=$?
217224
if [ $TEST -ne "0" ] ; then
218225
echo "Cannot connect to Netdata"
219226
exit 1
220227
fi
221228

222-
netdata_download_various $MURL "netdata.conf" "netdata.conf"
229+
netdata_download_various "$MURL" "netdata.conf" "netdata.conf"
223230

224-
netdata_download_various_with_options $MURL "netdata.conf" "netdata.conf"
231+
netdata_download_various_with_options "$MURL" "netdata.conf" "netdata.conf"
225232

226-
netdata_wrong_request_various $MURL "api/v15/info?this%20could%20not%20be%20here" "err_version"
233+
netdata_wrong_request_various "$MURL" "api/v15/info?this%20could%20not%20be%20here" "err_version"
227234

228-
netdata_wrong_request_various $MURL "api/v1/\(*@&$\!$%%5E\)\!$*%&\)\!$*%%5E*\!%5E%\!%5E$%\!%5E%\(\!*%5E*%5E%\(*@&$%5E%\(\!%5E#*&\!^#$*&\!^%\)@\($%^\)\!*&^\(\!*&^#$&#$\)\!$%^\)\!$*%&\)#$\!^#*$^\!\(*#^#\)\!%^\!\)$*%&\!\(*&$\!^#$*&^\!*#^$\!*^\)%\(\!*&$%\)\(\!&#$\!^*#&$^\!*^%\)\!$%\)\!\(&#$\!^#*&^$" "err_version2"
235+
netdata_wrong_request_various "$MURL" "api/v1/\(*@&$\!$%%5E\)\!$*%&\)\!$*%%5E*\!%5E%\!%5E$%\!%5E%\(\!*%5E*%5E%\(*@&$%5E%\(\!%5E#*&\!^#$*&\!^%\)@\($%^\)\!*&^\(\!*&^#$&#$\)\!$%^\)\!$*%&\)#$\!^#*$^\!\(*#^#\)\!%^\!\)$*%&\!\(*&$\!^#$*&^\!*#^$\!*^\)%\(\!*&$%\)\(\!&#$\!^*#&$^\!*^%\)\!$%\)\!\(&#$\!^#*&^$" "err_version2"
229236

230-
netdata_download_various $MURL "api/v1/info" "info"
231-
netdata_download_various_with_options $MURL "api/v1/info" "info"
232-
netdata_download_various $MURL "api/v1/info?this%20could%20not%20be%20here" "err_info"
237+
netdata_download_various "$MURL" "api/v1/info" "info"
238+
netdata_download_various_with_options "$MURL" "api/v1/info" "info"
239+
netdata_download_various "$MURL" "api/v1/info?this%20could%20not%20be%20here" "err_info"
233240

234241
netdata_print_header "Getting all the netdata charts"
235242
CHARTS=$( netdata_download_charts "$MURL" "api/v1/charts" )
@@ -244,58 +251,57 @@ elif [ ${#CHARTS[@]} -ne ${#WCHARTS2[@]} ]; then
244251
exit 3;
245252
fi
246253

247-
netdata_wrong_request_various $MURL "api/v1/chart" "err_chart_without_chart"
248-
netdata_wrong_request_various $MURL "api/v1/chart?_=234231424242" "err_chart_arg"
254+
netdata_wrong_request_various "$MURL" "api/v1/chart" "err_chart_without_chart"
255+
netdata_wrong_request_various "$MURL" "api/v1/chart?_=234231424242" "err_chart_arg"
249256

250-
netdata_download_various $MURL "api/v1/chart?chart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args"
251-
netdata_download_various_with_options $MURL "api/v1/chart?chart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args"
257+
netdata_download_various "$MURL" "api/v1/chart?chart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args"
258+
netdata_download_various_with_options "$MURL" "api/v1/chart?chart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args"
252259

253-
netdata_download_various $MURL "api/v1/chart%3Fchart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args_encoded"
254-
netdata_download_various_with_options $MURL "api/v1/chart%3Fchart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args_encoded"
255-
netdata_download_various $MURL "api/v1/chart%3Fchart=cpu.cpu0_interrupts%26_=234231424242" "chart_cpu_with_more_args_encoded2"
256-
netdata_download_various $MURL "api/v1/chart%3Fchart%3Dcpu.cpu0_interrupts%26_%3D234231424242" "chart_cpu_with_more_args_encoded3"
260+
netdata_download_various "$MURL" "api/v1/chart%3Fchart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args_encoded"
261+
netdata_download_various_with_options "$MURL" "api/v1/chart%3Fchart=cpu.cpu0_interrupts&_=234231424242" "chart_cpu_with_more_args_encoded"
262+
netdata_download_various "$MURL" "api/v1/chart%3Fchart=cpu.cpu0_interrupts%26_=234231424242" "chart_cpu_with_more_args_encoded2"
263+
netdata_download_various "$MURL" "api/v1/chart%3Fchart%3Dcpu.cpu0_interrupts%26_%3D234231424242" "chart_cpu_with_more_args_encoded3"
257264

258265
netdata_create_directory "$OUTDIR/chart"
259266
for I in $CHARTS ; do
260267
NAME=${I//\"/}
261-
netdata_download_various $MURL "api/v1/chart?chart=$NAME" "chart/$NAME"
268+
netdata_download_various "$MURL" "api/v1/chart?chart=$NAME" "chart/$NAME"
262269
done
263270

264-
netdata_wrong_request_various $MURL "api/v1/alarm_variables" "err_alarm_variables_without_chart"
265-
netdata_wrong_request_various $MURL "api/v1/alarm_variables?_=234231424242" "err_alarm_variables_arg"
266-
netdata_download_various $MURL "api/v1/alarm_variables?chart=cpu.cpu0_interrupts&_=234231424242" "alarm_cpu_with_more_args"
271+
netdata_wrong_request_various "$MURL" "api/v1/alarm_variables" "err_alarm_variables_without_chart"
272+
netdata_wrong_request_various "$MURL" "api/v1/alarm_variables?_=234231424242" "err_alarm_variables_arg"
273+
netdata_download_various "$MURL" "api/v1/alarm_variables?chart=cpu.cpu0_interrupts&_=234231424242" "alarm_cpu_with_more_args"
267274

268275
netdata_create_directory "$OUTDIR/alarm_variables"
269276
for I in $CHARTS ; do
270277
NAME=${I//\"/}
271-
netdata_download_various $MURL "api/v1/alarm_variables?chart=$NAME" "alarm_variables/$NAME"
278+
netdata_download_various "$MURL" "api/v1/alarm_variables?chart=$NAME" "alarm_variables/$NAME"
272279
done
273280

274281
netdata_create_directory "$OUTDIR/badge"
275282
netdata_create_directory "$OUTEDIR/badge"
276283
for I in $CHARTS ; do
277-
netdata_download_chart $MURL "api/v1/badge.svg?chart" "$I" "badge"
284+
netdata_download_chart "$MURL" "api/v1/badge.svg?chart" "$I" "badge"
278285
done
279286

280287
netdata_create_directory "$OUTDIR/allmetrics"
281-
netdata_download_allmetrics $MURL "allmetrics"
288+
netdata_download_allmetrics "$MURL" "allmetrics"
282289

283-
netdata_download_various $MURL "api/v1/alarms?all" "alarms_all"
284-
netdata_download_various $MURL "api/v1/alarms?active" "alarms_active"
285-
netdata_download_various $MURL "api/v1/alarms" "alarms_nothing"
290+
netdata_download_various "$MURL" "api/v1/alarms?all" "alarms_all"
291+
netdata_download_various "$MURL" "api/v1/alarms?active" "alarms_active"
292+
netdata_download_various "$MURL" "api/v1/alarms" "alarms_nothing"
286293

287-
netdata_download_various $MURL "api/v1/alarm_log?after" "alarm_without"
288-
netdata_download_various $MURL "api/v1/alarm_log" "alarm_nothing"
289-
netdata_download_various $MURL "api/v1/alarm_log?after&_=$PT" "alarm_log"
294+
netdata_download_various "$MURL" "api/v1/alarm_log?after" "alarm_without"
295+
netdata_download_various "$MURL" "api/v1/alarm_log" "alarm_nothing"
296+
netdata_download_various "$MURL" "api/v1/alarm_log?after&_=$PT" "alarm_log"
290297

291298
netdata_create_directory "$OUTDIR/data"
292299
netdata_create_directory "$OUTEDIR/data"
293300
for I in $CHARTS ; do
294-
netdata_download_chart $MURL "api/v1/data?chart" "$I" "data"
301+
netdata_download_chart "$MURL" "api/v1/data?chart" "$I" "data"
295302
break;
296303
done
297304

298-
WHITE='\033[0;37m'
299-
echo -e "${WHITE}ALL the URLS got 200 as answer!"
305+
echo -e "${GREEN}ALL the URLS got 200 as answer! ${NOCOLOR}"
300306

301307
exit 0

0 commit comments

Comments
 (0)