Need help for Energy Monitoring System Alerts

alerting

(Jodhi Adhikaprana Sardjono) #1

Hello I'm a student and I really need your help to sort this out. So, I want to create a real time monitoring data for voltage consumption. The outcome will be: there will be an alert if the voltage value exceeds the 'UpperThreshold' or lower than the 'LowerThreshold' I still don't understand how to write the 'input' part properly. Can someone help me to do so?

1. The response said like this:
"messages": [
"failed to execute watch input"

2. Here is my alerting code
{
"trigger": {
"schedule": {
"interval": "5s"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"voltage-ab"
],
"types": [
"VoltageAB"
]
}
}
},
"condition": {
"compare": {
"ctx.payload.voltageValue": {
"gt": 450
}
}
},
"actions": {
"logging": {
"logging": {
"level": "info",
"text": "its working!"
}
}
}
}

3. And here is my 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"
}
}
}
}
}

4. This is the example input
POST /test-1/Test1
{
"Value": "500",
"date": "2017-06-13T16:20:00.000Z",
"UpperThreshold":"450",
"LowerThreshold": "380"
}

Thank you for your help


(Alexander Reelsen) #2

Hey,

please paste the output of the execute watch API here and not just a single line, so debugging will be possible. Thanks!

--Alex


(Jodhi Adhikaprana Sardjono) #3

{
"watch_id": "Voltage-AB-Watcher2",
"state": "failed",
"_status": {
"state": {
"active": true,
"timestamp": "2017-06-14T00:37:22.768Z"
},
"actions": {
"logging": {
"ack": {
"timestamp": "2017-06-14T00:37:22.768Z",
"state": "awaits_successful_execution"
}
}
}
},
"trigger_event": {
"type": "schedule",
"triggered_time": "2017-06-15T16:06:46.961Z",
"schedule": {
"scheduled_time": "2017-06-15T16:06:46.665Z"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"voltage-ab"
],
"types": [
"VoltageAB"
]
}
}
},
"condition": {
"compare": {
"ctx.payload.voltageValue": {
"gt": 450
}
}
},
"metadata": {
"name": "Voltage-AB-Watcher2"
},
"result": {
"execution_time": "2017-06-15T16:06:46.961Z",
"execution_duration": 1,
"input": {
"type": "search",
"status": "failure",
"reason": "NullPointerException[null]"
},
"actions": []
},
"messages": [
"failed to execute watch input"
]
}


(Alexander Reelsen) #4

Hey,

can you try changing your search input to also include a query like this

"indices" : [ ... ],
"types" : [ ... ],
"body" : {
  "query" : { "match_all": {}}
}

and report back if that works?

--Alex


(Jodhi Adhikaprana Sardjono) #5

Thank you Alex it works!

Can you help also how to locate the "Value" property in my index using the 'compare'? I want to get an alert if the latest Value is more than 450.

I guess this query: "ctx.payload.Value" : {"gt: 450"} is wrong, isnt it?

This is the execution output:

{
"watch_id": "Voltage-AB-Watcher2",
"state": "execution_not_needed",
"_status": {
"state": {
"active": true,
"timestamp": "2017-06-24T05:14:24.291Z"
},
"last_checked": "2017-06-24T05:14:33.726Z",
"actions": {
"logging": {
"ack": {
"timestamp": "2017-06-24T05:14:24.291Z",
"state": "awaits_successful_execution"
}
}
}
},
"trigger_event": {
"type": "schedule",
"triggered_time": "2017-06-24T05:14:33.726Z",
"schedule": {
"scheduled_time": "2017-06-24T05:14:33.251Z"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"test-1"
],
"types": [
"Test1"
],
"body": {
"query": {
"match_all": {}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.Value": {
"gt": 400
}
}
},
"metadata": {
"name": "Voltage-AB-Watcher2"
},
"result": {
"execution_time": "2017-06-24T05:14:33.726Z",
"execution_duration": 11,
"input": {
"type": "search",
"status": "success",
"payload": {
"_shards": {
"total": 5,
"failed": 0,
"successful": 5
},
"hits": {
"hits": [
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T14:30:00.000Z",
"LowerThreshold": "380",
"Value": "415",
"UpperThreshold": "450"
},
"_id": "AVyiFsRyTbYjGVwV_rPd",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T16:10:00.000Z",
"LowerThreshold": "380",
"Value": "420",
"UpperThreshold": "450"
},
"_id": "AVyiE1t5TbYjGVwV_rG-",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T16:50:00.000Z",
"LowerThreshold": "380",
"Value": "410",
"UpperThreshold": "450"
},
"_id": "AVyiFD-_TbYjGVwV_rJL",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T15:00:00.000Z",
"LowerThreshold": "380",
"Value": "425",
"UpperThreshold": "450"
},
"_id": "AVyiFdJxTbYjGVwV_rM0",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T06:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys8d9PfS18ne-HaHbs",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T11:00:00.000Z",
"LowerThreshold": "380",
"Value": "390",
"UpperThreshold": "450"
},
"_id": "AVys8jUwfS18ne-HaHcu",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T19:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys8t7YfS18ne-HaHev",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T23:00:00.000Z",
"LowerThreshold": "380",
"Value": "410",
"UpperThreshold": "450"
},
"_id": "AVys8wMmfS18ne-HaHfR",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-12T06:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys82zqfS18ne-HaHgx",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T20:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys8uW9fS18ne-HaHew",
"_score": 1
}
],
"total": 83,
"max_score": 1
},
"took": 9,
"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.Value": null**
}
}
},
"actions": []
},
"messages": []
}


(Alexander Reelsen) #6

hey,

if you are on Elasticsearch 5.x, always use a scripting condition like return ctx.payload.Value > 450 as it's much simpler to use. It's as secure thanks to our relatively new painless scripting language.

--Alex


(Alexander Reelsen) #7

One more thing: When you are tring to access the Value of a found search hit, you need to specify the path like ctx.payload.hits.hits[0]._source.Value in painless or ctx.payload.hits.hits.0.Value in mustache.

Hope this helps!

--Alex


(Jodhi Adhikaprana Sardjono) #8

Thank you very much for your help! At first I thought that was the answer. It turns out, the response still indicates a 'null' like this: "ctx.payload.hits.hits[0]._source.Value": null.

Why does the alert not triggered as expected?

The response is like this (it is still the same) :

{
"watch_id": "Voltage-AB-Watcher2",
"state": "execution_not_needed",
"_status": {
"state": {
"active": true,
"timestamp": "2017-06-27T07:27:38.068Z"
},
"last_checked": "2017-06-27T07:27:58.149Z",
"actions": {
"logging": {
"ack": {
"timestamp": "2017-06-27T07:27:38.068Z",
"state": "awaits_successful_execution"
}
}
}
},
"trigger_event": {
"type": "schedule",
"triggered_time": "2017-06-27T07:27:58.149Z",
"schedule": {
"scheduled_time": "2017-06-27T07:27:58.040Z"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"test-1"
],
"types": [
"Test1"
],
"body": {
"query": {
"match_all": {}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.hits[0]._source.Value": {
"gt": 400
}
}
},
"metadata": {
"name": "Voltage-AB-Watcher2"
},
"result": {
"execution_time": "2017-06-27T07:27:58.149Z",
"execution_duration": 2,
"input": {
"type": "search",
"status": "success",
"payload": {
"_shards": {
"total": 5,
"failed": 0,
"successful": 5
},
"hits": {
"hits": [
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T14:30:00.000Z",
"LowerThreshold": "380",
"Value": "415",
"UpperThreshold": "450"
},
"_id": "AVyiFsRyTbYjGVwV_rPd",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T16:10:00.000Z",
"LowerThreshold": "380",
"Value": "420",
"UpperThreshold": "450"
},
"_id": "AVyiE1t5TbYjGVwV_rG-",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T16:50:00.000Z",
"LowerThreshold": "380",
"Value": "410",
"UpperThreshold": "450"
},
"_id": "AVyiFD-_TbYjGVwV_rJL",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-13T15:00:00.000Z",
"LowerThreshold": "380",
"Value": "425",
"UpperThreshold": "450"
},
"_id": "AVyiFdJxTbYjGVwV_rM0",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T06:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys8d9PfS18ne-HaHbs",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T11:00:00.000Z",
"LowerThreshold": "380",
"Value": "390",
"UpperThreshold": "450"
},
"_id": "AVys8jUwfS18ne-HaHcu",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T19:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys8t7YfS18ne-HaHev",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T23:00:00.000Z",
"LowerThreshold": "380",
"Value": "410",
"UpperThreshold": "450"
},
"_id": "AVys8wMmfS18ne-HaHfR",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-12T06:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys82zqfS18ne-HaHgx",
"_score": 1
},
{
"_index": "test-1",
"_type": "Test1",
"_source": {
"date": "2017-06-11T20:00:00.000Z",
"LowerThreshold": "380",
"Value": "400",
"UpperThreshold": "450"
},
"_id": "AVys8uW9fS18ne-HaHew",
"_score": 1
}
],
"total": 83,
"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]._source.Value": null
}
}
},
"actions": []
},
"messages": []
}


(Alexander Reelsen) #9

try to use mustache syntax in the compare condition, not painless syntax. Or use a scripted condition (which I personally would prefer)


(Jodhi Adhikaprana Sardjono) #10

Thank you for your replies! I dont know why it's still not working.... gotta work some more.


(Jodhi Adhikaprana Sardjono) #11

Hello, its me again. I did the mustache syntax, and the response is similar: the value is null. Can you elaborate a bit about what you said, in terms of the scripted condition? Really appreciate your help!

Response:
{
"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": []
}


(Alexander Reelsen) #12

Hey,

the path in your compare condition does not exist, you forgot to specify the _source field.

Yet, I still do not understand why you want to check values of a single document. Wouldnt it make more sense to find out the min/max value of the last 10 minute and use that one?

--Alex


(Jodhi Adhikaprana Sardjono) #13
  1. yes, I tried to go with your advice here, "....ctx.payload.hits.hits[0]._source.Value in painless or ctx.payload.hits.hits.0.Value in mustache." the results for both were the same.

  2. Thanks for the insight, I understand more now. So here is my mission: I want to create an alert, say for the last 1 minute. I want to send an email if, at least there was a 'Value', which was outside of the range (stated by the 'Upper Threshold' and the 'Lower Threshold').

How do I correct the code?

All of my friends are unfamiliar with this kind of syntax, so your help is much appreciated.


(system) #14

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.