Alert Sources


Other than IoT Hub data, data from third-party systems can also be used as triggers when configuring alert rules. You can configure an alert source to define the source of the third-party system data, such as Kafka client, and the method of processing the data to map to the required metrics to be used as triggers.

Managing Alert Sources

Creating Alert Sources

  1. Log in to the EnOS Management Console, go to Alert Service > Alert Sources, and you will see the list of alert sources that have been created.

  2. Click New Alert Source.

  3. Fill in the information for the Source as per the below and click Next.

    • Name: Enter the name of the alert source to be created. You can click the Internationalization icon btn_internationalization to enter customized names for different locales.
    • Type: Select the source type, currently supports Kafka Client.
    • Topic: Enter a Kafka topic, 1 per text field. For more topics, click + Add.
    • Description: Enter the description for the alert source.


  4. Fill in the information for Data Mapping as per the below and click Save.

    • Method: Select a method for mapping, currently supports JAR. You would need to specify the Class Name as well as upload the JAR package. For more information, see Using JAR.


  5. The created alert source will appear in the list of alert sources.

  6. You need to enable the alert source before it can be used. Toggle on the switch under Enable for the alert source you created to enable it.

Editing Alert Sources

  1. In Common Alert Sources, locate the alert source you wish to edit from the list and click the Edit icon btn_edit.
  2. All fields can be edited. After editing, click Save to save the changes.

Deleting Alert Sources

  1. In Common Alert Sources, locate the alert source you wish to delete from the list.
  2. If the alert source is enabled, disable it first, then click the Delete icon btn_delete.


Note

Ensure that no alert rules are using the alert source before deleting it. The alert rule that uses a deleted alert source will not trigger.

Using JAR

  1. In the POM of your project, add the following dependency.

    <dependency>
     <groupId>com.envisioniot.enos</groupId>
     <artifactId>alert-engine-share</artifactId>
     <version>0.1.10-SNAPSHOT</version>
     <exclusions>
         <exclusion>
             <groupId>*</groupId>
             <artifactId>*</artifactId>
         </exclusion>
     </exclusions>
    </dependency>
    


  2. Create a parsing class that implements com.envisioniot.enos.alert_engine.core.share.datasource.dto.codec.StandardMetricResolver. For sample codes, see Sample Codes.

  3. Build a fat JAR, which is the JAR package to upload.

  4. The Class Name will be the full path of the parsing class, for example, com.envisioniot.MySimpleCodec.


../_images/alert_source_data_mapping.png

Sample Codes

MySimpleCodec Parsing Class

package com.envisioniot;

import com.envisioniot.custom.CustomMetric;
import com.envisioniot.enos.alert_engine.core.share.datasource.dto.codec.StandardMetricResolver;
import com.envisioniot.enos.alert_engine.core.share.metric.dto.Metric;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

public class MySimpleCodec implements StandardMetricResolver {
  public void init() {
    System.out.println("init my codec");
  }

  public Metric decode(String msg, Map<String, String> context) {
    final CustomMetric customMetric = new Gson().fromJson(msg, CustomMetric.class);

    Metric metric = new Metric();
    metric.setMetric(customMetric.getPayload().getMeasurepoints().getPointId());
    metric.setDataSource("20210729d96b9a770671d71b105e6671237da762");
    metric.setInstance(customMetric.getPayload().getAssetId());
    Map<String, String> labels = new HashMap<String, String>() {{
      put("key", customMetric.getOrgId());
    }};
    metric.setLabels(labels);
    metric.setOrgId(customMetric.getOrgId());
    metric.setTimestamp(customMetric.getPayload().getTime());
    metric.setTimezone(customMetric.getPayload().getTimezone());
    metric.setValue(customMetric.getPayload().getMeasurepoints().getValue() + "");
    return metric;
  }
}


CustomMetric Class

package com.envisioniot.custom;

import lombok.Data;

@Data
public class CustomMetric {
  private String orgId;
  private String modelId;
  private String modelIdPath;
  private Payload payload;
}


Payload Class

package com.envisioniot.custom;

import lombok.Data;

@Data
public class Payload {
  private MeasurePoint measurepoints;
  private String timezone;
  private String assetId;
  private long time;
}


MeasurePoint Class

package com.envisioniot.custom;

import lombok.Data;

@Data
public class MeasurePoint {
  private String pointId;
  private long value;
}