#!/bin/bash
#
# This script is called when a status report has been produced.
#
# The first parameter passed is the path to the status file.
#
# Native HTTP POST upload is available via statusUpload.baseUrl in nsmd_conf.json
# (final URL is {baseUrl}/nsm; see NSM_USER_GUIDE.md). Use this hook only when you need extra side effects.
#
# NOTE: This script should execute as quickly as possible as it is called on
# NSM's execution thread.  If the script does not return in a timely fashion
# (less than 5 seconds), NSM's watchdog will declare a hung process and abort
# operation.


# Legacy shell example (curl) — prefer statusUpload.baseUrl when possible:
function example_send_status_to_url() {
     STATUS_JSON=$(cat "${1}")
     ID=$(echo ${STATUS_JSON} | jq -r .id)
     SERVER_URL="${2}"

     curl -s -X POST "$SERVER_URL/api/status/ingest/$ID" \
          -H "Content-Type: application/json" \
          -d "$STATUS_JSON" \
          --max-time 3
}

exit 0
