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

DQL query not working to pull out data from the settings

Danielm
Frequent Guest

I have this code which i will paste below as a comment but its not working correctly as it should. I opened a chat with Dynatrace who have said to paste the request into here . Essentially I am pulling data from the settings and checking that if a certain field contains, for example this app id "APP10001", then return true. I have two scenarios where this is working but I feel if I get one fixed then the other should follow suit. I have checked my settings and i should be getting a true return, but I'm not getting that here.


// Fifth part - IDs from Dashboards

nextPageKey = undefined;
do {
const params = nextPageKey ? { nextPageKey: nextPageKey } : {
schemaIds: "builtin:dashboards.general",
fields: "summary",
}
const res = await settingsObjectsClient.getSettingsObjects(params);
nextPageKey = res.nextPageKey;
if (res.items) {
res.items.forEach(item => {
let appId;
const nameMatch = /(APP\d{5})/.exec(item.summary ?? "");
if (nameMatch && nameMatch.length > 1) {
appId = nameMatch[1];
}
if (appId && snowAppIDs.includes(appId)) {
idsFromDashboard.push(appId);
}
})
}
} while (nextPageKey);

// Fifth part - IDs from SLO

nextPageKey = undefined;
do {
const params = nextPageKey ? { nextPageKey: nextPageKey } : {
schemaIds: "builtin:monitoring.slo",
fields: "summary",
}
const res = await settingsObjectsClient.getSettingsObjects(params);
nextPageKey = res.nextPageKey;
if (res.items) {
res.items.forEach(item => {
let appId;
const nameMatch = /(APP\d{5})/.exec(item.summary ?? "");
if (nameMatch && nameMatch.length > 1) {
appId = nameMatch[1];
}
if (appId && snowAppIDs.includes(appId)) {
idsFromSLO.push({
appId: appId,
});
}
})
}
} while (nextPageKey);





9 REPLIES 9

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

Hi @Danielm 

 

Just to summarize if I fully understand what you want to achieve here. You have some dashboards configured and want to check if a dashboard with a certain title exist?

If so, then the schema id builtin:dashboards.general is definetively not the correct one. With that schema id you are querying the settings of following screen:

sinisa_zubic_2-1700490334551.png

I have browsed through all the settings schemas and wasn't able to find any schema which would represent a dashboard configuration. Therefore, I have reached out internally to check if we are exposing the dashboard configuration via API. Will let you know as soon as I get a response.

Best,
Sini

 

Danielm_0-1700581804250.png

I have added the following dashboard in here and if this were to work i would then add more of the dashboards for this to check?

Im assuming by having the app id in this title it should be able to pick this up and bring back a 'true' value. But for some reason this isnt working.

Im doing the exact same thing for the SLO's which should be bringing back 'true' values also but with no luck

The assumption is wrong. For each item on that settings page we store only the "UserGroup" and "Dashboard" ids in the values. Because you configure for which user group which dashboard to be loaded as default on the landing page. You can easily check in swagger what is being returned when using the API. the SDK is just a wrapper for the API and settingsObjectsClient.getSettingsObjects maps to GET /settings/objects API

swagger.png

 

The way to go here is via the configuration API. Unfortunately that API is not directly exposed to AppEngine and there are no SDKs available for it. You can use the GET all dashboards API call by calling it via the standard fetch() api . You need to create a token with the "Read configuration" scope and pass it as header when doing the call. Also that URL needs to be allow listed in Settings -> preferences -> limit outbound connections.

Then the question regarding "token security" pops up. You don't want others to use that token. For that, please check out the guide about secrets management.

 

Best,

Sini

Can I ask how I go about presenting this information on my dashboard after this?

Also I am pulling out data regarding the management zones, alerting profiles and problem notifications using the same/ similar dql query and it is working fine so im not sure why trying to pull out the SLO and where i have sorted the dashboard info on that dashboard.general settings page shouldnt work.

I have attached my dashboard in the attachment below. I downloaded it as a json and converted it into a txt file as i couldnt upload as json.

Hi Sini,

I have added in the appropriate url into the limit outbound connections. But im now not getting any records in the fetch call.

Danielm_0-1701187078069.png

Danielm_1-1701187229340.png

 

Would you know if i have done anything wrong here or could you help in anyway?

you need to put the code into a function and have a return. please have a look at the sample

 

export default async function (payload: unknown = undefined) {
  const resp = await fetch(
    `https:/<environment>/api/config/v1/dashboards`,
    {
      headers: {
        Authorization:
          "Api-Token <>",
      },
    }
  );
  const json = await resp.json();
  const filter = json.dashboards.filter((dashboard) =>
    dashboard.name.toUpperCase().includes("KUBERNETES")
  );
  console.log(filter);
  return filter;
}

 

sinisa_zubic_0-1701281408700.png

 

Hi Sini,

 

This has worked perfectly for me.


I have added this into my code on my dashboard to try and use the results of this against another list and pull back whether the id exists in both the lists or it doesnt in the form of a green light , red light scenario. Im getting an error when i try to run the code and was wondering if you could help with it.

 

I have attached the code below with the environment id removed from the fetch and the api token, if you need i could provide this.

LawrenceBarratt
Dynatrace Advisor
Dynatrace Advisor

Hi Daniel.

As Sinisa mentioned the APIs are different. The SDK works for the Settings in V2 that is scoped, but the dashboards is within our config API which is not in the SDK parameters here

I want to ask, why the need for Dashboards in the Quality Gates Overview? But something I can add as to Sinisa suggestion above. SLOs should be fine as they are coming from Settings API.

See another iteration of this pulling more info such as Web Apps, Mobile, Synthetics etc

LawrenceBarratt_0-1700735572372.png

Hi Lawrence,

Thanks for this reply. I understand why the dashboards cant be picked up now. We are trying to track which management zones have dashboards created for them. So if we have an application, does that application have a dashboard to showcase the metrics etc being monitored.

My SLO dql still isnt working to pull out the slo's which have the app id in the name to bring back a true if you could have a look?

Maybe you could paste the dql which is pulling in the slo's from above which i could tweak and use ?

Thanks,

Daniel

Featured Posts