Shivangi Singh
Shivangi Singh

Reputation: 1139

How to create a workflow for Alert Policy in NewRelic using NerdGraph API

I am trying to programatically create NewRelic workflows, I know I need three things.

So I started with creating a destination.

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

Then I tried creating a channel..

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

I get an id in the response and when I try to use this to create a workflow.

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

I get the following error.

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

I tried creating a non-aiCreateChannel but that is also wrong.

Upvotes: 0

Views: 46

Answers (1)

Shivangi Singh
Shivangi Singh

Reputation: 1139

product - INIT instead of ALERT if you want to use the channel in workflows

Upvotes: 0

Related Questions