@cryptotaxi247 / netdata-1 / commits / 325857ef0

Common pattern for web and alarms together with two bug fixes (#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

thiagoftsm committed Sep 29, 2019 at 09:10 UTC 325857ef07822fa5e6a1330d96be55276d9e664a
4 files changed +82 -66
tests/acls/acl.sh.in
+22 -15
@@ -8,6 +8,7 @@ NETDATA_VARLIB_DIR="/var/lib/netdata"
8 RED='\033[0;31m'
9 GREEN='\033[0;32m'
10 YELLOW='\033[0;43m'
11 +NOCOLOR='\033[0m'
12
13 #change the previous acl file and with a new
14 #and store it on a new file
@@ -15,6 +16,8 @@ change_file(){
16 sed "s/$1/$2/g" netdata.cfg > "$4"
17 }
18
19 +NETDATAPID=""
20 +
21 change_ssl_file(){
22 KEYROW="ssl key = $3/key.pem"
23 CERTROW="ssl certificate = $3/cert.pem"
@@ -35,24 +38,24 @@ run_acl_tests() {
38
39 TOT=$(grep -c "HTTP/1.1 301" log_*.txt | cut -d: -f2| grep -c 1)
40 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}"
42 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
44 exit 1
45 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}"
47 return
48 fi
49
50 TOT=$(grep -c "HTTP/1.1 200 OK" log_* | cut -d: -f2| grep -c 1)
51 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
54 rm log_* netdata.conf.test* netdata.txt health.csv index.html badge.csv tmp* key.pem cert.pem info.txt
55 exit 1
56 fi
57
55 - echo -e "${GREEN}ACLs were applied correctly"
58 + echo -e "${GREEN}ACLs were applied correctly ${NOCOLOR}"
59 }
60
61 CONF=$(grep "bind" netdata.cfg)
@@ -69,12 +72,14 @@ else
72 fi
73
74 change_file "$CONF" " bind to = *" "$CWD" "netdata.conf.test0"
72 -netdata -c "netdata.conf.test0"
75 +netdata -c "netdata.conf.test0" -D &
76 +NETDATAPID=$!
77 run_acl_tests $TOKEN "$BASICURL:19999" 5 0
74 -killall netdata
78 +kill $NETDATAPID
79
80 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=$!
83 run_acl_tests $TOKEN "$BASICURL:19999" 5 5
84 run_acl_tests $TOKEN "$BASICURLS:19999" 5 0
85
@@ -86,10 +91,11 @@ run_acl_tests $TOKEN "$BASICURLS:20001" 4 0
91
92 run_acl_tests $TOKEN "$BASICURL:20002" 3 5
93 run_acl_tests $TOKEN "$BASICURLS:20002" 3 0
89 -killall netdata
94 +kill $NETDATAPID
95
96 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=$!
99 run_acl_tests $TOKEN "$BASICURL:19999" 5 5
100 run_acl_tests $TOKEN "$BASICURLS:19999" 5 0
101
@@ -101,10 +107,11 @@ run_acl_tests $TOKEN "$BASICURLS:20001" 4 0
107
108 run_acl_tests $TOKEN "$BASICURL:20002" 3 5
109 run_acl_tests $TOKEN "$BASICURLS:20002" 3 0
104 -killall netdata
110 +kill $NETDATAPID
111
112 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=$!
115 run_acl_tests $TOKEN "$BASICURL:19999" 5 5
116 run_acl_tests $TOKEN "$BASICURLS:19999" 5 0
117
@@ -113,7 +120,7 @@ run_acl_tests $TOKEN "$BASICURLS:20000" 4 0
120
121 run_acl_tests $TOKEN "$BASICURL:20001" 4 5
122 run_acl_tests $TOKEN "$BASICURLS:20001" 4 0
116 -killall netdata
123 +kill $NETDATAPID
124
125 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
+13 -10
@@ -7,7 +7,8 @@ HEALTHDIR="@configdir_POST@/health.d/"
7 OUTDIR="workdir/"
8
9 #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"
12
13 #error messages
14 RED='\033[0;31m'
@@ -35,24 +36,26 @@ netdata_test_download() {
36 grep "HTTP/1.1 200 OK" "$1" 2>/dev/null 1>/dev/null
37 TEST="$?"
38 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"
42 exit 1
43 fi
44
45 COUNT=$(grep -w "\"last_repeat\":" "$2" | grep -c "$OPT" "\"0\"")
46 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"
50 exit 1
51 fi
52
50 - echo -e "${GREEN} I got the expected result"
53 + echo -e "${GREEN} I got the expected result ${NOCOLOR}"
54 }
55
56 get_the_logs() {
57 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"
59 }
60
61 process_data() {
@@ -61,14 +64,14 @@ process_data() {
64 NETDATAPID=$!
65 echo -e "${NOCOLOR}Sleeping during $SEC seconds to create alarm entries"
66 sleep $SEC
64 - get_the_logs "$1" "$2" "$3"
67 + get_the_logs "$1" "$2" "$3" "$NETDATAPID"
68 kill $NETDATAPID
69 }
70
71 mkdir "$OUTDIR"
72 CREATEDIR="$?"
73 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}"
75 fi
76
77 change_alarm_file "./0" "ram_without_repetition.conf" "$HEALTHDIR/ram.conf"
@@ -81,6 +84,6 @@ cp -a netdata.conf_with_repetition netdata.conf
84 process_data "ram_with" "I" "activated."
85 rm netdata.conf
86
84 -echo -e "${GREEN} all the tests were sucessful"
87 +echo -e "${GREEN} all the tests were sucessful ${NOCOLOR}"
88 rm "$HEALTHDIR/ram.conf"
89 rm -rf $OUTDIR
tests/stress.sh
+5 -5
@@ -8,7 +8,7 @@ then
8 fi
9
10 # set the host to connect to
11 -if [ ! -z "$1" ]
11 +if [ -n "$1" ]
12 then
13 host="$1"
14 else
@@ -17,17 +17,17 @@ fi
17 echo "using netdata server at: $host"
18
19 # 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))
21 if [ "${#charts[@]}" -eq 0 ]
22 then
23 echo "Cannot download charts from server: $host"
24 exit 1
25 fi
26
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)"
28 [ $(( update_every + 1 - 1)) -eq 0 ] && update_every=1
29
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)"
31 [ $(( entries + 1 - 1)) -eq 0 ] && entries=3600
32
33 # to compare equal things, set the entries to 3600 max
@@ -55,7 +55,7 @@ trap cleanup EXIT
55
56 while true
57 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"
59 # shellcheck disable=SC2034
60 for x in {1..100}
61 do
tests/urls/request.sh.in
+42 -36
@@ -18,6 +18,9 @@ OUTDIR="tests"
18 OUTEDIR="encoded_tests"
19 OUTOPTDIR="options"
20 ERRDIR="etests"
21 +NOCOLOR='\033[0'
22 +RED='\033[0;31m'
23 +GREEN='\033[0;32m'
24
25 ################################################################################################
26 #### ####
@@ -27,7 +30,7 @@ ERRDIR="etests"
30
31 # Print error message and close script
32 netdata_print_error(){
30 - echo "Closing due error \"$1\" code \"$2\""
33 + echo "${RED} Closing due error \"$1\" code \"$2\" ${NOCOLOR}"
34 exit 1
35 }
36
@@ -200,36 +203,40 @@ netdata_download_allmetrics() {
203 }
204
205
203 -################################################################################################
206 +####################################################
207 #### ####
205 -#### MAIN ROUTINE ####
208 +#### MAIN ROUTINE ####
209 #### ####
207 -################################################################################################
210 +####################################################
211 MURL="http://127.0.0.1:19999"
212
213 +if [ -n "$1" ]; then
214 + MURL="$1"
215 +fi
216 +
217 netdata_create_directory $OUTDIR
218 netdata_create_directory $OUTEDIR
219 netdata_create_directory $OUTOPTDIR
220 netdata_create_directory $ERRDIR
221
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"
223 TEST=$?
224 if [ $TEST -ne "0" ] ; then
225 echo "Cannot connect to Netdata"
226 exit 1
227 fi
228
222 -netdata_download_various $MURL "netdata.conf" "netdata.conf"
229 +netdata_download_various "$MURL" "netdata.conf" "netdata.conf"
230
224 -netdata_download_various_with_options $MURL "netdata.conf" "netdata.conf"
231 +netdata_download_various_with_options "$MURL" "netdata.conf" "netdata.conf"
232
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"
234
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"
236
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"
240
241 netdata_print_header "Getting all the netdata charts"
242 CHARTS=$( netdata_download_charts "$MURL" "api/v1/charts" )
@@ -244,58 +251,57 @@ elif [ ${#CHARTS[@]} -ne ${#WCHARTS2[@]} ]; then
251 exit 3;
252 fi
253
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"
256
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"
259
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"
264
265 netdata_create_directory "$OUTDIR/chart"
266 for I in $CHARTS ; do
267 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"
269 done
270
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"
274
275 netdata_create_directory "$OUTDIR/alarm_variables"
276 for I in $CHARTS ; do
277 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"
279 done
280
281 netdata_create_directory "$OUTDIR/badge"
282 netdata_create_directory "$OUTEDIR/badge"
283 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"
285 done
286
287 netdata_create_directory "$OUTDIR/allmetrics"
281 -netdata_download_allmetrics $MURL "allmetrics"
288 +netdata_download_allmetrics "$MURL" "allmetrics"
289
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"
293
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"
297
298 netdata_create_directory "$OUTDIR/data"
299 netdata_create_directory "$OUTEDIR/data"
300 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"
302 break;
303 done
304
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}"
306
307 exit 0