Unit 4: Configuring Alert


To monitor the performance of your devices, you can define customized alert severities, alert types, alert content, and alert rules for any device anomaly. This unit shows how to enable alerts to monitor the data of the water meter. Refer to the steps below.

Step 1: Creating Alert Source

As the data from the water meter is of non-EnOS standard data format, this step creates an alert source to monitor the Kafka message and customize the conversion method to construct the alert metric using a data mapping JAR package.


For more information, see Alert Sources.

Data Mapping JAR Package

The JAR package will implement the StandardMetricResolver method which will be defined when creating the alert source later to take out the flow value in the Kafka message and convert it to alert data.

  1. Include the dependency by adding the following code snippet.

    <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. Use the example code below to create a parsing class that implements StandardMetricResolver.

    package com.example.alertsource;
    
    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 com.google.gson.reflect.TypeToken;
    import lombok.extern.slf4j.Slf4j;
    
    import java.util.Map;
    
    @Slf4j
    public class CodecAlertData implements StandardMetricResolver {
     private static final String METRIC = "flow";
    
     private static final String ORG_ID = "yourOrgId";
     private static final String INSTANCE = "XolflP2C";
     private static final String TIMEZONE = "+08:00";
    
     private static final Gson GSON = new Gson();
    
     @Override
     public void init() {
       // do nothing
     }
    
     @Override
     public Metric decode(String msg, Map<String, String> context) {
       log.info("consume msg: {}, context: {}", msg, context);
    
       Metric metric = new Metric();
    
       try {
         Map<String, Object> inputData = GSON.fromJson(msg, new TypeToken<Map<String, Object>>() {}.getType());
    
         final long timestamp = System.currentTimeMillis();
    
         metric.setMetric(METRIC);
         metric.setOrgId(ORG_ID);
         metric.setInstance(INSTANCE);
         metric.setTimezone(TIMEZONE);
         metric.setTimestamp(timestamp);
         metric.setValue(String.valueOf(inputData.get(METRIC)));
    
         log.info("output metric: {}", metric);
    
         return metric;
       } catch (Throwable t) {
         log.error("process data error, ", t);
    
         return metric;
       }
     }
    }
    


  3. Create a JAR file from the above.

Alert Source

  1. In EnOS Management Console, select Alert Engine > Alert Sources.

  2. Click New Alert Source, and enter the following in the Source page.

    • Name: Water Meter Alert Source
    • Type: Kafka Client
    • Topic: Enter the topic given in the Kafka Pub node in the routing rule created in Unit 3.


    ../../_images/alert_source_source.png


  3. Click Next, and enter the following in the Data Mapping page.

    • Method: JAR
    • Class Name: com.example.alertsource.CodecAlertData
    • File: Upload the JAR file created above.


    ../../_images/alert_source_data_mapping.png


  4. Click Save to save the configuration.

  5. At the Alert Source page, enable the alert source.


    ../../_images/alert_source_enable.png

Step 2: Creating Alert Severity

  1. In EnOS Management Console, select Alert Engine > Alert Severities.

  2. Click New Severity, and enter the following in the New Severity window.

    • Severity ID: WaterMeterWarning
    • Severity Description: Warning


  3. Click Confirm to save the configuration.


    ../../_images/alert_severity2.png


For more information, see Alert Severities.

Step 3: Creating Alert Type

  1. In EnOS Management Console, select Alert Engine > Alert Types.

  2. Click New Type, and enter the following in the New Type window.

    • Type ID: FlowOverThreshold
    • Type Description: Flow over threshold


  3. Click Confirm to save the configuration.


    ../../_images/alert_type2.png


For more information, see Alert Types.

Step 4: Creating Alert Rule

  1. In EnOS Management Console, select Alert Engine > Alert Rules.
  2. Click New Rule, enter the following in the Add Alert Rule window, and click Confirm when done.


For more information, see Alert Rules.

Basic Information

  • Rule Name: Water Meter Rule
  • Rule ID: RuleForWaterMeter


../../_images/alert_rule_basic.png

Trigger

Specify the trigger metric.

  • Trigger Source: Others
    • Alert Source: Select the alert source created in step 1 above (Water Meter Alert Source)
    • Metric: flow
    • Data Type: Number


../../_images/alert_rule_trigger.png

Alert Condition

Set the alert condition to trigger the alert if the value of flow equals to or exceeds 10000.

  • Alert Condition: Threshold
    • Trigger: flow
    • Operator: >=
    • Type: Value
    • Value: 10000


../../_images/alert_rule_condition.png

Alert Details

  • Alert Content: Flow is over 10000
  • Alert Severity: Select the alert severity created in step 2 (Warning).
  • Alert Type: Select the alert type created in step 3 (Flow over threshold).


../../_images/alert_rule_details.png