20 Apr 2022 03:18 PM
Hi everyone,
Recently I have found myself with the need to implement events from some custom bash scripts and send the events into dynatrace. I am sending an error event type right now in order to open a problem on the host on which the script is running on, but when I receive the email all of the fields are present but we only need a specific field to be present in the body.
For example the event that I send is like this
event="{
\"eventType\": \"${eventType}\",
\"title\": \"External.Check event title\",
\"timeout\": 15,
\"entitySelector\": \"type(host),entityName("${entity}")\",
\"properties\": {
\"allowDavisMerge\": \"false\",
\"scriptPath\": \"${0}\",
\"scriptName\": \"${scriptName}\",
\"dt.event.description\": \"${scriptOutput}\"
}
}"
I only need the dt.event.description value to be sent by mail, the scriptPath and Name values should only be visible on dynatrace and not on the mail, but I can't seem to figure out how to do it
For example this is the mail I get, and I don't need the last 3 fields, I only need the first field with the name of the file that is missing, which is the dt.event.description field.
Does anyone know if this is doable? I searched around but I couldn't find anything and the chat support had no idea how the events work and they said they have no documentation other than what is on the public website but it doesn't seem to cover how you can filter what you need to send in a problem notification email
Thank you
Best regards
Solved! Go to Solution.
20 Apr 2022 08:45 PM
You can select the placeholders that are used in the email body, but you can't further filter or customize what those placeholders contain. So if that is the HTML payload placeholder you can't filter what it includes.
With that being said, there's a few things you can try. I tried in my environment and setting the eventType to CUSTOM_ALERT seems to change the body and it only included the following which looks like what you want:
{
"eventType": "CUSTOM_ALERT",
"title": "External.Check event title",
"timeout": 5,
"entitySelector":
"type(host),entityName(\"example.com\")",
"properties": {
"dt.event.allow_davis_merge": false,
"scriptPath": "/fake/path/",
"scriptName": "fake.sh}",
"dt.event.description": "output of the script"
}
}
I don't know what event type you are using but I saw the behavior you saw when it was set to a severity like AVAILABILITY.
CUSTOM_ALERT also has the affect of disabling DAVIS analysis which is what would cause events to be merged together into problems which I see you are trying to disable.
And on that note, what you have there for disabling the event merging likely won't work as that would need to be the reserved property dt.event.allow_davis_merge like you see in my example payload above. Note that false is not within quotes as it is a Boolean value. You can see the reserved properties by using the API call to list event properties.
21 Apr 2022 08:21 AM
Hi James,
Thank you very much for your inputs, I am using an error event type of event sorry I forgot to mention it.
I am a bit confused about the reserved properties to be honest, on the events documentation I didn't find info on everything and the example that is mentioned on the page has the allowDavisMerge property as a string value, is the example wrong?
https://www.dynatrace.com/support/help/dynatrace-api/environment-api/events-v2/post-event#examples
I found about the dt.event.description property from another community post as I was struggling to get the description field sent by mail and the chat support wasn't aware of this property either.
Do you know if there is further documentation on the official website that I didn't find about how the events work? I would love to get more insight into this as I found a very good usage for them.
Thank you!
Best regards
21 Apr 2022 10:00 AM
The documentation around Rest API is not helping and its under statement
I usually look at the schema part in the Rest API UI
And trying to play around with the Rest API from the UI and check the outcomes, kind of trail and error.
For you question I would try to split the Rest calls into 2 first the one with the property you want to get the alert with and the other one with the rest of the properties.
From dynatrace perspective the second will join the first and you get only one alert.
The only problem will be with the close message that will contains all the properties
HTH
Yos
21 Apr 2022 05:39 PM
Hi @MariusNicolae,
the documentation is being worked on afaik in order to update on the new event properties
Some other of these properties that may come in handy are .e.g.:
dt.event.allow_davis_merge
dt.event.suppress_problem
Both of them will store a Boolean.
The first one (as the name gives away) replaces the event v1 allowDavisMerge.
The second one can be used when an event that would usually raise a problem but in some specific case does not need to do so.
A complete payload with the examples above:
{
"eventType": "AVAILABILITY_EVENT",
"title": "Event Ttile",
"entitySelector": "entityId(HOST-12345)",
"properties": {
"dt.event.suppress_problem": true,
"dt.event.allow_davis_merge": true
}
}
Best,
Mark
04 May 2022 08:21 AM
Hi everyone, thank you so much for your answers!
I will go ahead and start replacing allowDavisMerge with the dt.event property and be waiting for the documentation to get written a bit better or at least the examples part, I think this could come in handy when trying to integrate an external check for a customer or at least this is the best solution that came to me.
Thank you!
Best regards