Use the values inside $TARGETS as a variable outside of $TARGETS

Alerts Question Template

I want to pass-in the value of the host for which the alert violation occurred in the webhook. I understand that the name of the target information is passed under the JSON object represented by $TARGETS. I want to leverage the name key, i.e. name of the target or entity passed in the $TARGETS outside of the $TARGETS variable. Is it possible?

Something like this:

  "entity": "$NAME",
  "targets": "$TARGETS",

Is it possible to do something like this?

The problem is that we have an existing system which does process webhooks from various systems but expects all the parameters to be of type String. So, it fails to parse the JSON object denoted by $TARGETS.

Helpful Resources:

Hi @siddhant.agarwal

If you’re passing the webhook into Insights, the $TARGETS variable (which is a JSON object in its own right) gets flattened. This is because Insights won’t accept nested arrays.

If you still want to access the name of the host for which the violation occurred, though, you may want to look into Alert custom violation descriptions. Depending on what type of alert condition you’re using, you could add {{targetname}} or {{tag.entityName}} to your description field to get that information. You can then include it in your webhook by adding the $DESCRIPTION variable (listed in the webhook notification channel documentation), which will render as a string that can be parsed.

Note that if you’re using a NRQL alert condition, you will need to make sure that you’re faceting by any of the attributes you want to include in your Description field. If you’re using {{tag.entityName}} in your description, you have to make sure to use FACET entityName in your NRQL query.

I hope this helps!

1 Like

We aren’t sending the webhook into Insights. We were sending it to an external system which expects it to be only of type string. So, I was looking for a way to pass it as String input to the external system. However, I found a resolution for this. In the Webhook if I append a string value to $TARGETS, New Relic automatically sends it as a String in the webhook. For example, I just did this: <custom_key>: “TEST - $TARGETS”

1 Like

@siddhant.agarwal Glad to hear that you resolved your issue! Thanks for sharing how. If you run into any other problems, feel free to let us know.

1 Like