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!

3 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:

Hi @d.meyer

Is there any way 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?

Only attributes on the event type itself (probably SyntheticCheck) can be included in the description field. If you wanted to include an attribute, you would need to facet on it (e.g. FACET attributeName) in your NRQL query. So the answer to this question is “only if that information is included on the event type.”

Assuming that information is not included on the event, you could put instructions on how to get to the defined URL in your Runbook.

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 ?

This will come through in epoch timestamp format (e.g. 1617120000 = 16:00 UTC 30 March 2021). I am not aware of a way to change that format, but you could include a short instruction on how to translate the epoch timestamp in your Runbook.

As for Attributes on the evet type itself.
Does it include MonitorURL if u use Simple Browser checks.
I would like to get at least the monitor URL in my Alert Description.
The NRQL Alert for this would be: SELECT percentage(count(*), WHERE result='FAILED' ) FROM SyntheticCheck WHERE monitorName NOT LIKE '%testing%' FACET monitorName

I would like to get at least the monitor URL in my Alert Description.

If you wanted to include an attribute, you would need to facet on it (e.g. FACET attributeName) in your NRQL query. So long as it exists on the event type, and so long as you use it in the FACET clause, you can include it in your Custom Violation Description field.

In your example NRQL query, you would need to include it in the FACET clause, so it would look like this: ...FACET monitorName, monitorUrl.

1 Like

Well the Problem would be if I use something like
SELECT percentage(count(*), WHERE result='FAILED' ) FROM SyntheticCheck WHERE monitorName NOT LIKE '%testing%' FACET monitorName, monitorUrl
as a Signal i get monitorName, null in response.

Hi @d.meyer

I’ll be happy to take a look into it for you. :grin:

Can you send me here or as a private message the link to the condition that you have created?

thanks

Rodrigo