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

Error HTTP Error 540: Unknown when using Javascript code to get external data


Hello everyone, everything good ?

I'd like to see if anyone has explored creating javascript code for external data in the new Dynatrace Dashboards.

We are working on indicators in our Selfmon environment that is consuming data from our Managed cluster and we would like to display the sum of oneagents connected to each of our ActiveGates, but I suspect that Dynatrace does not support the "reduce()" function.

The error "HTTP Error 540: Unknown" is occurring and no details of the reason for the error are displayed (improvement point for this new interface).

Below code example:

export default async function() {
const environment = 'https://{Endpoint Example}'
const token = 'Token example';
const params = '/api/v2/activeGates?versionCompareType=EQUAL&enabledModule=ONE_AGENT_ROUTING';

const uri = environment + params;
const response = await fetch(uri, {
headers: {
Accept: "application/json",
Authorization: "Api-Token " + token

const result = await response.json();
const HostnamesAndOneagents = => ({
ConnectedOneagents: parseInt(activeGate.connectedHosts.number)

const sumOneagents = HostnamesAndOneagents.reduce((sum, activeGate) => sum + activeGate.connectedHosts.number, 0);

return sumOneagents;

Thanks for your help if anyone can make a similar code work to add the values of the array activeGates.connectedHosts.number !


Dynatrace Champion
Dynatrace Champion

Hi @MarcioKaue 

The reduce() function is supported. I don't fully understand what you want to achieve with your code snippet. Do you want maybe display all ActiveGate with the number of connected hosts and their sum?

If so, this is the code snippet (with using reduce) 

export default async function () {
  const environment =
  const token =
  const params =

  const uri = environment + params;
  const response = await fetch(uri, {
    headers: {
      Accept: "application/json",
      Authorization: "Api-Token " + token,

  const result = await response.json();

  const sumOneagents = result.activeGates.reduce(
    (sum, activeGate) => sum + parseInt(activeGate.connectedHosts.number),

  const HostnamesAndOneagents = [ => ({
      hostname: activeGate.hostname,
      ConnectedOneagents: parseInt(activeGate.connectedHosts.number),
      hostname: "sum",
      ConnectedOneagents: sumOneagents,

  return HostnamesAndOneagents;


For troubleshooting code snippets in dashboards and notebooks you could use the console.log functionality. The logs can be found in the options side panel





Hello @sinisa_zubic !

Thanks for the help, I had managed to perform the sum through the use of for and let. Anyway thank you very much for directing with the console.log() for the purposes of analysis.

Featured Posts