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"];
//console.log(scopes);
const settingsObjects = await settingsObjectsClient.getSettingsObjects({
schemaIds: "builtin:host.monitoring",
scopes,
fields: "objectId,value,summary,searchSummary,created,modifid,createdBy,modifiedBy,author,updateToken,scope,modificationInfo,schemaId,schemaVersion,externalId"
});
//console.log(settingsObjects);
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 };
}
}
Best,
Sini