Search code examples
curlherokunewrelic

With new relic's http api, how do you turn off uptime monitoring?


I am attempting to turn off uptime monitoring, using curl, per the instructions given in new relics documentation here: https://docs.newrelic.com/docs/alerts/availability-monitor-settings

According to this documentation, this request will disable my uptime monitoring:

curl https://www.myhost.com/accounts/acct_id/applications/app_id/ping_targets/disable -X POST -H "X-Api-Key: "my_key"

Here is the request that I am using (stripped of personal info): curl "https://api.newrelic.com/api/v1/accounts/NNNNNN/applications/NNNNNNN/ping_targets/disable" -X POST -H "X-Api-Key:x...x"

I have used my acct_id, app_id, and x-api-key successfully for other GET commands. However when I attempt the above command I get this error:

<hash>
  <error>The requested page could not be found</error>
</hash>

According to this stack exchange post: Turn Newrelic monitoring on or off via rest api there is not a way to do this, but that conflicts with the documentation.

So, is there a way to accomplish this? Has anyone successfully done this?


Solution

  • Assuming that "uptime monitoring" refers to Availability Monitoring, this must be accomplished by disabling the policy that controls the monitoring. This can be found by using a command like this to determine the policy id number

    curl -X GET 'https://api.newrelic.com/v2/alert_policies.xml' -gH "X-Api-Key:<APIKEY>" -i -d 'filter[name]=<POLICY_NAME>' 
    

    If the policy name contains spaces, substitute with '+'.

    From the output, locate the POLICY_ID

    <alert_policies_response>
      <alert_policies>
        <alert_policy>
          <id>104446</id>    <----<<<< POLICY_ID
          <type>application</type>
          <name><POLICY_NAME></name>
          .....
    

    Also identify the condition id by scanning the output for 'availability' and note the ID number.

       <condition>
         <id>997294</id>   <----<<<<   CONDITION_ID
         <type>application_availability</type>
         <severity>downtime</severity>
         ....
    

    Now use the resultant POLICY_ID and CONDITON_ID to disable the policy.

    curl -X PUT 'https://api.newrelic.com/v2/alert_policies/<POLICY_ID>.json' \
         -H 'X-Api-Key:<APIKEY>' -i \
         -H 'Content-Type: application/json' \
         -d \
    '{
      "alert_policy": 
        {
        "conditions": [
           {
             "id": <CONDITION_ID>,
             "enabled": false
           }]
        }
     }' 
    

    Note that once the POLICY_ID and CONDITION_ID are determined, only the last command is required.