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

SDK problems fetched using @dynatrace-sdk/client-classic-environment-v2

derija
Participant

code:

import { problemsClient} from '@dynatrace-sdk/client-classic-environment-v2'
export default async function () {

const config: Object = {
"problemSelector": "displayId(P-23097463)",
"from": "-60d",
"to": "now"
}

let problems = (await problemsClient.getProblems(config)).problems
for (var sv of problems) {
console.log(Date(sv.startTime), Date(sv.endTime))
}
console.log(problems)

}

The startTime and EndTime are for the query and NOT for the actual Problem:

 

derija_1-1697239190603.png

 

UI shows correct values:

derija_0-1697239118537.png

 

How is this supposed to work? If I ask for a problem in the past?? Things like reports of problems in the last X days, to calculate total disruption based on entities and problems? like above?

 

 

 

4 REPLIES 4

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

Hi @derija 

 

I can't reproduce your problem with problemsClient.getProblems

Also I am not sure why you are quering problems via the problemsClient and not using DQL? Davis events and problems are also being stored in Grail.

here you have my code snippet

import React, { useEffect } from "react";
import { DataTable, Flex, convertToColumns } from "@dynatrace/strato-components-preview";
import { problemsClient } from "@dynatrace-sdk/client-classic-environment-v2";
import { useDqlQuery } from "@dynatrace-sdk/react-hooks";


export const Home = () => {
  const query = `fetch events, from:now()-60d
  | filter event.kind == "DAVIS_PROBLEM"
  | filter display_id == "P-2309107"
  | summarize {problem=takeMax(record(timestamp,resolved_problem_duration,event.end,event.start,dt.davis.is_duplicate,event.status,maintenance.is_under_maintenance,dt.davis.is_frequent_event)) }, by:{display_id}
  | fieldsFlatten problem
  | filter problem.event.status == "CLOSED"
  | filter problem.dt.davis.is_frequent_event == false and problem.dt.davis.is_duplicate == false and problem.maintenance.is_under_maintenance == false
  | fields display_id, problem.event.start, problem.event.end`;

  const resp = useDqlQuery({
    body: {
      query: query,
    },
  });

  useEffect(() => {
    if (resp.data !== undefined) {
      console.log(resp.data.records);
    }
  }, [resp]);

  useEffect(() => {
    const config: Object = {
      "problemSelector": "displayId(P-2309107)",
      "from": "-60d",
      "to": "now"
    };

    problemsClient.getProblems(config).then((problems) => {

      for (var sv of problems.problems) {
        console.log(new Date(sv.startTime), new Date(sv.endTime));
      }
    });
  }, []);


  return (
    <Flex flexDirection="column" >
      {resp.data && resp.data.records && <DataTable columns={convertToColumns(resp.data.types)} data={resp.data.records} fullWidth />}
    </Flex>
  );
};

 

You can use that snippet if you connect to https://wkf10640.apps.dynatrace.com/ - that is the Discover Dynatrace environment and every user has access to that.

sinisa_zubic_0-1697302027136.png

 

Please let me know if  you still have problems after checking out my snippet.

 

Best,
Sini

Thank for response. I used the example as a tuned down example I received as an example for problem inquiry.

I used your code as is in a new notebook and received the following:

derija_0-1697751880257.png

Note sure why.. thanks in advance.

Went to the playground created new notebook and pasted your code in and ran code with same error

derija_0-1697815817496.png

 

derija_1-1697815838236.png

 

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

I did not know that you want to do this in notebooks. The code snippet I have shared with you works within a Dynatrace custom app

If you want to see the duration of a problem, you can use this dql query:

fetch events, from:now()-90d
  | filter event.kind == "DAVIS_PROBLEM"
  | filter display_id == "P-2309241"
  | summarize {problem=takeMax(record(timestamp,resolved_problem_duration,event.end,event.start,dt.davis.is_duplicate,event.status,maintenance.is_under_maintenance,dt.davis.is_frequent_event)) }, by:{display_id}
  | fieldsFlatten problem
  | filter problem.event.status == "CLOSED"
  | filter problem.dt.davis.is_frequent_event == false and problem.dt.davis.is_duplicate == false and problem.maintenance.is_under_maintenance == false
  | fields display_id, problem.event.start, problem.event.end, duration=problem.event.end - problem.event.start

 

Here you see the example problem.

 

sinisa_zubic_0-1698931834143.png

sinisa_zubic_1-1698931862198.png

 

for more examples on how to use DQL and Davis problems, please check out following help page: https://docs.dynatrace.com/docs/platform/davis-ai/davis-dql-examples

 

Best,
Sini

Featured Posts