<?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: Is it possible to create a Workflow to call Dynatrace Objects API? in Automations</title>
    <link>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/228063#M25</link>
    <description>&lt;P&gt;I completely missed the native option that runs http requests into workflow &lt;img class="lia-deferred-image lia-image-emoji" src="https://community.dynatrace.com/html/@F2D1C2F7F4E2482D3B1CB233C93F9C13/images/emoticons/facepalm.gif" alt=":facepalm:" title=":facepalm:" /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-11-08 143936.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/15264i34E42749442E48B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-11-08 143936.png" alt="Screenshot 2023-11-08 143936.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Javascript code is required to run batch executions, but in my case, it was simple run in two hosts only.&lt;/P&gt;&lt;P&gt;Anyway, I learned, and I am happy. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2023 17:41:05 GMT</pubDate>
    <dc:creator>dannemca</dc:creator>
    <dc:date>2023-11-08T17:41:05Z</dc:date>
    <item>
      <title>Is it possible to create a Workflow to call Dynatrace Objects API?</title>
      <link>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/226994#M22</link>
      <description>&lt;P&gt;Hi team, good day.&lt;/P&gt;
&lt;P&gt;The idea is to create a Workflow to disable CPU monitoring for some hosts in a crontab way (we do downsize some machines for $aving purpose) to avoid unneeded alerts/problems, since the Maintenance Window does not allow us to suppres a specific event type, &lt;A href="https://community.dynatrace.com/t5/Product-ideas/Maintenance-windows-by-event-type/idi-p/206889" target="_self"&gt;yet&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I know I can call a Workflow in a &lt;A href="https://docs.dynatrace.com/docs/platform-modules/cloud-automation/workflows/schedules#fixed-time" target="_self"&gt;crontab way&lt;/A&gt;, what I don't know is how to properly call the api/v2/settings/objects API as a task. I was expecting something we have for &lt;A href="https://developer.dynatrace.com/develop/data/ingest-data/" target="_self"&gt;ingest data&lt;/A&gt;, for example.&lt;/P&gt;
&lt;P&gt;Any clue/help on this?&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 10:11:44 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/226994#M22</guid>
      <dc:creator>dannemca</dc:creator>
      <dc:date>2023-11-09T10:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a Workflow to call Dynatrace Objects API?</title>
      <link>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/227666#M23</link>
      <description>&lt;P&gt;A possible suggestion is creating two Workflows, one where you disable monitoring and one where you enable it based on your schedule, both with the same JavaScript task but different payloads for the PUT call.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Following is some basic JavaScript code that could be used in the workflow; just meant as a starting point; it needs both `settings.read` and `settings.write` scopes for the access token&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const https://{environmentid}.live.dynatrace.com/api/v2/";
const api_token = "dt0c01.XXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Step 1: Get all Object Ids for HOST schema
const options = {
  method: 'GET',
  headers: {
    'Authorization': `Api-Token ${api_token}`
  }
};

https.get(`${base_url}settings/objects?schemaIds=builtin:host.monitoring&amp;amp;fields=objectId,value,scope`, options, (response) =&amp;gt; {
  let data = '';

  response.on('data', (chunk) =&amp;gt; {
    data += chunk;
  });

  response.on('end', () =&amp;gt; {
    const hostObjects = JSON.parse(data);
    if ("error" in hostObjects) {
      console.log(`Error occurred: ${hostObjects.error.message}`);
      process.exit(1);
    }

    // Extracting host IDs and object IDs from the response
    const hostIds = hostObjects.items.map(item =&amp;gt; item.scope);
    const objectIds = hostObjects.items.map(item =&amp;gt; item.objectId);

    // Step 2: Modify monitoring settings for all hosts
    const payload = {
      value: {
        enabled: true, // or false
        autoInjection: true // or false
      }
    };

    hostIds.forEach(hostId =&amp;gt; {
      const objectId = objectIds[hostIds.indexOf(hostId)];
      const requestOptions = {
        method: 'PUT',
        headers: {
          'Authorization': `Api-Token ${api_token}`,
          'Content-Type': 'application/json'
        }
      };

      const req = https.request(`${base_url}settings/objects/${objectId}`, requestOptions, (res) =&amp;gt; {
        let responseData = '';
        res.on('data', (chunk) =&amp;gt; {
          responseData += chunk;
        });

        res.on('end', () =&amp;gt; {
          if (res.statusCode === 200) {
            console.log(`Modified monitoring settings for host ID: ${hostId} (Object ID: ${objectId})`);
          } else {
            console.log(`Failed to modify monitoring settings for host ID: ${hostId} (Object ID: ${objectId})`);
          }
        });
      });

      req.write(JSON.stringify(payload));
      req.end();
    });
  });

}).on("error", (error) =&amp;gt; {
  console.error(`Error: ${error.message}`);
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 22:11:53 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/227666#M23</guid>
      <dc:creator>rkdy</dc:creator>
      <dc:date>2023-11-03T22:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a Workflow to call Dynatrace Objects API?</title>
      <link>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/227905#M24</link>
      <description>&lt;P&gt;Thanks, &lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/54274"&gt;@rkdy&lt;/a&gt; , it was really helpful.&lt;/P&gt;&lt;P&gt;That's the final javascript code for the purpose I need, to disable the CPU monitoring for a specific host only:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var https = require('https');

const base_url = "https://myenv.live.dynatrace.com/api/v2/";
const api_token = "dt0c01.XXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Step 1: Get all Object Ids for HOST schema
const options = {
  method: 'GET',
  headers: {
    'Authorization': `Api-Token ${api_token}`
  }
};

https.get(`${base_url}settings/objects?pageSize=500&amp;amp;scopes=HOST-XXXXXXXXXXXXXXX&amp;amp;schemaIds=builtin:anomaly-detection.infrastructure-hosts&amp;amp;fields=objectId,value,scope`, options, (response) =&amp;gt; {
  let data = '';

  response.on('data', (chunk) =&amp;gt; {
    data += chunk;
  });

  response.on('end', () =&amp;gt; {
    const hostObjects = JSON.parse(data);
    if ("error" in hostObjects) {
      console.log(`Error occurred: ${hostObjects.error.message}`);
      process.exit(1);
    }

    // Extracting host IDs and object IDs from the response
    const hostIds = hostObjects.items.map(item =&amp;gt; item.scope);
    const objectIds = hostObjects.items.map(item =&amp;gt; item.objectId);

    // Step 2: Modify monitoring settings for all hosts
    const payload = {
		value: {
                "host": {
                    "connectionLostDetection": {
                        "enabled": true,
                        "onGracefulShutdowns": "DONT_ALERT_ON_GRACEFUL_SHUTDOWN"
                    },
                    "highCpuSaturationDetection": {
                        "enabled": false
                    },
                    "highSystemLoadDetection": {
                        "enabled": false
                    },
                    "highMemoryDetection": {
                        "enabled": true,
                        "detectionMode": "auto"
                    },
                    "highGcActivityDetection": {
                        "enabled": true,
                        "detectionMode": "auto"
                    },
                    "outOfMemoryDetection": {
                        "enabled": true,
                        "detectionMode": "auto"
                    },
                    "outOfThreadsDetection": {
                        "enabled": true,
                        "detectionMode": "auto"
                    }
                },
                "network": {
                    "networkDroppedPacketsDetection": {
                        "enabled": true,
                        "detectionMode": "auto"
                    },
                    "networkErrorsDetection": {
                        "enabled": true,
                        "detectionMode": "auto"
                    },
                    "highNetworkDetection": {
                        "enabled": false
                    },
                    "networkTcpProblemsDetection": {
                        "enabled": false
                    },
                    "networkHighRetransmissionDetection": {
                        "enabled": false
                    }
                }
            }
    };

    hostIds.forEach(hostId =&amp;gt; {
      const objectId = objectIds[hostIds.indexOf(hostId)];
      const requestOptions = {
        method: 'PUT',
        headers: {
          'Authorization': `Api-Token ${api_token}`,
          'Content-Type': 'application/json'
        }
      };

      const req = https.request(`${base_url}settings/objects/${objectId}`, requestOptions, (res) =&amp;gt; {
        let responseData = '';
        res.on('data', (chunk) =&amp;gt; {
          responseData += chunk;
        });

        res.on('end', () =&amp;gt; {
          if (res.statusCode === 200) {
            console.log(`Modified monitoring settings for host ID: ${hostId} (Object ID: ${objectId})`);
          } else {
            console.log(`Failed to modify monitoring settings for host ID: ${hostId} (Object ID: ${objectId})`);
          }
        });
      });

      req.write(JSON.stringify(payload));
      req.end();
    });
  });

}).on("error", (error) =&amp;gt; {
  console.error(`Error: ${error.message}`);
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 15:07:13 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/227905#M24</guid>
      <dc:creator>dannemca</dc:creator>
      <dc:date>2023-11-07T15:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a Workflow to call Dynatrace Objects API?</title>
      <link>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/228063#M25</link>
      <description>&lt;P&gt;I completely missed the native option that runs http requests into workflow &lt;img class="lia-deferred-image lia-image-emoji" src="https://community.dynatrace.com/html/@F2D1C2F7F4E2482D3B1CB233C93F9C13/images/emoticons/facepalm.gif" alt=":facepalm:" title=":facepalm:" /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-11-08 143936.png" style="width: 999px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/15264i34E42749442E48B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-11-08 143936.png" alt="Screenshot 2023-11-08 143936.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Javascript code is required to run batch executions, but in my case, it was simple run in two hosts only.&lt;/P&gt;&lt;P&gt;Anyway, I learned, and I am happy. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 17:41:05 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/228063#M25</guid>
      <dc:creator>dannemca</dc:creator>
      <dc:date>2023-11-08T17:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to create a Workflow to call Dynatrace Objects API?</title>
      <link>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/228335#M26</link>
      <description>&lt;P&gt;That was an oversite on my end, too &lt;img class="lia-deferred-image lia-image-emoji" src="https://community.dynatrace.com/html/@1C781DEA9875E929062D0A5367C7E39A/images/emoticons/facepalm-pickard.png" alt=":facepalm_pickard:" title=":facepalm_pickard:" /&gt;; one improvement if you were to have gone down the route of using JavaScript for future reference would be to use the SDK for Typescript -&amp;nbsp;&lt;A href="https://developer.dynatrace.com/reference/sdks/" target="_blank"&gt;SDK for TypeScript | Dynatrace Developer&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 22:09:05 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Automations/Is-it-possible-to-create-a-Workflow-to-call-Dynatrace-Objects/m-p/228335#M26</guid>
      <dc:creator>rkdy</dc:creator>
      <dc:date>2023-11-09T22:09:05Z</dc:date>
    </item>
  </channel>
</rss>

