Configure Alerts#

This section provides instructions for setting up alerts in Time Series Analytics Microservice.

Docker Compose Deployment#

Docker - Publish MQTT Alerts#

Configure MQTT Alerts#

The following MQTT alerts are configured for both Wind Turbine Anomaly Detection sample app. Refer to the alerts section of each app’s config.json:

Configure MQTT Alert in TICK Script#

The MQTT alert() block is already configured by default in the TICK script for each app. Refer to the alert() section of each app’s TICK script:

Note

Setting QoS to 1 ensures messages are delivered at least once. Alerts are preserved and re-sent if the MQTT broker reconnects after downtime.

Docker - Subscribe to MQTT Alerts#

Follow the steps to subscribe to the published MQTT alerts.

  • To subscribe to all MQTT topics, execute the following command:

docker exec -ti ia-mqtt-broker mosquitto_sub -h localhost -v -t '#' -p 1883

Docker - Publish OPC-UA Alerts#

Prerequisite#

Ensure that make up_opcua_ingestion has been executed by following the steps in the getting started guide for the docker compose deployment

To enable OPC-UA alerts in Time Series Analytics Microservice, use the following steps.

Configuration#

1. Configure OPC-UA Alert in TICK Script#

The following code snippets show how to add the OPC-UA alert, if not already added, replace this in place of MQTT alert section in the TICK script.

wind-turbine-anomaly-detection/time-series-analytics-config/tick_scripts/windturbine_anomaly_detector.tick

data0
    |alert()
        .crit(lambda: "anomaly_status" > 0)
        .message('Anomaly detected: Wind Speed: {{ index .Fields "wind_speed" }}, Grid Active Power: {{ index .Fields "grid_active_power" }}, Anomaly Status: {{ index .Fields "anomaly_status" }}')
        .noRecoveries()
        .post('http://localhost:5000/opcua_alerts')
        .timeout(30s)

Note

  • The noRecoveries() method suppresses recovery alerts, ensuring only critical alerts are sent.

2. Upload the new UDF deployment package

To copy the TICK script and upload the new UDF deployment package, run the following commands:

cd industrial-edge-insights-time-series/apps/wind-turbine-anomaly-detection # path relative to git  clone   folder
cd time-series-analytics-config
export SAMPLE_APP="wind-turbine-anomaly-detection"

rm -f ${SAMPLE_APP}.tar
tar cf ${SAMPLE_APP}.tar models/ tick_scripts/ udfs/
curl -X POST https://127.0.0.1:3000/ts-api/udfs/package -F "file=@${SAMPLE_APP}.tar" -k

Note

If the curl command fails with 502, wait briefly and retry the command. This response can occur while the Time Series Analytics Microservice is still becoming ready.

3. Configuring OPC-UA Alert in config.json

Make the following REST API call to the Time Series Analytics microservice using config-opcua.json, which replaces the mqtt alerts key from config.json with the opcua key and its specific details:

wind-turbine-anomaly-detection/time-series-analytics-config/config.json

cd industrial-edge-insights-time-series/apps/wind-turbine-anomaly-detection/time-series-analytics-config
curl -k -X 'POST' \
'https://127.0.0.1:3000/ts-api/config' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d @config-opcua.json

Docker - Subscribe to OPC UA Alerts using Sample OPCUA Subscriber

  1. Install Python packages asyncio and asyncua to run the sample OPC UA subscriber

    python3 -m venv venv
    source venv/bin/activate
    pip install asyncio asyncua
    
  2. Run the following sample OPC UA subscriber by updating the <IP-Address of OPCUA Server> to read the alerts published to server on tag ns=1;i=2004 from Time Series Analytics Microservice.

    import asyncio
    from asyncua import Client, Node
    class SubscriptionHandler:
        def datachange_notification(self, node: Node, val, data):
            print(val)
    async def main():
        client = Client(url="opc.tcp://<IP-Address of OPCUA Server>:30003/freeopcua/server/")
        async with client:
            handler = SubscriptionHandler()
            subscription = await client.create_subscription(50, handler)
            myvarnode = client.get_node("ns=1;i=2004")
            await subscription.subscribe_data_change(myvarnode)
            await asyncio.sleep(100)
            await subscription.delete()
            await asyncio.sleep(1)
    if __name__ == "__main__":
        asyncio.run(main())
    

Supporting Resources