cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Events API V2

MariusNicolae
Contributor

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

MariusNicolae_1-1650464071552.png

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

5 REPLIES 5

JamesKitson
Dynatrace Guru
Dynatrace Guru

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:

JamesKitson_0-1650483635036.png

 

{
        "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.

MariusNicolae
Contributor

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?

MariusNicolae_0-1650525396321.png

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

Hi @MariusNicolae 

The documentation around Rest API is not helping and its under statement :facepalm: 

I usually look at the schema part in the Rest API UI 

Yosi_Neuman_0-1650531420433.png

 

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  

 

 

dynatrace certificated professional - dynatrace primer partner - Matrix Soft Ware Division - Israel

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

MariusNicolae
Contributor

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