template_dim.sh.in 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. #The health directory to put the alarms
  3. HEALTHDIR="@configdir_POST@/health.d/"
  4. #the current time
  5. OUTDIR="alarms"
  6. QUERY="/api/v1/alarms?all"
  7. MURL="http://localhost:19999$QUERY"
  8. #error messages
  9. RED='\033[0;31m'
  10. GREEN='\033[0;32m'
  11. NOCOLOR='\033[0m'
  12. ALARMTEST="dev_dim_template"
  13. change_alarm_file() {
  14. if [ -f "$1" ]; then
  15. rm "$1"
  16. fi
  17. #copy keeping the permissions
  18. cp -a "$2" "$3"
  19. }
  20. netdata_test_download() {
  21. grep "HTTP/1.1 200 OK" "$1" 2>/dev/null 1>/dev/null
  22. TEST="$?"
  23. if [ "$TEST" -ne "0" ]; then
  24. echo -e "${RED} Error to get the alarm log. ${NOCOLOR}"
  25. exit 1
  26. fi
  27. TOTALARM=$(grep "$ALARMTEST" "$2" | grep name | cut -d: -f2 | grep -c "$ALARMTEST")
  28. if [ "$TOTALARM" -ne "$3" ]; then
  29. echo -e "${RED} The number of actives alarms with the name $SYSTEMALARM is wrong ${NOCOLOR}"
  30. exit 1
  31. fi
  32. }
  33. get_the_logs() {
  34. curl -v -k --create-dirs -o "$OUTDIR/$1.out" "$MURL" 2> "$OUTDIR/$1.err"
  35. netdata_test_download "$OUTDIR/$1.err" "$OUTDIR/$1.out" "$2"
  36. }
  37. process_data() {
  38. netdata -D &
  39. NETDATAPID=$!
  40. echo -e "${NOCOLOR}Sleeping during 15 seconds to create alarms"
  41. sleep 15
  42. kill $NETDATAPID
  43. get_the_logs "$1" "$2"
  44. }
  45. mkdir "$OUTDIR"
  46. CREATEDIR="$?"
  47. if [ "$CREATEDIR" -ne "0" ]; then
  48. echo -e "${RED}Cannot create the output directory, it already exists. The test will overwrite previous results. ${NOCOLOR}"
  49. fi
  50. if [ -n "$1" ]; then
  51. MURL="$1$QUERY"
  52. fi
  53. change_alarm_file "./0" "system_cpu.conf.unique_alarm" "$HEALTHDIR/dim_double_without_template.conf"
  54. process_data "double_without_template" 3 "$HEALTHDIR/dim_double_without_template.conf"
  55. change_alarm_file "$HEALTHDIR/dim_double_without_template.conf" "system_cpu.conf.alarm_foreach" "$HEALTHDIR/dim_foreach_without_template.conf"
  56. process_data "foreach_without_template" 3 "$HEALTHDIR/dim_foreach_without_template.conf"
  57. change_alarm_file "$HEALTHDIR/dim_foreach_without_template.conf" "system_cpu.conf.alarm_foreach_sp" "$HEALTHDIR/dim_foreach_without_template_sp.conf"
  58. process_data "foreach_without_template" 10 "$HEALTHDIR/dim_foreach_without_template_sp.conf"
  59. change_alarm_file "$HEALTHDIR/dim_foreach_without_template_sp.conf" "system_cpu.conf.template_alarm" "$HEALTHDIR/dim_double_with_template.conf"
  60. process_data "double_with_template" 3 "$HEALTHDIR/dim_double_with_template.conf"
  61. change_alarm_file "$HEALTHDIR/dim_double_with_template.conf" "system_cpu.conf.template_foreach" "$HEALTHDIR/dim_foreach_with_template.conf"
  62. process_data "foreach_with_template" 3 "$HEALTHDIR/dim_foreach_with_template.conf"
  63. change_alarm_file "$HEALTHDIR/dim_foreach_with_template.conf" "system_cpu.conf.template_foreach_sp" "$HEALTHDIR/dim_foreach_with_template_sp.conf"
  64. process_data "foreach_with_template" 10 "$HEALTHDIR/dim_foreach_with_template_sp.conf"
  65. rm "$HEALTHDIR/dim_foreach_with_template_sp.conf"
  66. rm -rf "$OUTDIR"
  67. echo -e "${GREEN} all the tests were successful ${NOCOLOR}"