View a markdown version of this page

Memanggil DevOps Agen melalui Webhook - AWS DevOps Agen

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Memanggil DevOps Agen melalui Webhook

Webhook memungkinkan sistem eksternal untuk secara otomatis memicu investigasi AWS DevOps Agen. Ini memungkinkan integrasi dengan sistem tiket, alat pemantauan, dan platform lain yang dapat mengirim permintaan HTTP ketika insiden terjadi.

Prasyarat

Sebelum mengonfigurasi akses webhook, pastikan Anda memiliki:

  • Ruang Agen yang dikonfigurasi di AWS DevOps Agen

  • Akses ke konsol AWS DevOps Agen

  • Sistem eksternal yang akan mengirim permintaan webhook

Jenis webhook

AWS DevOps Agen mendukung jenis webhook berikut:

  • Webhook khusus integrasi — Dibuat secara otomatis saat Anda mengonfigurasi integrasi pihak ketiga seperti Dynatrace, Splunk, Datadog, New Relic, atau Slack. ServiceNow Webhook ini dikaitkan dengan integrasi spesifik dan menggunakan metode otentikasi yang ditentukan oleh jenis integrasi

  • Webhook generik — Dapat dibuat secara manual untuk memicu penyelidikan dari sumber apa pun yang tidak tercakup oleh integrasi tertentu. Webhook generik saat ini menggunakan otentikasi HMAC (token pembawa saat ini tidak tersedia).

  • Grafana alert webhook — Grafana dapat mengirim notifikasi peringatan langsung AWS DevOps ke Agen melalui titik kontak webhook. Untuk petunjuk penyiapan termasuk templat notifikasi khusus, lihat Menghubungkan Grafana.

Metode otentikasi Webhook

Metode otentikasi untuk webhook Anda bergantung pada integrasi mana yang terkait dengannya:

Otentikasi HMAC - Digunakan oleh:

  • Webhook integrasi Dynatrace

  • Webhook generik (tidak ditautkan ke integrasi pihak ketiga tertentu)

Otentikasi token pembawa - Digunakan oleh:

  • Webhook integrasi splunk

  • Webhook integrasi Datadog

  • Webhook integrasi Relic baru

  • ServiceNow integrasi webhooks

  • Webhook integrasi slack

Mengkonfigurasi akses webhook

Langkah 1: Arahkan ke konfigurasi webhook

  1. Masuk ke AWS Management Console dan navigasikan ke konsol AWS DevOps Agen

  2. Pilih Ruang Agen Anda

  3. Buka tab Kemampuan

  4. Di bagian Webhook, klik Konfigurasi

Langkah 2: Hasilkan kredenal webhook

Untuk webhook khusus integrasi:

Webhook dibuat secara otomatis saat Anda menyelesaikan konfigurasi integrasi pihak ketiga. URL titik akhir webhook dan kredensil disediakan di akhir proses penyiapan integrasi.

Untuk webhook generik:

  1. Klik Hasilkan webhook

  2. Sistem akan menghasilkan key pair HMAC

  3. Simpan kunci dan rahasia yang dihasilkan dengan aman — Anda tidak akan dapat mengambilnya lagi

  4. Salin URL titik akhir webhook yang disediakan

Langkah 3: Konfigurasikan sistem eksternal Anda

Gunakan URL endpoint webhook dan kredensional untuk mengonfigurasi sistem eksternal Anda untuk mengirim permintaan ke Agen. AWS DevOps Langkah-langkah konfigurasi spesifik tergantung pada sistem eksternal Anda.

Mengelola kredenal webhook

Menghapus kredensi — Untuk menghapus kredenal webhook, buka bagian konfigurasi webhook dan klik Hapus. Setelah menghapus kredensil, titik akhir webhook tidak akan lagi menerima permintaan sampai Anda menghasilkan kredensil baru.

Regenerating credentials — Untuk menghasilkan kredensi baru, hapus kredensi yang ada terlebih dahulu, lalu buat key pair atau token baru.

Menggunakan webhook

Format permintaan webhook

Untuk memicu investigasi, sistem eksternal Anda harus mengirim permintaan HTTP POST ke URL endpoint webhook.

Untuk Versi 1 (otentikasi HMAC):

Header:

  • Content-Type: application/json

  • x-amzn-event-signature: <HMAC signature>

  • x-amzn-event-timestamp: <+%Y-%m-%dT%H:%M:%S.000Z>

Tanda tangan HMAC dihasilkan dengan menandatangani badan permintaan dengan kunci rahasia Anda menggunakan SHA-256.

Untuk Versi 2 (otentikasi token pembawa):

Header:

  • Content-Type: application/json

  • Authorization: Bearer <your-token>

Permintaan badan:

Badan permintaan harus menyertakan informasi tentang insiden tersebut:

json { "title": "Incident title", "severity": "high", "affectedResources": ["resource-id-1", "resource-id-2"], "timestamp": "2025-11-23T18:00:00Z", "description": "Detailed incident description", "data": { "metadata": { "region": "us-east-1", "environment": "production" } } }

Contoh kode

Versi 1 (otentikasi HMAC) -: JavaScript

const crypto = require('crypto'); // Webhook configuration const webhookUrl = 'https://your-webhook-endpoint.amazonaws.com/invoke'; const webhookSecret = 'your-webhook-secret-key'; // Incident data const incidentData = { eventType: 'incident', incidentId: 'incident-123', action: 'created', priority: "HIGH", title: 'High CPU usage on production server', description: 'High CPU usage on production server host ABC in AWS account 1234 region us-east-1', timestamp: new Date().toISOString(), service: 'MyTestService', data: { metadata: { region: 'us-east-1', environment: 'production' } } }; // Convert data to JSON string const payload = JSON.stringify(incidentData); const timestamp = new Date().toISOString(); const hmac = crypto.createHmac("sha256", webhookSecret); hmac.update(`${timestamp}:${payload}`, "utf8"); const signature = hmac.digest("base64"); // Send the request fetch(webhookUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-amzn-event-timestamp': timestamp, 'x-amzn-event-signature': signature }, body: payload }) .then(res => { console.log(`Status Code: ${res.status}`); return res.text(); }) .then(data => { console.log('Response:', data); }) .catch(error => { console.error('Error:', error); });

Versi 1 (otentikasi HMAC) - cURL:

#!/bin/bash # Configuration WEBHOOK_URL="https://event-ai.us-east-1.api.aws/webhook/generic/YOUR_WEBHOOK_ID" SECRET="YOUR_WEBHOOK_SECRET" # Create payload TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%S.000Z) INCIDENT_ID="test-alert-$(date +%s)" PAYLOAD=$(cat <<EOF { "eventType": "incident", "incidentId": "$INCIDENT_ID", "action": "created", "priority": "HIGH", "title": "Test Alert", "description": "Test alert description", "service": "TestService", "timestamp": "$TIMESTAMP" } EOF ) # Generate HMAC signature SIGNATURE=$(echo -n "${TIMESTAMP}:${PAYLOAD}" | openssl dgst -sha256 -hmac "$SECRET" -binary | base64) # Send webhook curl -X POST "$WEBHOOK_URL" \ -H "Content-Type: application/json" \ -H "x-amzn-event-timestamp: $TIMESTAMP" \ -H "x-amzn-event-signature: $SIGNATURE" \ -d "$PAYLOAD"

Versi 2 (otentikasi token pembawa) -: JavaScript

function sendEventToWebhook(webhookUrl, secret) { const timestamp = new Date().toISOString(); const payload = { eventType: 'incident', incidentId: 'incident-123', action: 'created', priority: "HIGH", title: 'Test Alert', description: 'Test description', timestamp: timestamp, service: 'TestService', data: {} }; fetch(webhookUrl, { method: "POST", headers: { "Content-Type": "application/json", "x-amzn-event-timestamp": timestamp, "Authorization": `Bearer ${secret}`, // Fixed: template literal }, body: JSON.stringify(payload), }); }

Versi 2 (otentikasi token pembawa) - cURL:

#!/bin/bash # Configuration WEBHOOK_URL="https://event-ai.us-east-1.api.aws/webhook/generic/YOUR_WEBHOOK_ID" SECRET="YOUR_WEBHOOK_SECRET" # Create payload TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%S.000Z) INCIDENT_ID="test-alert-$(date +%s)" PAYLOAD=$(cat <<EOF { "eventType": "incident", "incidentId": "$INCIDENT_ID", "action": "created", "priority": "HIGH", "title": "Test Alert", "description": "Test alert description", "service": "TestService", "timestamp": "$TIMESTAMP" } EOF ) # Send webhook curl -X POST "$WEBHOOK_URL" \ -H "Content-Type: application/json" \ -H "x-amzn-event-timestamp: $TIMESTAMP" \ -H "Authorization: Bearer $SECRET" \ -d "$PAYLOAD"

Memecahkan masalah webhook

Jika Anda tidak menerima 200

Sebuah 200 dan pesan seperti webhook diterima menunjukkan otentikasi berlalu dan pesan telah antri untuk sistem untuk memverifikasi dan memproses. Jika Anda tidak mendapatkan 200 tetapi 4xx kemungkinan besar ada yang salah dengan otentikasi atau header. Coba kirim secara manual menggunakan opsi curl untuk membantu men-debug otentikasi.

Jika Anda menerima 200 tetapi penyelidikan tidak dimulai

Kemungkinan penyebabnya adalah muatan yang salah format.

  1. Periksa stempel waktu dan id insiden diperbarui dan unik. Pesan duplikat di-deduplikasi.

  2. Periksa pesan JSON yang valid

  3. Periksa formatnya benar

Jika Anda menerima 200 dan investigasi segera dibatalkan

Kemungkinan besar Anda telah mencapai batas untuk bulan itu. Silakan berbicara dengan AWS kontak Anda untuk meminta perubahan batas tarif jika sesuai.