-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define threshold condition on Elasticsearch data #477
Comments
Hello @ehsanjavadynia,
https://github.com/hawkular/hawkular-alerts/blob/master/examples/elasticsearch/create-logs.sh The Elasticsearch alerter transform an Elasticsearch document into a Hawkular Event, and this requires a transformation to define which Elasticsearch field goes to target Hawkular Event, in the example this is defined in the trigger context mapping field like
Once the mapping is in place, the Elasticsearch alerter will pull ES documents and feed Hawkular Events that are ready to be evaluated with Event conditions like
So, it is important to note that any event/data in Hawkular needs an id as a source to refer in the condition, so, that normally should be defined in the mapping from Elasticsearch -> Hawkular. So, in your example, I would add a "@timestamp" data in the Elasticsearch document, that will help Kibana and Hawkular to have a time series data, something like:
So, in the trigger mapping we could then define something like:
And then define your condition like:
In theory, it should work, the Hawkular Event is thought for complex documents (which is the normal Elasticsearch use cases we have been working on, like logs info or similar) and perhaps for this specific example mapping into a simple Hawkular Data may work better, that is something we can plan in the roadmap, but using Event should work for your scenario. Please, let me know if these examples and steps work for your scenario. Lucas |
Thank you @lucasponce, your comment was very helpful. I've added number to this function: protected String getField(Map<String, Object> source, String name) {
if (source == null || name == null) {
return null;
}
if (name.charAt(0) == '\'' && name.charAt(name.length() - 1) == '\'') {
return name.substring(1, name.length() - 1);
}
String[] names = name.split("\\|");
String defaultValue = "";
if (names.length > 1) {
if (names[1].charAt(0) == '\'' && names[1].charAt(names[1].length() - 1) == '\'') {
defaultValue = names[1].substring(1, names[1].length() - 1);
}
name = names[0];
}
String[] fields = name.split("\\.");
for (int i=0; i < fields.length; i++) {
Object value = source.get(fields[i]);
if (value instanceof String) {
return (String) value;
}
if (value instanceof Number) {
return String.valueOf(value);
}
if (value instanceof Map) {
source = (Map<String, Object>) value;
}
}
return defaultValue;
} we couldn't run alert engine without docker. so I compiled the code and pushed the jar file into docker. now it's working. |
ah, good catch ! Really appreciate you can use this and help us to improve it. |
I have created |
Sure! thanks, I've joined jira, and I've created a pull request here: |
Hi, I've read the elasticsearch alerter document. but I didn't realize how I can define my condition based on source.
our elasticsearch document is something like this:
{ "key": "my-key", "value": 20 }
I want to define an alert which detect value higher than 45. Is it possible in hawkular?
I've already tried mapping value to text (using mapping field in context) and it didn't work. value won't be mapped to text.
is it possible to write a condition like this:
"conditions": [ { "type": "EVENT", "dataId": "myDataId", "expression": "source.value > 20" } ]
and can we use other condition types with elasticsearch plugin? (threshold, compare, ...).
Could you help me with this? I have spent two days reading documents and trying...
Thanks in advance
The text was updated successfully, but these errors were encountered: