<?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: Extracting hostname via JS in Automations</title>
    <link>https://community.dynatrace.com/t5/Automations/Extracting-hostname-via-JS/m-p/276800#M2147</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/90188"&gt;@Dyno193&lt;/a&gt;,&amp;nbsp;If the requirement is to get the hostnames from the environment, then u can get it from the notebook, with the query,&lt;/P&gt;&lt;P&gt;fetch dt.entity.host&lt;BR /&gt;| fields entity.name&lt;/P&gt;&lt;P&gt;Or if any automation then u can use this code to get the entity name and add ur condition on top of it.&lt;/P&gt;&lt;P&gt;export default async function ({ executionId }) {&lt;BR /&gt;try {&lt;BR /&gt;const query = `&lt;BR /&gt;fetch dt.entity.host&lt;BR /&gt;| fields entity.name`;&lt;BR /&gt;&lt;BR /&gt;const queryResponse = await queryExecutionClient.queryExecute({ body: { query } });&lt;/P&gt;&lt;P&gt;if (queryResponse.requestToken) {&lt;BR /&gt;const pollQuery = async (requestToken) =&amp;gt; {&lt;BR /&gt;let pollResponse;&lt;BR /&gt;do {&lt;BR /&gt;pollResponse = await queryExecutionClient.queryPoll({ requestToken });&lt;BR /&gt;if (pollResponse.state === 'RUNNING') {&lt;BR /&gt;await new Promise((resolve) =&amp;gt; setTimeout(resolve, 1000));&lt;BR /&gt;}&lt;BR /&gt;} while (pollResponse.state === 'RUNNING');&lt;BR /&gt;return pollResponse;&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;const finalResponse = await pollQuery(queryResponse.requestToken);&lt;BR /&gt;console.log(finalResponse.result.records);&lt;BR /&gt;}&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error(`Dynatrace API Error:`, error);&lt;BR /&gt;return { error: error.message };&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Fri, 09 May 2025 07:22:51 GMT</pubDate>
    <dc:creator>AravindhanV</dc:creator>
    <dc:date>2025-05-09T07:22:51Z</dc:date>
    <item>
      <title>Extracting hostname via JS</title>
      <link>https://community.dynatrace.com/t5/Automations/Extracting-hostname-via-JS/m-p/276784#M2146</link>
      <description>&lt;P&gt;Struggling to extract hostname via JS, can someone look at this - I keep getting Constratins Violated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try {&lt;BR /&gt;// Use entitySelector that just gets all HOSTS&lt;BR /&gt;console.log(`Searching for all hosts first...`);&lt;BR /&gt;const allHostsResponse = await monitoredEntitiesClient.getEntities({&lt;BR /&gt;entitySelector: `type("HOST")`,&lt;BR /&gt;fields: '+properties.monitoringState'&lt;BR /&gt;});&lt;BR /&gt;&lt;BR /&gt;console.log(`Found ${allHostsResponse.totalCount} hosts in total`);&lt;BR /&gt;&lt;BR /&gt;// Manually filter for the hostname&lt;BR /&gt;const matchedHosts = allHostsResponse.entities.filter(entity =&amp;gt;&lt;BR /&gt;entity.displayName === hostname ||&lt;BR /&gt;entity.entityId.includes(hostname.toUpperCase())&lt;BR /&gt;);&lt;BR /&gt;&lt;BR /&gt;if (matchedHosts.length === 0) {&lt;BR /&gt;console.warn(`Host ${hostname} not found in Dynatrace environment`);&lt;BR /&gt;results.push({&lt;BR /&gt;hostname,&lt;BR /&gt;status: "error",&lt;BR /&gt;message: "Host not found in Dynatrace environment"&lt;BR /&gt;});&lt;BR /&gt;continue;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Snippet of Code&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 20:49:10 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Extracting-hostname-via-JS/m-p/276784#M2146</guid>
      <dc:creator>Dyno193</dc:creator>
      <dc:date>2025-05-08T20:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting hostname via JS</title>
      <link>https://community.dynatrace.com/t5/Automations/Extracting-hostname-via-JS/m-p/276800#M2147</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/90188"&gt;@Dyno193&lt;/a&gt;,&amp;nbsp;If the requirement is to get the hostnames from the environment, then u can get it from the notebook, with the query,&lt;/P&gt;&lt;P&gt;fetch dt.entity.host&lt;BR /&gt;| fields entity.name&lt;/P&gt;&lt;P&gt;Or if any automation then u can use this code to get the entity name and add ur condition on top of it.&lt;/P&gt;&lt;P&gt;export default async function ({ executionId }) {&lt;BR /&gt;try {&lt;BR /&gt;const query = `&lt;BR /&gt;fetch dt.entity.host&lt;BR /&gt;| fields entity.name`;&lt;BR /&gt;&lt;BR /&gt;const queryResponse = await queryExecutionClient.queryExecute({ body: { query } });&lt;/P&gt;&lt;P&gt;if (queryResponse.requestToken) {&lt;BR /&gt;const pollQuery = async (requestToken) =&amp;gt; {&lt;BR /&gt;let pollResponse;&lt;BR /&gt;do {&lt;BR /&gt;pollResponse = await queryExecutionClient.queryPoll({ requestToken });&lt;BR /&gt;if (pollResponse.state === 'RUNNING') {&lt;BR /&gt;await new Promise((resolve) =&amp;gt; setTimeout(resolve, 1000));&lt;BR /&gt;}&lt;BR /&gt;} while (pollResponse.state === 'RUNNING');&lt;BR /&gt;return pollResponse;&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;const finalResponse = await pollQuery(queryResponse.requestToken);&lt;BR /&gt;console.log(finalResponse.result.records);&lt;BR /&gt;}&lt;BR /&gt;} catch (error) {&lt;BR /&gt;console.error(`Dynatrace API Error:`, error);&lt;BR /&gt;return { error: error.message };&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 07:22:51 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Extracting-hostname-via-JS/m-p/276800#M2147</guid>
      <dc:creator>AravindhanV</dc:creator>
      <dc:date>2025-05-09T07:22:51Z</dc:date>
    </item>
  </channel>
</rss>

