cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post

How can I call pingdom api delete maintenance?

Hello,

I try to use an API to delete maintenance set on monitors, at the end of my technical operation.

I read the following documentation: https://docs.pingdom.com/api/#tag/Maintenance/paths/~1maintenance~1{id}/delete

And this helped me to write the following SHELL script

now_epoch=$(date +%s)
for maintid in ${maintenanceids}; do
  echo -e "0-Working on ${maintid}"
  curl -X GET -sS -H "Authorization: Bearer ${PINGDOM_TOKEN}" \
    "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -er '.'
  maintenance_end=0
  filter_description="${TENANT} muted by script"
  maintenance_end=$(curl -X GET -sS -H "Authorization: Bearer ${PINGDOM_TOKEN}" \
    "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -er --arg F_DESCRIPTION "${filter_description}" '.maintenance | select (.description == $F_DESCRIPTION) | .to')
  echo -e "1-Maintenance_end ::${maintenance_end}:: now_epoch ::${now_epoch}::"
  if [[ "${maintenance_end}" -gt "${now_epoch}" ]]; then
    echo -e "\t 2-CAN BE STOPPED"
    echo -e "\t\t 3-GET https://api.pingdom.com/api/3.1/maintenance/${maintid}"
    curl -X -sS GET -H "Authorization: Bearer ${PINGDOM_TOKEN}" \
      "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -r '.'
    echo -e "\t\t 4-DELETE https://api.pingdom.com/api/3.1/maintenance/${maintid}"
    curl -X DELETE -H "Authorization: Bearer ${PINGDOM_TOKEN}" \
      "https://api.pingdom.com/api/3.1/maintenance/${maintid}" | jq -r '.'
  else
    echo -e "\t ---NO NEED TO STOP MAINTENANCE"
  fi
done

 

Yet, my DELETE maintenance API call ends with a 404 error. 

Here is the script output, in case I find a maintenance that I need to delete:

0-Working on 159819
{
  "maintenance": {
    "id": 159819,
    "description": "xxxxx muted by script",
    "from": 1602858337,
    "to": 1602858636,
    "duration": 4,
    "durationunit": "minute",
    "recurrencetype": "none",
    "repeatevery": 0,
    "dayofweekinmonth": 0,
    "effectiveto": 1602858636,
    "checks": {
      "uptime": [
        6352482,
        6352483,
        6352484
      ],
      "tms": []
    }
  }
}
1-Maintenance_end ::1602858636:: now_epoch ::1602858350::
	 2-CAN BE STOPPED
		 3-GET https://api.pingdom.com/api/3.1/maintenance/159819
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   291  100   291    0     0   1961      0 --:--:-- --:--:-- --:--:--  1966
{
  "maintenance": {
    "id": 159819,
    "description": "xxxxx muted by script",
    "from": 1602858337,
    "to": 1602858636,
    "duration": 4,
    "durationunit": "minute",
    "recurrencetype": "none",
    "repeatevery": 0,
    "dayofweekinmonth": 0,
    "effectiveto": 1602858636,
    "checks": {
      "uptime": [
        6352482,
        6352483,
        6352484
      ],
      "tms": []
    }
  }
}
		 4-DELETE https://api.pingdom.com/api/3.1/maintenance/159819
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   106  100   106    0     0    731      0 --:--:-- --:--:-- --:--:--   736
{
  "error": {
    "statuscode": 404,
    "statusdesc": "Not Found",
    "errormessage": "Please specify a valid API resource"
  }
}

Can you tell me how to invoque properly this API?

 

Thanks in advance,

Thomas

2 Replies

I tried to call the API putting the maintenance ID between brace symbols, the documentation page display braces between the ID:

 

'https://api.pingdom.com/api/3.1/maintenance/{1234}'

But I still get the same error message. 

0 Kudos

I found a workaround terminating the maintenance thanks to the following CURL command:

      echo -e "\t\t 4bis-CHANGE end timestamp https://api.pingdom.com/api/3.1/maintenance/${maintid}"
      curl -X PUT -sS -H "Authorization: Bearer ${PINGDOM_TOKEN}" \
        "https://api.pingdom.com/api/3.1/maintenance/${maintid}" \
        --data-urlencode "to=1" \
        --data-urlencode "description=$TENANT muted by script--shortened" | jq -r '.'

 

Inspiring from the following code:

https://github.com/russellcardullo/go-pingdom/blob/master/pingdom/maintenance.go#L136

https://github.com/russellcardullo/go-pingdom/blob/master/pingdom/pingdom.go#L73

I found that their request in order to delete a maintenance is performed in a very similar way than my CURL command. I also tried to perform a multiple maintenance DELETE, but it failed, the feedback from CURL was:

 

{
  "message": "0 maintenance windows successfully deleted."
}

 

Any advice/info welcomed!

0 Kudos