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

Workflows Davis problem trigger

JhonU
Contributor

Hello everyone, I'm starting out with automations with workflows. I am making a worflow that, based on a Davis problem trigger, assigns a category between 3 levels that I have defined according to the time of day. For this I have the event trigger, as the first task I recover this information with a javascript code.

 

 

import { execution } from '@dynatrace-sdk/automation-utils';
export default async function ({ execution_id }) {
  // your code goes here
  // e.g. get the current execution
  const ex = await execution(execution_id);
  const problem_event = ex.params.event

  console.log('Affected entity IDs', problem_event);
}

 

 

My problem is that I cannot find a way to call the information of the sfirst task in my second task with GQL code where based on the problem id I detect the problem and do the aggregation functions that I require by assigning a priority field. For Example(I still need to execute the aggregations but I have it clearer in dql than in javascript)

 

 

fetch events, from:now()-6m
| filter event.kind == "DAVIS_PROBLEM"
| filter display_id==<id.problem_firstTask>
| fieldsAdd hour=formatTimestamp(timestamp,format:"H")

 

 

The goal of this is to then be able to use this information in an integration with ServiceNow to generate Tk's.

3 REPLIES 3

christian_kreuz
Dynatrace Helper
Dynatrace Helper

Hi!

Please try adding a sleep step in your JavaScript code:

export default async function ({ execution_id }) {
  console.log('Starting to sleep');
  const milliseconds = 15000;
  await new Promise(resolve => setTimeout(resolve, milliseconds));
  console.log('Done sleeping');
}

 

It can take a couple of seconds for events (in this case a Davis Problem) to be query-able in Grail via DQL, whereas the Workflow is triggered immediately when we first see the event.

 

ChristopherHejl
Dynatrace Advisor
Dynatrace Advisor

In order to make data available from a javascript task to its subsequent tasks, you need to return some data. This well then show up as a result on that task. In your example you could return the problem_event variable like so:

import { execution } from '@dynatrace-sdk/automation-utils';
export default async function ({ execution_id }) {
  // your code goes here
  // e.g. get the current execution
  const ex = await execution(execution_id);
  const problem_event = ex.params.event

  console.log('Affected entity IDs', problem_event);

  // return data will show up as task result
  // return data should always be an object
  // eg return {"my_key": "my_value"}
  return problem_event
}

  
Task results can be used by follow-up tasks using expressions: Expression reference - Dynatrace Docs
So again for your example, assuming the first task is named "get_problem_details":

fetch events, from:now()-6m
| filter event.kind == "DAVIS_PROBLEM"
| filter display_id=="{{ result('get_problems_details')['display_id']}}"
| fieldsAdd hour=formatTimestamp(timestamp,format:"H")


However if you simply need to access data from the event, you can also access this directly using the expressions as well  Expression reference - Dynatrace Docs

fetch events, from:now()-6m
| filter event.kind == "DAVIS_PROBLEM"
| filter display_id=="{{ event()['display_id'] }}"
| fieldsAdd hour=formatTimestamp(timestamp,format:"H")

Thanks so much, I am clearer about the use of reference expressions, I really didn't know how to integrate them into the gql codes.

Featured Posts