[Quick Hint] Suspend VM monitoring in Patrol with REST call

There are situations when your workflow will have to restart a VM. This post shows a way to disable VM monitoring in Patrol using a simple REST call. This way your monitoring team will not get a false positive alarm and you will avoid unnecessary emails 😉

Disable VM Monitoring:

/***
Inputs: 
  vmName <String> - Hostname
  sleepTime <Number>  - Monitoring suspend time in sec
***/
//https://<patrolweb>/eadmin/suppress_host_bem.pl?host=<hostname>&until_ts=<time_in_sec>&action = add

System.debug("Supend VM Monitoring...");
var operationUrl = "/eadmin/suppress_host_bem.pl?host={vmName}&until_ts={sleepTime}&action=add";
operationUrl = operationUrl.replace("{vmName}", vmName);
operationUrl = operationUrl.replace("{sleepTime}", sleepTime);

request = patrol.createRequest("GET", operationUrl);
request.setHeader("Content-Type", "application/json");
var response = request.execute();
if(response.statusCode > 399){
	throw 'Error: ' + response.contentAsString;
} 
else {
	System.log(response.contentAsString);
}

Once you are done with all VM operations and restarts you can enable monitoring again.

Enable VM Monitoring:

/***
Inputs: 
  vmName <String> - Hostname
***/
//https://<patrolweb>/eadmin/suppress_host_bem.pl?host=<hostname>&action=delete

System.debug("Unsupend Monitoring...");
var operationUrl = "/eadmin/suppress_host_bem.pl?host={vmName}&action=delete";
operationUrl = operationUrl.replace("{vmName}", vmName);

request = patrol.createRequest("GET", operationUrl);
request.setHeader("Content-Type", "application/json");
var response = request.execute();
if(response.statusCode > 399){
	throw 'Error: ' + response.contentAsString;
} 
else {
	System.log(response.contentAsString);
}