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

I want to add a loop task to enable/disable host monitoring using workflows

Frequent Guest

Hi team,

I want to use loop task for a list of hosts to enable or disable monitoring in Dynatrace. I would like to have multiple hosts to be executed with single workflow for http_request.


"externalId": "string",
"schemaId": "builtin:host.monitoring",
"scope": "HOST-7AA30C2D50D93E12",
"value": {
"enabled": false




Dynatrace Champion
Dynatrace Champion

Hi @Smalhotra89 


Yes this is possible with the loop task. Before you start you need to generate an "Access Token" with the scopes "Read settings" and "Write settings". 

Then you can start creating the workflow. First you need to fetch all settings objects for the list of hosts you want to disable or enable with a http request task. The list of hosts is put in the URL and is comma separated. In the header section you add the Autorization details, please have a look at following screenshot


in the subsequent http request task you need to configure the loop task like this


The input for the tasks should be that



For this approach you have to create the token and manage it yourself. 


But you could also do the same thing with a javascript task with custom javascript code, the benefit there would be that you don't need to create a token for changing the settings. Since the used sdks underneath managed this for you.

this is the snippet for the javascript task

// optional import of sdk modules
import { execution } from '@dynatrace-sdk/automation-utils';
import { actionExecution } from "@dynatrace-sdk/automation-utils";

import { SettingsObject, settingsObjectsClient } from "@dynatrace-sdk/client-classic-environment-v2";

export default async function ({ execution_id, action_execution_id }) {
  // your code goes here
  // e.g. get the current execution
  const ex = await execution(execution_id);
  const actionEx = await actionExecution(action_execution_id);
  const scopes = actionEx.loopItem["host"];
  const settingsObjects = await settingsObjectsClient.getSettingsObjects({
      schemaIds: "builtin:host.monitoring",
      fields: "objectId,value,summary,searchSummary,created,modifid,createdBy,modifiedBy,author,updateToken,scope,modificationInfo,schemaId,schemaVersion,externalId"
  if (settingsObjects.items.length > 0){
    const settingsObject = (settingsObjects.items[0]);
    const settingsObjectResponse = await settingsObjectsClient.putSettingsObjectByObjectId({
        objectId: settingsObject.objectId,
        body: {
          updateToken: settingsObject.updateToken,
          value: {
            "enabled": false
    return { settingsObjectResponse };









Frequent Guest

Thanks Sini, javascript task works well.

I was unable to use the http request with loop task as it was unable to read allobjects.json.item in loop. I am not sure if I did something wrong but the first task to get all objects task ran through fine.

Featured Posts