#!/bin/bash
# os_actions_daemon -- s6 longrun: polls the OpenStack API every INTERVAL seconds
# and keeps /var/lib/openstack-actions/state.json current for the Zabbix
# UserParameters (openstack.*). Credentials come from the environment, which
# run-script-daemon assembles from /etc/default/openstack-actions:
#   OS_AUTH_URL, OS_APPLICATION_CREDENTIAL_ID, OS_APPLICATION_CREDENTIAL_SECRET, OS_REGION_NAME
# The collector itself runs once per call and exits; failures are logged and
# retried at the next interval, the state file keeps the last good result.
set -u
INTERVAL="${INTERVAL:-300}"
for v in OS_AUTH_URL OS_APPLICATION_CREDENTIAL_ID OS_APPLICATION_CREDENTIAL_SECRET; do
  [ -n "${!v:-}" ] || { echo "openstack-actions: $v not set (see /etc/default/openstack-actions)" >&2; exec sleep 300; }
done
while :; do
  /usr/lib/aep-zabbix-checks/os_actions_collect.py || echo "openstack-actions: collector exited with $?" >&2
  sleep "$INTERVAL"
done
