check-results.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. matched_node1="$(curl --user admin:public -sf http://localhost:18083/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@node1.emqx.io\") | .metrics.matched")"
  4. matched_node2="$(curl --user admin:public -sf http://localhost:18084/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@node2.emqx.io\") | .metrics.matched")"
  5. success_node1="$(curl --user admin:public -sf http://localhost:18083/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@node1.emqx.io\") | .metrics.\"actions.success\"")"
  6. success_node2="$(curl --user admin:public -sf http://localhost:18084/api/v5/rules | jq --raw-output ".[0].node_metrics[] | select(.node==\"emqx@node2.emqx.io\") | .metrics.\"actions.success\"")"
  7. webhook="$(curl -sf http://localhost:7077/counter | jq '.data')"
  8. MATCHED_TOTAL="$(( matched_node1 + matched_node2 ))"
  9. SUCCESS_TOTAL="$(( success_node1 + success_node2 ))"
  10. COLLECTED_TOTAL="$webhook"
  11. is_number() {
  12. re='^[0-9]+$'
  13. if ! [[ $2 =~ $re ]] ; then
  14. echo "error: $1=$2 is not a number" >&2; exit 1
  15. fi
  16. }
  17. is_number MATCHED_TOTAL "$MATCHED_TOTAL"
  18. is_number SUCCESS_TOTAL "$SUCCESS_TOTAL"
  19. is_number COLLECTED_TOTAL "$COLLECTED_TOTAL"
  20. if [ "$MATCHED_TOTAL" -lt 290 ] || \
  21. [ "$SUCCESS_TOTAL" -lt 290 ] || \
  22. [ "$COLLECTED_TOTAL" -lt 290 ]; then
  23. echo "FAILED"
  24. echo "MATCHED_TOTAL=$MATCHED_TOTAL"
  25. echo "SUCCESS_TOTAL=$SUCCESS_TOTAL"
  26. echo "COLLECTED_TOTAL=$COLLECTED_TOTAL"
  27. exit 1
  28. else
  29. echo "ALL_IS_WELL"
  30. exit 0
  31. fi