#!/bin/bash # Find the first "Restricted zone" alert, update its status and operator, # then list alerts before and after. # Usage: ./alert_status.sh [status] [operator] # status - optional, default: resolved # operator - optional, default: admin # Example: ./alert_status.sh acknowledged "John Doe" # BASE_URL=http://host:port ./alert_status.sh resolved admin SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" . "${SCRIPT_DIR}/../_common.sh" STATUS="${1:-resolved}" OPERATOR="${2:-admin}" echo "=== Alerts before update ===" ALERTS=$(curl -s -X GET "${BASE_URL}/reslevis/alerts?limit=100&offset=0") echo "$ALERTS" | jq '.' ALERT_ID=$(echo "$ALERTS" | jq -r '[.[] | select(.type == "Restricted zone")] | first | .id') if [ -z "$ALERT_ID" ] || [ "$ALERT_ID" = "null" ]; then echo "No alert with type 'Restricted zone' found." exit 1 fi echo "" echo "=== Updating alert ${ALERT_ID} (status=${STATUS}, operator=${OPERATOR}) ===" curl -s -X PATCH "${BASE_URL}/reslevis/alerts/${ALERT_ID}" \ -H "Content-Type: application/json" \ -d "{\"status\": \"${STATUS}\", \"operator\": \"${OPERATOR}\"}" echo "" echo "" echo "=== Alerts after update ===" curl -s -X GET "${BASE_URL}/reslevis/alerts?limit=100&offset=0" | jq '.'