Placing 'Console.log' of an API in an Alert Notification

Hi,
I’m using a Condition, which notifies me via email if my API script fails in synthetics.
The Synthetic API Script checks a website for a certain json object and if it contains a predefined string.
The output from the function is via “console.log(object)”.

I want to create a custom violation description that includes this ‘console.log’ if the condition fails.
So basically there are 3 things missing:
-Adress this API via NRQL,
-define a FAILED / SUCCESS Threshold
-Include ‘Console.log’ in the Incident description/Notification

Hi @d.meyer

Nearly any attribute on an event (for example SyntheticCheck) can be included in the notification resulting from a violation on a NRQL alert condition. Alert custom violation descriptions can be used to include any attribute you use in a FACET clause in the NRQL alert condition’s query.

I think the biggest problem with meeting this use-case would be getting the console.log(object) to show up as an attribute on the SyntheticCheck event. However, this would make a great feature request.

For now, you could write up some instructions on how to access the console.log in a Google doc (or some shared format) and include a URL link in the Runbook URL field of the alert condition.

As a (far more complex) alternative, you could access the Insights Event API in your script and publish your own custom event to NRDB. You could then include attributes that would show success or failure, and send along the log as its own attribute. You would then set up your NRQL alert condition to query your custom event and facet on the attribute that contains the console.log information, then use Custom Descriptions (documentation linked above) to include that detail in any notifications that got sent out.

I hope this helps get you sorted!

2 Likes

Thank You,
I’m going with that runbook URL solution.
Is there anyway to get the definied URL from the Synthetic Script into the Alert Description ?
Like “$browser.get(‘URL’);” or paste the entire Script into the Alert Description of the Failed Monitor ?
Also In which format is {{timestamp}}, and is there a way to get it to show the actual date of the incident like MM-DD-YY HH:MM:SS ?

Thank you so far :wink: