24 Jun 2024 07:26 AM - edited 26 Jun 2024 07:27 AM
Hello Guys,
I am using workflows to disable/enable host monitoring as specific timeframe. It works pretty well if I only use the javascript and add the Host ids in the loop as below:
// 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,Tags,used_for"
});
//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 };
}
}
But my scenario is now if I want to use the above method to loop on tags instead of Host ids, I created one DQL task to extract the ids for the tagged host as below and applied the above jscript task followed by get tagged host and loop on the result records and I get the error:
fetch dt.entity.host
| fields id, entity.name, tags
| filter contains(toString(tags), "used_for:non_prod")
| fields id
An error of type UNCAUGHT_EXCEPTION occurred in an imported library: 404: Scope '[object Object]' not found
at SettingsObjectsClient.getSettingsObjects (file:///opt/sdk_modules/@dynatrace-sdk/client-classic-environment-v2/esm/index.js:28691:19)
at eventLoopTick (ext:core/01_core.js:169:7)
at async default (file:///script.ts:14:27)
========================================
An error of type UNCAUGHT_EXCEPTION occurred in an imported library: 404: Scope '[object Object]' not found
at SettingsObjectsClient.getSettingsObjects (file:///opt/sdk_modules/@dynatrace-sdk/client-classic-environment-v2/esm/index.js:28691:19)
at eventLoopTick (ext:core/01_core.js:169:7)
at async default (file:///script.ts:14:27)
So I tried to use the same DQL query and used an HTTP workflow to try it out with the API call, when I use that with url and authorization token, I get below error:
Payload:
[{
"schemaId":"builtin:host.monitoring",
"schemaVersion":"1.4",
"scope": "{{_.host }}" ,
"value":
{"enabled":true}
}
]
Loop
Error:
[ERROR] {"error":{"code":404,"message":"Scope '{'id': 'HOST-5E****'}' not found"}}
[ERROR] Error: Response has status code 404 which indicates an error.
========================================
[ERROR] {"error":{"code":404,"message":"Scope '{'id': 'HOST-7A2****'}' not found"}}
[ERROR] Error: Response has status code 404 which indicates an error.
If anyone can please help me in identifying where am I going wrong and how can I make it working using any method jscript or http.
Thanks