# Start OneAgent in off mode

**URL:** <https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534>\
**Category:** Open Q&A\
**Tags:** installation, oneagent\
**Created:** [July 10, 2024, 12:52pm UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534 "2024-07-10T12:52:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ellery](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@Ellery](https://community.dynatrace.com/u/Ellery)\
**Post date:** [July 10, 2024, 12:52pm UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/1 "2024-07-10T12:52:35Z")

</div>

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.

 ![Ellery_0-1720615782713.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/0/906a2e78a82034d0c5cf60ba8bd038cd37ba33bb.png)

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 10, 2024, 1:04pm UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/2 "2024-07-10T13:04:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ellery](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@Ellery](https://community.dynatrace.com/u/Ellery)\
**Post date:** [July 10, 2024, 1:58pm UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/3 "2024-07-10T13:58:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [July 11, 2024, 2:02pm UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/4 "2024-07-11T14:02:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ellery](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@Ellery](https://community.dynatrace.com/u/Ellery)\
**Post date:** [July 12, 2024, 4:13pm UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/5 "2024-07-12T16:13:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PierreGutierrez](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/pierregutierrez/32/5934_2.png) [@PierreGutierrez](https://community.dynatrace.com/u/PierreGutierrez)\
**Post date:** [July 15, 2024, 10:15pm UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/6 "2024-07-15T22:15:14Z")

</div>

Hi&nbsp;[@Ellery](https://community.dynatrace.com/user/65321)

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 💪

---

<div class="post-metadata">

**Author:** ![Ellery](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@Ellery](https://community.dynatrace.com/u/Ellery)\
**Post date:** [September 9, 2024, 11:50am UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/7 "2024-09-09T11:50:58Z")

</div>

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.

```markup
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

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [September 10, 2024, 6:28am UTC](https://community.dynatrace.com/t/start-oneagent-in-off-mode/46534/8 "2024-09-10T06:28:01Z")

</div>

[@Ellery](https://community.dynatrace.com/user/65321)&nbsp;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.

 ![Julius_Loman_0-1725949566153.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/c/bcadded63bbd01552c61993ffe94cf5977252398.png)
