Elasticsearch + Kibana + Alerting (X-Pack) For Energy Monitoring System

安稳与你 提交于 2019-12-13 17:21:45

问题


Can somebody help me with Alerting Via X-Pack for Energy monitoring system project? The main problem here is I can't collect the 'Value' data from the database, as I want to compare it later with the upper and the lower threshold.

So here is the index:

PUT /test-1
{
  "mappings": {
    "Test1": {
      "properties": {
        "Value": {
          "type": "integer"
        },
        "date": {
          "type": "date",
          "format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
        },
         "UpperThreshold": {
          "type": "integer"
         },
         "LowerThreshold": {
          "type": "integer"
         }
      }
    }
  }
}

Here is the example of the input:

POST /test-1/Test1
{
  "Value": "500",
  "date": "2017-06-13T16:20:00.000Z",
  "UpperThreshold":"450",
  "LowerThreshold": "380"
}

This is my alerting code

{
  "trigger": {
    "schedule": {
      "interval": "10s"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "logs"
        ],
        "types": [],
        "body": {
          "query": {
            "match": {
              "message": "error"
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gt": 0
      }
    }
  },
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "to": [
          "<account@gmail.com>"
        ],
        "subject": "Watcher Notification",
        "body": {
          "text": "{{ctx.payload.hits.total}} error logs found"
        }
      }
    }
  }
}

Here is the response I got from the alerting plugin

    {
    "watch_id": "Alerting-Test",
    "state": "execution_not_needed",
    "_status": {
    "state": {
    "active": true,
    "timestamp": "2017-07-26T15:27:35.497Z"
    },
    "last_checked": "2017-07-26T15:27:38.625Z",
    "actions": {
    "logging": {
    "ack": {
    "timestamp": "2017-07-26T15:27:35.497Z",
    "state": "awaits_successful_execution"
    }
    }
    }
    },
    "trigger_event": {
    "type": "schedule",
    "triggered_time": "2017-07-26T15:27:38.625Z",
    "schedule": {
    "scheduled_time": "2017-07-26T15:27:38.175Z"
    }
    },
    "input": {
    "search": {
    "request": {
    "search_type": "query_then_fetch",
    "indices": [
    "test-1"
    ],
    "types": [
    "Test1"
    ],
    "body": {
    "query": {
    "match_all": {}
    }
    }
    }
    }
    },
    "condition": {
    "compare": {
    "ctx.payload.hits.hits.0.Value": {
    "gt": 450
    }
    }
    },
    "metadata": {
    "name": "Alerting-Test"
    },
    "result": {
    "execution_time": "2017-07-26T15:27:38.625Z",
    "execution_duration": 0,
    "input": {
    "type": "search",
    "status": "success",
    "payload": {
    "_shards": {
    "total": 5,
    "failed": 0,
    "successful": 5
    },
    "hits": {
    "hits": [
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-22T12:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "350",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1P3lArbJ1tbnct4e",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-22T18:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "4100",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1Sq0ArbJ1tbnct4v",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-24T18:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "450",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1eLJArbJ1tbnct6G",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-23T00:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "400",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1VUzArbJ1tbnct5A",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-23T12:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "390",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1X4FArbJ1tbnct5R",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-23T18:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "390",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1YySArbJ1tbnct5T",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-26T00:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "4700",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1mflArbJ1tbnct67",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-26T06:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "390",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1oluArbJ1tbnct7M",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-21T12:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "400",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1IrZArbJ1tbnct3r",
    "_score": 1
    },
    {
    "_index": "test-1",
    "_type": "Test1",
    "_source": {
    "date": "2017-07-21T18:00:00.000Z",
    "LowerThreshold": "380",
    "Value": "440",
    "UpperThreshold": "450"
    },
    "_id": "AV1-1LwzArbJ1tbnct38",
    "_score": 1
    }
    ],
    "total": 20,
    "max_score": 1
    },
    "took": 1,
    "timed_out": false
    },
    "search": {
    "request": {
    "search_type": "query_then_fetch",
    "indices": [
    "test-1"
    ],
    "types": [
    "Test1"
    ],
    "body": {
    "query": {
    "match_all": {}
    }
    }
    }
    }
    },
    "condition": {
    "type": "compare",
    "status": "success",
    "met": false,
    "compare": {
    "resolved_values": {
    **"ctx.payload.hits.hits.0.Value": null**
    }
    }
    },
    "actions": []
    },
    "messages": []
    }

Really appreciate for your help!!

来源:https://stackoverflow.com/questions/45353931/elasticsearch-kibana-alerting-x-pack-for-energy-monitoring-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!