【问题标题】:With new relic's http api, how do you turn off uptime monitoring?使用new relic的http api,如何关闭正常运行时间监控?
【发布时间】:2014-01-13 17:54:01
【问题描述】:

我正在尝试使用 curl 关闭正常运行时间监控,按照此处的新遗物文档中给出的说明:https://docs.newrelic.com/docs/alerts/availability-monitor-settings

根据本文档,此请求将禁用我的正常运行时间监控:

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

这是我正在使用的请求(已删除个人信息): curl "https://api.newrelic.com/api/v1/accounts/NNNNNN/applications/NNNNNNN/ping_targets/disable" -X POST -H "X-Api-Key:x...x"

我已成功将我的 acct_id、app_id 和 x-api-key 用于其他 GET 命令。但是,当我尝试上述命令时,出现此错误:

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

根据此堆栈交换帖子:Turn Newrelic monitoring on or off via rest api 没有办法做到这一点,但这与文档冲突。

那么,有没有办法做到这一点?有没有人成功做到这一点?

【问题讨论】:

    标签: curl heroku newrelic


    【解决方案1】:

    假设“正常运行时间监控”是指可用性监控,这必须通过禁用控制监控的策略来完成。这可以通过使用类似这样的命令来确定策略 ID 号来找到

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

    如果策略名称包含空格,请替换为“+”。

    从输出中找到 POLICY_ID

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

    还可以通过扫描输出中的“可用性”来识别条件 ID,并记下 ID 号。

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

    现在使用生成的 POLICY_ID 和 CONDITON_ID 禁用策略。

    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
           }]
        }
     }' 
    

    请注意,一旦确定了 POLICY_ID 和 CONDITION_ID,就只需要最后一个命令。

    【讨论】:

    • 你是完全正确的。该文档适用于 api 版本 1,而我的实例使用版本 2。经过进一步研究,我在这里发现了更好的文档:rpm.newrelic.com/api/explore,您必须在右上角选择您的应用程序才能在此处查看警报策略选项:@987654322 @
    • 非常感谢您的回答,它帮助我开始使用 V2。
    猜你喜欢
    • 2012-09-12
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    相关资源
    最近更新 更多