14 Oct 2023 12:26 AM
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:
UI shows correct values:
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?
Solved! Go to Solution.
14 Oct 2023 05:47 PM
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.
Please let me know if you still have problems after checking out my snippet.
Best,
Sini
19 Oct 2023 10:45 PM
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:
Note sure why.. thanks in advance.
20 Oct 2023 04:30 PM
Went to the playground created new notebook and pasted your code in and ran code with same error
02 Nov 2023 01:33 PM
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.
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