> For the complete documentation index, see [llms.txt](https://edgex-api-advantech.gitbook.io/edgex-api-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edgex-api-advantech.gitbook.io/edgex-api-doc/advanteched-services-apis/alarm-service-apis.md).

# Alarm Service APIs

## **Content**

* Introduction
* Alarm Service APIs

## Introduction

Alarm service includes a lightweight rule engine, which provides IoT analytics and streaming capability. The rules are based on Source, SQL and Sink.

It is an edge lightweight IoT data analytics / streaming software implemented by Golang, and it can be run at all kinds of resource constrained edge devices. Kuiper rules are based on Source, SQL and Sink.

* Source: The data source of streaming data, such as data from MQTT broker. In EdgeX scenario, the data source is EdgeX message bus, which could be MQTT broker.
* SQL: SQL is where you specify the business logic of streaming data processing. Kuiper provides SQL-like statements to allow you to extract, filter & transform data.
* Sink: Sink is used for sending analysis result to a specified target. For example, send analysis result to another MQTT broker, or an HTTP rest address.

It provides a set of REST API for streams and rules management in addition to CLI.

By default, the REST API are running in port 9081. You can change the port in /etc/kuiper.yaml for the restPort property. We have used support-rulesengine API version 1.0.0 that running in port 48075.

## Alarm Service APIs

### Rules management

* create a rule
* show rules
* describe a rule
* update a rule
* drop a rule
* start a rule
* stop a rule
* restart a rule
* get the status of a rule

#### create a rule

(1) Example for MQTT output:

<div align="left"><img src="https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FrChsVFHje7f6CuR0ziNi%2Fkk.JPG?alt=media&amp;token=d592a93c-4aab-4a7e-be25-d3e076fed3a1" alt=""></div>

User application subscribes the broker and topic, then will get the alarm data with JSON format as below.

|                                |
| ------------------------------ |
| *\[{"RandomValue\_Int8": -6}]* |

(2) Example for Rest API output:

<div align="left"><img src="https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FFEDbxwLpz4MF5kYAVi7O%2Fhh.JPG?alt=media&amp;token=a69b1eb2-fe18-4dd5-b66a-5d725087571a" alt=""></div>

User application implements the your-restapi-server/api/action method, then the RestAPI server will get the alarm data with JSON format as below.

|                            |
| -------------------------- |
| *{RandomValue\_Int8: -97}* |

(3) CPU temperature example for MQTT output:

* An example of CPU temperature
* Create a sink that both name and type is EdgeX
* The sink result will be published to the topic result and you can get the data context from the MQTT broker as below: \[{"device":"cpu","temperature":62}]

<div align="left"><img src="https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FsyIxLx9m5pVQmWePDXKf%2F1.JPG?alt=media&amp;token=1ba679b4-e142-419b-8df2-b751cd368930" alt=""></div>

(4) Battery temperature example for MQTT output:

* An example of battery temperature
* Create a sink that name is demo and type is zmq
* The sink result will be published to the topic result and you can get the data context from the MQTT broker as below: \[{"device":"Battery-POC6-01“, "temperature":31}]

<div align="left"><img src="https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2F9ykQusPYuOBwOtAThFwu%2F2.JPG?alt=media&amp;token=b94d9130-9f10-4af3-acbd-26834ecf2b34" alt=""></div>

(5) Battery remaining capacity example for MQTT output:

* An example of battery remaining capacity
* Create a sink that name is demo and type is zmq
* The sink result will be published to the topic result and you can get the data context from the MQTT broker as below: \[{"device":"Battery-POC6-01“, “capacity":100}

<div align="left"><img src="https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FRaGaGU6BahOGA6vRe2jC%2F3.JPG?alt=media&amp;token=28f7afee-5854-4641-a328-4d06e9c120f8" alt=""></div>

#### show rules

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2F2O0CFokxaWMohFkj9IgF%2F14.JPG?alt=media\&token=6a8c4eef-49a3-42c9-940b-ab3e7171c39d)

#### describe a rule

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FWpR4lJP3YKzrhq4ycvcx%2F16.JPG?alt=media\&token=8c27ea9c-2558-47f1-bda5-b4375ffc8ea7)

#### update a rule

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2F9jBshQSbNZzD8LvU1aHP%2F18.JPG?alt=media\&token=c4ee52b7-11b4-44ba-9a73-fe81b40215bf)

#### drop a rule

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FlIHoCUVQVZHYzQzh1Xkt%2F20.JPG?alt=media\&token=e91b8bd2-fa23-429d-b08f-2c955a2bb188)

#### start a rule

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FyELwJAlaeFfExZ3SBhKh%2F22.JPG?alt=media\&token=a4fe817d-4640-45b7-9678-0e3b50de1c43)

#### stop a rule

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FKn6mu2nWo1V5qpRrQxiv%2F24.JPG?alt=media\&token=16e74ce0-214f-4cbc-a351-5bfa72bd70f4)

#### restart a rule

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2FqLp0d3fvy0HRX18IojLq%2F26.JPG?alt=media\&token=99d51d24-ac33-43ef-8da0-9552338fdd71)

#### get the status of a rule

Example:

![](https://1210863923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ldahy90A1eekcr5A2U8%2Fuploads%2F278COfweIiIl2A9uobLr%2F28.JPG?alt=media\&token=49a00394-5e6c-4166-80bc-1570e11876c7)

**Reference:**

1.<https://github.com/lf-edge/ekuiper/blob/master/docs/en_US/edgex/edgex_rule_engine_tutorial.md>\
2.<https://fuji-docs.edgexfoundry.org/support-rulesengine.html>\
3.[https://github.com/lf-edge/ekuiper/blob/master/docs/en\_US/restapi/overview.md](<https://github.com/lf-edge/ekuiper/blob/master/docs/en_US/restapi/overview.md&#xD;&#xA;>)\
4\. [https://github.com/lf-edge/ekuiper/blob/master/docs/en\_US/sqls/streams.md <br>](<https://github.com/lf-edge/ekuiper/blob/master/docs/en_US/sqls/streams.md&#xD;&#xA;>)
