New Relicアラートの場合、NerdGraphAPIを使用してアラート通知チャネルを管理できます。適用されたインテリジェンス通知を管理する方法については、宛先に関するNerdGraphチュートリアルを参照してください。
ヒント
NerdGraphの使用を開始する方法については、NerdGraphの概要を参照してください。
通知チャンネルの取得
notificationChannels
クエリを使用すると、アカウントごとにすべてのアラート通知チャネルをページ分割できます。notificationChannel
クエリを使用して、IDで特定の通知チャネルを取得することもできます。
ヒント
なお、特定のシークレットフィールド(例えば、パスワードやAPIキー)は、返されたフィールドの中で難読化されます。
この例では、指定されたアカウントIDのすべての通知チャネルのすべてのフィールドをページ制限200まで返します。インラインフラグメントを使用して、 AlertsNotificationChannel
インターフェイスを実装する具象型の特定のフィールドを参照する方法に注意してください。
account(id: YOUR_ACCOUNT_ID) {
... on AlertsXMattersNotificationChannel {
... on AlertsWebhookNotificationChannel {
... on AlertsVictorOpsNotificationChannel {
... on AlertsUserNotificationChannel {
... on AlertsSlackNotificationChannel {
... on AlertsPagerDutyNotificationChannel {
... on AlertsOpsGenieNotificationChannel {
... on AlertsHipChatNotificationChannel {
... on AlertsEmailNotificationChannel {
... on AlertsCampfireNotificationChannel {
特定のアカウントの通知チャンネルのリストが200チャンネルのページ制限を超える場合、ページネーションカーソルを使って追加ページを取得することができます。
カーソルページネーションを使用すると、応答でそのフィールドが空になるまで、 nextCursor
を使用して追加のページを要求し続けます。空のnextCursor
は、結果セットの最後に到達したことを示します。
次の例を見てみましょう。
account(id: YOUR_ACCOUNT_ID) {
上のコードは、次のような結果のセットを返します。
"notificationChannels": {
"nextCursor": "Wh4LK9JYzfACVlNkyvf7Rg==:I5VbSEpgx3UWNA5AOVsUPv4=",
次のリクエストでは、このようにカーソルを提供し、カーソルが空になるまで、後続の各リクエストを更新して、更新されたカーソルを返します。
account(id: YOUR_ACCOUNT_ID) {
cursor: "Wh4LK9JYzfACVlNkyvf7Rg==:I5VbSEpgx3UWNA5AOVsUPv4="
特定の通知チャネルのIDがある場合、APIを使用するとそれを直接検索できます。特定のチャネルはAlertsNotificationChannel
インターフェイスを実装する具象型であるため、インラインフラグメントの... on
構文を使用して特定のフィールドを指定する必要がある場合があることに注意してください。
この例では、Slackのチャンネルを取得しています。
account(id: YOUR_ACCOUNT_ID) {
notificationChannel(id: YOUR_CHANNEL_ID) {
... on AlertsSlackNotificationChannel {
この例では、指定されたアカウントID上のすべての通知チャネルのID、名前、タイプと、そのチャネルに関連付けられているすべてのポリシーのリストを返します。
account(id: YOUR_ACCOUNT_ID) {
通知チャンネルの作成
アラート通知チャネルを作成するには、作成する通知チャネルの特定の種類 (電子メール、Slack など) と、その構成に必要な詳細 (チャネルによって異なります) を把握する必要があります。タイプ)。通知チャネルを作成したら、1 つ以上の アラート ポリシーに関連付けることができます。関連付けられると、条件が違反されたときに、これらのチャネルはポリシーから通知を受け取ります。
注意
既存の通知チャネルタイプを照会することはできますが、作成できるのはそのサブセットのみです。具体的には、 user チャンネルタイプには編集可能なフィールドがなく、 Campfire と HipChat チャンネルタイプはどちらも非推奨です。
メール通知チャンネルのミューテーション作成例。
alertsNotificationChannelCreate(
accountId: YOUR_ACCOUNT_ID
emails: ["email@example.com"]
name: "Some Name <email@example.com>"
... on AlertsEmailNotificationChannel {
OpsGenie通知チャネルのcreate mutationの例です。
alertsNotificationChannelCreate(
accountId: YOUR_ACCOUNT_ID
apiKey: "api-key-from-opsgenie"
name: "OpsGenie notification channel name"
recipients: ["user@example.com"]
teams: ["team1", "team2"]
... on AlertsOpsGenieNotificationChannel {
PagerDutyの通知チャンネルのcreate mutationの例です。
alertsNotificationChannelCreate(
accountId: YOUR_ACCOUNT_ID
name: "PagerDuty notification channel name"
apiKey: "api-key-from-pagerduty"
... on AlertsPagerDutyNotificationChannel {
Slackの通知チャンネルのcreate mutationの例です。
alertsNotificationChannelCreate(
accountId: YOUR_ACCOUNT_ID
name: "Slack notification channel name"
teamChannel: "#team-channel"
url: "https://hooks.slack.com/services/FAKE/MOREFAKE/IMAGINARYEXAMPLEURLCHUNK"
... on AlertsSlackNotificationChannel {
VictorOpsの通知チャンネルのcreate mutationの例です。
alertsNotificationChannelCreate(
accountId: YOUR_ACCOUNT_ID
key: "example-api-key-from-victorops"
name: "VictorOps notification channel name"
routeKey: "example-route-key"
... on AlertsVictorOpsNotificationChannel {
Webhook通知チャンネルのcreate mutationの例です。
alertsNotificationChannelCreate(
accountId: YOUR_ACCOUNT_ID
baseUrl: "https://example.com/webhook"
password: "t0t4lly-s3cr3t-p455w0rd"
{ name: "X-Api-Key", value: "100%-real-api-key" }
{ name: "X-Calling-Service", value: "New Relic Alerts" }
customPayloadBody: "{ \"account_id\": \"$ACCOUNT_ID\", \"account_name\": \"$ACCOUNT_NAME\", \"closed_violations_count_critical\": \"$CLOSED_VIOLATIONS_COUNT_CRITICAL\", \"closed_violations_count_warning\": \"$CLOSED_VIOLATIONS_COUNT_WARNING\", \"condition_description\": \"$DESCRIPTION\", \"condition_family_id\": \"$CONDITION_FAMILY_ID\", \"condition_name\": \"$CONDITION_NAME\", \"current_state\": \"$EVENT_STATE\", \"details\": \"$EVENT_DETAILS\", \"duration\": \"$DURATION\", \"event_type\": \"$EVENT_TYPE\", \"incident_acknowledge_url\": \"$INCIDENT_ACKNOWLEDGE_URL\", \"incident_id\": \"$INCIDENT_ID\", \"incident_url\": \"$INCIDENT_URL\", \"metadata\": \"$METADATA\", \"open_violations_count_critical\": \"$OPEN_VIOLATIONS_COUNT_CRITICAL\", \"open_violations_count_warning\": \"$OPEN_VIOLATIONS_COUNT_WARNING\", \"owner\": \"$EVENT_OWNER\", \"policy_name\": \"$POLICY_NAME\", \"policy_url\": \"$POLICY_URL\", \"runbook_url\": \"$RUNBOOK_URL\", \"severity\": \"$SEVERITY\", \"targets\": \"$TARGETS\", \"timestamp\": \"$TIMESTAMP\", \"timestamp_utc_string\": \"$TIMESTAMP_UTC_STRING\", \"violation_callback_url\": \"$VIOLATION_CALLBACK_URL\", \"violation_chart_url\": \"$VIOLATION_CHART_URL\" }"
name: "Webhook notification channel name"
... on AlertsWebhookNotificationChannel {
xMattersの通知チャネルのクリエイトミューテーションの例です。
alertsNotificationChannelCreate(
accountId: YOUR_ACCOUNT_ID
integrationUrl: "https://company.instance.xmatters.com/api/xm/v<version>/..."
name: "xMatters notification channel name"
... on AlertsXMattersNotificationChannel {
通知チャンネルの更新
アラート通知チャネルを更新するためには、変更したい通知チャネルの具体的なタイプ(たとえばメール、Slackなど)と、その設定に必要な詳細(チャネルのタイプによって異なります)を知っておく必要があります。他のGraphQL APIと同様に、チャネルのID以外の情報を知らなくても、チャネルの単一フィールドを更新することができます。
注意
既存の通知チャネルタイプを照会することはできますが、更新できるのはそのうちのサブセットのみです。具体的には、 user チャンネルタイプには編集可能なフィールドがなく、 Campfire と HipChat チャンネルタイプはどちらも非推奨です。
名前だけを更新するメール通知チャンネルの更新ミューテーションの例です。
alertsNotificationChannelUpdate(
accountId: YOUR_ACCOUNT_ID
notificationChannel: { email: { name: "Updated Name <email@example.com>" } }
... on AlertsEmailNotificationChannel {
名前のみを更新するOpsGenie通知チャネルのアップデート・ミューテーションの例です。
alertsNotificationChannelUpdate(
accountId: YOUR_ACCOUNT_ID
notificationChannel: { opsGenie: { name: "OpsGenie updated channel name" } }
... on AlertsOpsGenieNotificationChannel {
PagerDutyの通知チャンネルで名前だけを更新する場合の更新ミューテーションの例です。
alertsNotificationChannelUpdate(
accountId: YOUR_ACCOUNT_ID
pagerDuty: { name: "PagerDuty updated channel name" }
... on AlertsPagerDutyNotificationChannel {
Slackの通知チャンネルで名前だけを更新する場合の更新変異の例です。
alertsNotificationChannelUpdate(
accountId: YOUR_ACCOUNT_ID
notificationChannel: { slack: { name: "Slack updated channel name" } }
... on AlertsSlackNotificationChannel {
VictorOpsの通知チャンネルで、名前だけを更新する場合の更新変異の例です。
alertsNotificationChannelUpdate(
accountId: YOUR_ACCOUNT_ID
victorOps: { name: "VictorOps updated channel name" }
... on AlertsVictorOpsNotificationChannel {
名前だけを更新するWebhook通知チャンネルの更新ミューテーションの例です。
alertsNotificationChannelUpdate(
accountId: YOUR_ACCOUNT_ID
notificationChannel: { webhook: { name: "Webhook updated channel name" } }
... on AlertsWebhookNotificationChannel {
xMattersの通知チャンネルで名前だけを更新する場合の更新ミューテーションの例です。
alertsNotificationChannelUpdate(
accountId: YOUR_ACCOUNT_ID
notificationChannel: { xMatters: { name: "xMatters updated channel name" } }
... on AlertsXMattersNotificationChannel {
通知チャンネルの削除
通知チャネルの削除は、アカウントIDとチャネルIDのみで可能です。チャネルを削除すると、すべてのポリシーから切り離され、そのチャネルには今後通知が送られなくなることに注意してください。
alertsNotificationChannelDelete(
accountId: YOUR_ACCOUNT_ID
チャンネルをポリシーに関連付ける
アラート通知チャネルを作成するだけでは十分ではありません。チャネルを作成したら、それを 1 つ以上の ポリシーに関連付ける必要があります。ポリシーに関連付けられると、チャネルは、そのポリシーの条件がしきい値を超えたときにアラート通知を受信できるようになります。
この例では、2つのチャンネルと1つのポリシーを関連付けます。
alertsNotificationChannelsAddToPolicy(
accountId: YOUR_ACCOUNT_ID
notificationChannelIds: [FIRST_CHANNEL_ID, SECOND_CHANNEL_ID]
チャンネルとポリシーの分離
通知チャネルが耐用年数を過ぎた場合 (たとえば、引退した電子メールリストなど)、そのチャネルを、アラート通知を送信している ポリシー (またはポリシー) から切り離す必要が出てきました。この API コールは、チャネル自体はそのまま残しますが、指定されたポリシーからは削除します。
この例では、ポリシーから2つのチャンネルを削除し(他のチャンネルはそのまま)、その2つのチャンネルIDが削除されたことを確認しています。
alertsNotificationChannelsRemoveFromPolicy(
accountId: YOUR_ACCOUNT_ID
notificationChannelIds: [FIRST_CHANNEL_ID, SECOND_CHANNEL_ID]
ヒント
ポリシー からアラート通知チャネルを削除しても、他のポリシーで使用されている可能性があるため、 チャネルは削除されません。一方で、チャネルを削除すると、関連するすべてのポリシーがそのチャネルへのアラート通知の送信を停止します。