如何使用 NerdGraph API 在 NewRelic 中创建警报策略工作流程

问题描述 投票:0回答:1

我正在尝试以编程方式创建 NewRelic 工作流程,我知道我需要三件事。

  • 目的地
  • 频道
  • 工作流程。

所以我开始创建一个目的地。

mutation CreateDestination {
  aiNotificationsCreateDestination(
    accountId: {{ accountId }}
    destination: {
      auth: {type: BASIC}, 
      name: "{{ name }}", 
      properties: {key: "url", value: "{{ url }}"}, 
      type: WEBHOOK
    }
  ) {
    destination {
      id
      name
      properties {
        displayValue
        label
      }
      guid
      active
    }
    error {
      ... on AiNotificationsConstraintsError {
        constraints {
          dependencies
        }
      }
      ... on AiNotificationsDataValidationError {
        details
      }
      ... on AiNotificationsResponseError {
        description
      }
    }
  }
}

然后我尝试创建一个频道..

mutation {
  aiNotificationsCreateChannel(
    accountId: {{ account_id }}
    channel: {
      destinationId: "{{ destination_id }}", 
      name: "{{ channel_name }}", 
      product: ALERTS, 
      properties: {
        displayValue: null, 
        key: "payload", 
        label: null, 
        value: """{{ properties_value }}""",
      }, 
      type: WEBHOOK
    }
  ) {
    channel {
      accountId
      active
      createdAt
      destinationId
      id
      name
      product
      properties {
        displayValue
        key
        label
        value
      }
    }
    error {
      ... on AiNotificationsConstraintsError {
        constraints {
          dependencies
          name
        }
      }
      ... on AiNotificationsResponseError {
        description
        details
        type
      }
      ... on AiNotificationsDataValidationError {
        details
        fields {
          field
          message
        }
      }
    }
  }
}

当我尝试使用它来创建工作流程时,我在响应中获得了一个 ID。

mutation {
    aiWorkflowsCreateWorkflow(
        accountId: {{ account_id }}
        createWorkflowData: {
            destinationConfigurations: [
                {% for channel in destination_configurations %}
                {
                    channelId: "{{ channel.channelId }}",
                    notificationTriggers: [{{ channel.notificationTriggers | join(', ') }}],
                    updateOriginalMessage: {{ channel.updateOriginalMessage | lower }}
                }{% if not loop.last %},{% endif %}
                {% endfor %}
            ],
            name: "{{ workflow_name }}",
            workflowEnabled: true,
            mutingRulesHandling: DONT_NOTIFY_FULLY_MUTED_ISSUES,
            issuesFilter: {
                name: "{{ issues_filter_name }}",
                predicates: {
                    attribute:  "labels.policyIds",
                    operator: EXACTLY_MATCHES
                    values: [ " {{ issues_filter_values }}" ]
                },
                type: FILTER
            },
            destinationsEnabled: true
        }
    ) {
    workflow {
      id
      name
      destinationConfigurations {
        channelId
        notificationTriggers
        updateOriginalMessage
        name
      }
      workflowEnabled
      mutingRulesHandling
      issuesFilter {
        name
        predicates {
          attribute
          operator
          values
        }
        type
      }
      destinationsEnabled
      guid
    }
    errors {
      description
      type
    }
  }
}

我收到以下错误。

{
  "data": {
    "aiWorkflowsCreateWorkflow": {
      "errors": [
        {
          "description": "A channel with id XXXXXXXXXXXX was not found",
          "type": "INVALID_PARAMETER"
        }
      ],
      "workflow": null
    }
  }
}

我尝试创建一个非aiCreateChannel,但这也是错误的。

graphql newrelic newrelic-platform newrelic-synthetics
1个回答
0
投票

产品 - 如果您想在工作流程中使用通道,请使用 INIT 而不是 ALERT

© www.soinside.com 2019 - 2024. All rights reserved.