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

On-demand Schedule to Enable/Disable the Host Monitoring

Babar_Qayyum
DynaMight Guru
DynaMight Guru

Dears,

Do we have a way to schedule the on-demand enabling/disabling monitoring of the host?

I read the below news, there are many API options, but I could not find the schedule option.

https://www.dynatrace.com/news/blog/manage-thousands-of-hosts-with-the-new-oneagent-on-a-host-rest-a...

Regards,

Babar

14 REPLIES 14

ChadTurner
DynaMight Legend
DynaMight Legend

I dont think you can schedule it within the API, but you could use an application like Jenkins or Postman to create a playlist where at a scheduled time, the application of choice would trigger an api call thus enabling or disabling a Dynatrace Oneagent on a host or set of hosts.

-Chad

Hello @Chad T.

Thank you for sharing the alternatives. In the lighter node, I would like to share my experience with the customers, that mostly they do not like to ask them for other tools to fulfill the basic requirements, which can be provided by the main vendor very easily. Especially when they do not have the requested tools already in their environment.

Regards,

Babar

AntonioSousa
DynaMight Guru
DynaMight Guru

Yes, we also do it in some cases, as Chad has noted, especially with HU/hours.

The relevant API call we use, along simple crontab configurations, is the Configuration API, "OneAgent on a host", as seen below:

Antonio Sousa

Hello @Antonio S.

Yes. I had gone through with these configurations API, but what I am looking to provide the scheduled time e.g. host monitoring will be turned off from 1:00 AM to 4:00 AM etc.

If you do not mind, please share the crontab configurations. Also, how to use the crontab configurations?

Regards,

Babar

On my side, I do it this way:

  1. In /etc/crontab, I have two entries as following. It's quite simple in Linux and if not known, just check online for crontab. At every hour, startHosts.sh is run, and inside the script it checks for the hour, and "cases" which hour it is, and does the relevant job of starting the required Hosts. At every 58 minute in the hour, it checks which Hosts should be stopped., and stops them. The 1-5 states that I'm only starting/stopping the agents Monday-Friday, as I they are stopped during the weekend:
    00 * * * 1-5 nnnnnnnnnn cd /home/nnnnnnnnnn/APIdyna && ./startHosts.sh
    58 * * * 1-5 nnnnnnnnnn cd /home/nnnnnnnnnn/APIdyna && ./stopHosts.sh
  2. For starting the agents, all you need to do is execute something like the curl command below. Replace the host and Api-Token. For stopping, you have to change monitoringEnabled to false:
    curl -v -X PUT "https://xxxxxxxxx.live.dynatrace.com/api/config/v1/hosts/HOST-B243D963FE5E32A9/monitoring" -H "accept: */*" -H "Authorization: Api-Token yyyyyyyyyyyyy" -H "Content-Type: application/json; charset=utf-8" -d "{\"monitoringEnabled\":true,\"monitoringMode\":\"FULL_STACK\"}"

I have this running in the context of controlling the consumption of HU/hours. Please beware that some additional features might be required. I have not had those issues, but one improvement I'll be doing in the near future is confirming if effectively the change was implemented.

Antonio Sousa

Hello @Antonio S.

Thank you for the details.

Point # 1:

  • Where it will be configured (/etc/crontab)?
  • Will the below commands star/stop hosts or disable monitoring?

00 * * * 1-5 nnnnnnnnnn cd /home/nnnnnnnnnn/APIdyna && ./startHosts.sh
58 * * * 1-5 nnnnnnnnnn cd /home/nnnnnnnnnn/APIdyna && ./stopHosts.sh

Point # 2:

  • Do you mean reenabling/disabling the host monitoring with curl command instead of the UI?

Regards,

Babar

Regarding Point #1,

  • I do the configuration in /etc/crontab, but depending on the Linux distribution, you may have other ways.
  • startHosts.sh and stopHosts.sh are shell scripts we developed and that include curl commands like the one I posted above. The command that effectively start/stop host monitoring is the curl command.
  • nnnnnnnnnn is the Linux user name, and typically the user owns directory /home/nnnnnnnnnn, where the scripts might be located.

Regarding Point #2, it seems clear to me now that I didn't express myself like I should. The curl command has to be put inside the shell script as stated in the two points above. The curl that starts has to be in the script that starts, and the one that stops, in the stopping script. Hope it's clearer now 😉

Antonio Sousa

Hello @Antonio S.

Once again thank you for your kind explanation.

One more clarification required for the /etc/crontab configuration. Will this done on the Dynatrace Cluster Nodes/ or the monitoring hosts?

Regards,

Babar

You can do this in any Linux machine that can connect to the API endpoints of your environments, be it Managed or SaaS. In our case, we do it on AG machines.

Antonio Sousa

Hello @Antonio S.

Thank you for the clarification of one more point. With this flexibility, we can use whether the AG or one of the cluster nodes.

I will test in the UAT environment and will come back to you in case of any challenge.

Regards,

Babar

Hi @AntonioSousa 

Thanks for sharing this idea,

Very helpful.

 

In some cases (some Technologies) processes need to be restarted after OFF/ON of the monitoring, what you are doing for the same?

 

With this case, you will save HU consumption? or which kind of license you keep?

 

 

Thanks.

Sharing Knowledge

When we stop, the servers are stopped. When they start, we haven't had problems with starting the process, as it already comes instrumented. We are using this because we are really stopping the servers.

If this is used for controlling licensing with hosts that keep on running, you probably need to consider restarting those processes. But am not absolutely sure about it.

Antonio Sousa

CTull
Contributor

After disable\enable do the processes need restarting?  If so wouldn't an entry in the hosts file to send that traffic to 127.0.0.1?  So that it cannot communicate to SAAS.?  There is scripting to rem\unrem a comment in the hosts file and manage that by a batch file and use the windows scheduler.  Similar with Linux using different processes.  

AntonPineiro
DynaMight Guru
DynaMight Guru

Hi,

API V1 is not deprecated:

AntonPineiro_0-1709552670105.png

Are you using API V2 for same purpuse? I would like to confirm if we can disable OneAgent vía API actually.

Thank you!

Best regards

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

Featured Posts