seed.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env bash
  2. # Runs a few fictional actions through OliveTin's public API so that the
  3. # logs and execution pages have history to show. Fixed tracking ids keep
  4. # the logs table and execution URLs the same on every run.
  5. # Usage: seed.sh <base-url>
  6. set -euo pipefail
  7. base="${1:?base url}"
  8. api="$base/api/olivetin.api.v1.OliveTinApiService"
  9. rpc() {
  10. curl -fsS --max-time 10 -X POST -H 'Content-Type: application/json' -d "$2" "$api/$1"
  11. }
  12. run() {
  13. local tracking_id="$1" binding_id="$2" arguments="${3:-[]}"
  14. rpc StartAction "{\"bindingId\": \"$binding_id\", \"uniqueTrackingId\": \"$tracking_id\", \"arguments\": $arguments}" >/dev/null
  15. for _ in $(seq 50); do
  16. rpc ExecutionStatus "{\"executionTrackingId\": \"$tracking_id\"}" |
  17. jq -e '.logEntry.executionFinished' >/dev/null && return 0
  18. sleep 0.1
  19. done
  20. echo "Action $binding_id did not finish" >&2
  21. return 1
  22. }
  23. run 5eed0000-0000-4000-8000-000000000001 run_playbook
  24. run 5eed0000-0000-4000-8000-000000000002 nightly_backup
  25. run 5eed0000-0000-4000-8000-000000000003 restart_container '[{"name": "container", "value": "demo-web"}]'
  26. run 5eed0000-0000-4000-8000-000000000004 restart_media
  27. run 5eed0000-0000-4000-8000-000000000005 porch_light
  28. run 5eed0000-0000-4000-8000-000000000006 ping_host '[{"name": "host", "value": "nas.example.com"}, {"name": "count", "value": "4"}]'
  29. run 5eed0000-0000-4000-8000-000000000007 check_disk