<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error HTTP Error 540: Unknown when using Javascript code to get external data in Developer Q&amp;A Forum</title>
    <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Error-HTTP-Error-540-Unknown-when-using-Javascript-code-to-get/m-p/217501#M386</link>
    <description>&lt;P&gt;Hello &lt;A class="" href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/38283" target="_self"&gt;&lt;SPAN class=""&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/38283"&gt;@sinisa_zubic&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/A&gt;!&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2023 12:28:59 GMT</pubDate>
    <dc:creator>MarcioKaue</dc:creator>
    <dc:date>2023-07-11T12:28:59Z</dc:date>
    <item>
      <title>Error HTTP Error 540: Unknown when using Javascript code to get external data</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Error-HTTP-Error-540-Unknown-when-using-Javascript-code-to-get/m-p/217393#M384</link>
      <description>&lt;P&gt;Hello everyone, everything good ?&lt;/P&gt;
&lt;P&gt;I'd like to see if anyone has explored creating javascript code for external data in the new Dynatrace Dashboards.&lt;/P&gt;
&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;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).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Below code example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;export default async function() {&lt;BR /&gt;const environment = 'https://{Endpoint Example}'&lt;BR /&gt;const token = 'Token example';&lt;BR /&gt;const params = '/api/v2/activeGates?versionCompareType=EQUAL&amp;amp;enabledModule=ONE_AGENT_ROUTING';&lt;/P&gt;
&lt;P&gt;const uri = environment + params;&lt;BR /&gt;const response = await fetch(uri, {&lt;BR /&gt;headers: {&lt;BR /&gt;Accept: "application/json",&lt;BR /&gt;Authorization: "Api-Token " + token&lt;BR /&gt;}});&lt;/P&gt;
&lt;P&gt;const result = await response.json();&lt;BR /&gt;const HostnamesAndOneagents = result.activeGates.map(activeGate =&amp;gt; ({&lt;BR /&gt;ConnectedOneagents: parseInt(activeGate.connectedHosts.number)&lt;BR /&gt;}));&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;const sumOneagents = HostnamesAndOneagents.reduce((sum, activeGate) =&amp;gt; sum + activeGate.connectedHosts.number, 0);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;return sumOneagents;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;Thanks for your help if anyone can make a similar code work to add the values of the array activeGates.connectedHosts.number !&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 09:22:35 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Error-HTTP-Error-540-Unknown-when-using-Javascript-code-to-get/m-p/217393#M384</guid>
      <dc:creator>MarcioKaue</dc:creator>
      <dc:date>2023-07-11T09:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Error HTTP Error 540: Unknown when using Javascript code to get external data</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Error-HTTP-Error-540-Unknown-when-using-Javascript-code-to-get/m-p/217463#M385</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/55571"&gt;@MarcioKaue&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;If so, this is the code snippet (with using reduce)&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;export default async function () {
  const environment =
    "{environment-link";
  const token =
    "dt0c01.{token}";
  const params =
    "/api/v2/activeGates?versionCompareType=EQUAL&amp;amp;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();

  console.log(result);
  const sumOneagents = result.activeGates.reduce(
    (sum, activeGate) =&amp;gt; sum + parseInt(activeGate.connectedHosts.number),
    0
  );

  const HostnamesAndOneagents = [
    ...result.activeGates.map((activeGate) =&amp;gt; ({
      hostname: activeGate.hostname,
      ConnectedOneagents: parseInt(activeGate.connectedHosts.number),
    })),
    {
      hostname: "sum",
      ConnectedOneagents: sumOneagents,
    },
  ];

  return HostnamesAndOneagents;
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sinisa_zubic_0-1689067268119.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/12765iB4E61F320B7545A7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sinisa_zubic_0-1689067268119.png" alt="sinisa_zubic_0-1689067268119.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Sini&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 09:21:38 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Error-HTTP-Error-540-Unknown-when-using-Javascript-code-to-get/m-p/217463#M385</guid>
      <dc:creator>sinisa_zubic</dc:creator>
      <dc:date>2023-07-11T09:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Error HTTP Error 540: Unknown when using Javascript code to get external data</title>
      <link>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Error-HTTP-Error-540-Unknown-when-using-Javascript-code-to-get/m-p/217501#M386</link>
      <description>&lt;P&gt;Hello &lt;A class="" href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/38283" target="_self"&gt;&lt;SPAN class=""&gt;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/38283"&gt;@sinisa_zubic&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/A&gt;!&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 12:28:59 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Developer-Q-A-Forum/Error-HTTP-Error-540-Unknown-when-using-Javascript-code-to-get/m-p/217501#M386</guid>
      <dc:creator>MarcioKaue</dc:creator>
      <dc:date>2023-07-11T12:28:59Z</dc:date>
    </item>
  </channel>
</rss>

