Giter Club home page Giter Club logo

Comments (7)

dbbaughe avatar dbbaughe commented on August 16, 2024

Hi @ammardodin,

It's just left out of the documentation. You have access to the id as {{ctx.monitor.id}}, when testing with the preview in Kibana or "Send test message" it appears this is empty, but during actual execution it will be correctly supplied.

It does look like we have inconsistent values being passed in Kibana UI and Elasticsearch though when comparing the actual context values with what's listed on the documentation:
https://github.com/opendistro-for-elasticsearch/alerting/blob/master/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/model/Monitor.kt#L79

from alerting.

lucaswin-amzn avatar lucaswin-amzn commented on August 16, 2024

This is a bug / discrepancy between the UI and backend documentation. Kibana is using the execute API which is providing different context variables than during actual monitor execution.

from alerting.

ammardodin avatar ammardodin commented on August 16, 2024

Unfortunately, it seems that {{ctx.monitor.id}} is rendered as an empty string. Same is true for {{ctx.alert.id}}, which is extremely problematic.

from alerting.

dbbaughe avatar dbbaughe commented on August 16, 2024

@ammardodin
The UI is rendering it as an empty string, but it should actually be provided in the message being sent. This is a discrepancy between Kibana plugin and Elasticsearch plugin providing different context values for the message preview. You should be able to see the actual value from your destination when clicking "send test message". If you still do not see it let me know from your destination and I can look into it more.

Edit: Looked into it a bit more. The Kibana UI is calling the Execute API with dryrun=false and no MonitorID. This is because our current logic only sends out notifications when dryrun=false, but will also save an alert if dryrun=false AND MonitorID exists. Because of this we do not have a MonitorID while in the Execute API. So when providing the monitor to the context variable, it has no MonitorID to access during the "send test message". That being said, you will have the monitor ID during an actual alert.

from alerting.

ammardodin avatar ammardodin commented on August 16, 2024

@dbbaughe to clarify, I am not using Kibana. I am using the API to create my monitors. It seems that I can access the monitor id via {{ctx.monitor._id}} not {{ctx.monitor.id}}.

As for the alert id, I still can't access it via {{ctx.alert.id}}, as that is being returned as an empty string, even though that I definitely see an active alert for the monitor in question in the .opendistro-alerting-alerts index.

To reproduce on 0.7.1 using the API:

  1. Create a Slack destination.
  2. Create a monitor with a truthy trigger, i.e. return true;.
  3. Point monitor action to destination id from 1, and use {{ctx.alert.id}} as the action message.

from alerting.

dbbaughe avatar dbbaughe commented on August 16, 2024

@ammardodin,

This is what's currently provided on the monitor on the ctx variable during trigger execution and action execution. The documentation should be updated to reflect this (and this should probably provide more than just this information).

This is what's currently provided on the alert on the ctx variable. This was updated in v0.9.0 which included this PR.

The thing to be aware of though is that this is referring to the current existing alert (if one exists) during this execution. So for your very first alert there would be no alert.id because no alert exists. And the next alert would contain an alert.id of the existing alert (again, only if one exists).

from alerting.

skkosuri-amzn avatar skkosuri-amzn commented on August 16, 2024

Closing based on last comment. Feel free to reopen, if this is still an issue.

from alerting.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.