10 Jul 2024 01:52 PM - last edited on 12 Jul 2024 02:38 PM by MaciejNeumann
Hello dear community, I turn to your infinite wisdom for guidance. I have some Kubernetes clusters in a QA environment that are turned off every night and turned on the next day. I have Dynatrace installed on these clusters, but I generally use it on-demand. The problem occurs every morning when the clusters are turned on, they come up with a new name and this causes the configuration I left the day before (turning off One-agent monitoring) to be lost and One-agent to start in ON mode.
Is it possible or is there any configuration in the One-agent installation that starts in OFF monitoring mode?
I appreciate your help.
Solved! Go to Solution.
10 Jul 2024 02:04 PM
We have developed an extension 2.0 which allows you to define profiles and sets one agent modes accordingly to the profile for new connected OneAgents. If you are interested, reach out to me here in the thread.
With Kubernetes it also depends on your deployment mode.
This can be also accomplished by workflows - if you are on SaaS.
10 Jul 2024 02:58 PM
We are currently using the DPS and SaaS model. The installation was done with HELM and with the dynakube.yaml file that Dynatrace suggests in its installation guide. Is it not possible to set monitoring=off in dynakube.yaml or something similar to make it start up turned off?
11 Jul 2024 03:02 PM
No, oneagents (either full stack or pass) cannot be started deactivated. You can always deactivate and reactivate them using Settings API. That's exactly what we are doing with the extension.
12 Jul 2024 05:13 PM
Thank you for your help. How can I enable or disable monitoring with OneAgent on Kubernetes using the extension you mentioned?
Thank you very much
10 Sep 2024 07:28 AM
@Ellery our extension allows you to configure newly connected OneAgents and disable them or switch the monitoring mode according to the defined rules, I think the screenshot says it all.
15 Jul 2024 11:15 PM
Hi @Ellery
I understand your problem, however I think it can be solved by configuring the Process Group, Services Name rules, Container rules, Host naming 💪.
My best recommendation is that you evaluate those rules and your problem could be solved 😄
I hope its help 💪
09 Sep 2024 12:50 PM
I found the solution in a workflow, and using JavaScript, we search for each monitored host, filter them based on the pattern we need, and then shut them down. Here's the code.
var https://{environmentid}.live.dynatrace.com/api/v2/";
//const request = require('request');
const schemaIds = "builtin:host.monitoring"
var api_token_entities = "<token TOKEN READ WRITTE ENTITIES>";
var api_token = "<TOKEN ONEAGENT - READ - WRITTE>";
// Step 1: Get all Object Ids for HOST schema
const options = {
method: 'GET',
headers: {
'Authorization': `Api-Token ${api_token}`
}
};
const disable_host_group = ["qa-xxxxxx", "qa-yyyyyyy", "qa-ddddddd", "qa-sssssssss"]
https://{environmentid}.live.dynatrace.com/api/v1/oneagents`, options, (response) => {
let data = '';
response.on('data', (chunk) => {
data += chunk;
});
response.on('end', () => {
const hostObjects = JSON.parse(data);
if ("error" in hostObjects) {
console.log(`Error occurred: ${hostObjects.error.message}`);
process.exit(1);
}
const hosts = hostObjects["hosts"]
Object.keys(hosts).forEach(key => {
var cluster = hosts[key]["hostInfo"]["kubernetesCluster"];
var estado = hosts[key]["availabilityState"];
var entityID = hosts[key]["hostInfo"]["entityId"];
try {
var hostgroupID = hosts[key]["hostInfo"]["hostGroup"]["meId"];
} catch (error) {
var hostgroupID = "nulo";
}
try {
var hostGroup = hosts[key]["hostInfo"]["hostGroup"]["name"];
} catch (error) {
var hostGroup = "nulo";
}
if(disable_host_group.includes(hostGroup)) {
if(estado == "MONITORED"){
console.log(key + " " + entityID + " ---> " + cluster + " ---> " + estado + " ---> " + hostgroupID + " ---> " + hostGroup );
update(entityID);
}
}
});
});
}).on("error", (error) => {
console.error(`Error: ${error.message}`);
});
// Configura las opciones para la solicitud
function update(host) {
console.log("inicio actualizacion : " + host)
const options_update = {
hostname: '<tenantdyantrace>.live.dynatrace.com',
port: 443,
path: '/api/v2/settings/objects/?scope='+host,
method: 'POST',
headers: {
'Accept': 'application/json; charset=utf-8',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': `Api-Token ${api_token_entities}`
}
};
// make the petition
const req_update = https.request(options_update, (res) => {
let data1 = '';
// Reception the data
res.on('data1', (chunk) => {
data1 += chunk;
});
// when the answere end, process data
res.on('end', () => {
//console.info('Response:', data1);
});
});
// error management
req_update.on('error', (e) => {
console.error('Error:', e.message);
});
// send data
const postData = JSON.stringify([{
"schemaId": "builtin:host.monitoring",
"scope": host,
"value": { "enabled": false }
}]);
req_update.write(postData);
req_update.end();
console.log("update end: " + host)
}
i hope this solution can help somebody