🔌
Generic Webhook / API
HTTP POST gönderebilen her sistem Alertalk ile entegre olabilir. Python, PHP, C#, Node.js, cURL ve daha fazlası için hazır kod örnekleri.
Endpoint & Payload Referansı
⚡ Hızlı Referans
URL
https://tr.alertalk.net/webhook/receive
Method
POST
Content-Type
application/json
Header X-Webhook-Key: YOUR_WEBHOOK_KEY
phone_number Zorunlu — 5XXXXXXXXX (virgülle birden fazla) error_message Zorunlu — TTS ile okunacak mesaj, max 500 karakter
Header X-Webhook-Key: YOUR_WEBHOOK_KEY
phone_number Zorunlu — 5XXXXXXXXX (virgülle birden fazla) error_message Zorunlu — TTS ile okunacak mesaj, max 500 karakter
Birden fazla numaraya çağrı:
"phone_number": "5XXXXXXXXX,5YYYYYYYYY,5ZZZZZZZZZ"
Her numara için 1 kredi kullanılır.
Response Kodları
| Kod | Anlam | Açıklama |
|---|---|---|
| 200 | Success | Webhook alındı, çağrı kuyruğa alındı. {"message":"1 call(s) queued","status":"success"} |
| 402 | Insufficient Credit | Yetersiz kredi. Alertalk panelinden kredi satın alın. |
| 403 | Invalid Webhook Key | Webhook key geçersiz veya eksik. X-Webhook-Key header'ını kontrol edin. |
| 400 | Bad Request | Hatalı istek formatı. phone_number veya error_message eksik. |
Kod Örnekleri
cURL
curl -X POST "https://tr.alertalk.net/webhook/receive" \ -H "Content-Type: application/json" \ -H "X-Webhook-Key: YOUR_WEBHOOK_KEY" \ -d '{ "phone_number": "5XXXXXXXXX", "error_message": "Kritik alarm: Sunucu erişilemiyor" }'
cURL ile test yapmak için YOUR_WEBHOOK_KEY ve telefon numarasını değiştirip terminalde çalıştırın.
Python — requests
import requests WEBHOOK_KEY = "YOUR_WEBHOOK_KEY" URL = "https://tr.alertalk.net/webhook/receive" def send_voice_alert(phone_number, message): headers = { "Content-Type": "application/json", "X-Webhook-Key": WEBHOOK_KEY } payload = { "phone_number": phone_number, "error_message": message } response = requests.post(URL, json=payload, headers=headers, timeout=10) return response.json() # Kullanım result = send_voice_alert( phone_number="5XXXXXXXXX", message="Kritik alarm: Veritabanı bağlantısı kesildi" ) print(result)
Python — birden fazla numara
# Birden fazla numaraya çağrı — virgülle ayır result = send_voice_alert( phone_number="5XXXXXXXXX,5YYYYYYYYY", message="Disk dolulugu kritik seviyeye ulasti" )
PHP — cURL
<?php function sendVoiceAlert($phoneNumber, $message) { $webhookKey = 'YOUR_WEBHOOK_KEY'; $url = 'https://tr.alertalk.net/webhook/receive'; $payload = json_encode([ 'phone_number' => $phoneNumber, 'error_message' => $message ]); $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'X-Webhook-Key: ' . $webhookKey ] ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ['code' => $httpCode, 'body' => json_decode($response, true)]; } // Kullanım $result = sendVoiceAlert('5XXXXXXXXX', 'Kritik alarm: Sunucu erisilemez'); var_dump($result);
C# — HttpClient (.NET)
using System.Net.Http; using System.Text; using System.Text.Json; public class AlertalkService { private const string WebhookKey = "YOUR_WEBHOOK_KEY"; private const string Url = "https://tr.alertalk.net/webhook/receive"; private static readonly HttpClient _client = new HttpClient(); public static async Task<string> SendVoiceAlertAsync( string phoneNumber, string message) { _client.DefaultRequestHeaders.Remove("X-Webhook-Key"); _client.DefaultRequestHeaders.Add("X-Webhook-Key", WebhookKey); var payload = JsonSerializer.Serialize(new { phone_number = phoneNumber, error_message = message }); var content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await _client.PostAsync(Url, content); return await response.Content.ReadAsStringAsync(); } } // Kullanım await AlertalkService.SendVoiceAlertAsync( "5XXXXXXXXX", "Kritik: Veritabani baglantisi kesildi" );
Node.js — fetch (built-in)
const WEBHOOK_KEY = 'YOUR_WEBHOOK_KEY'; const URL = 'https://tr.alertalk.net/webhook/receive'; async function sendVoiceAlert(phoneNumber, message) { const response = await fetch(URL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Webhook-Key': WEBHOOK_KEY }, body: JSON.stringify({ phone_number: phoneNumber, error_message: message }) }); if (!response.ok) { throw new Error(`Alertalk error: ${response.status}`); } return response.json(); } // Kullanım sendVoiceAlert('5XXXXXXXXX', 'Kritik alarm: Servis down') .then(r => console.log(r)) .catch(e => console.error(e));
Node.js — axios
const axios = require('axios'); await axios.post('https://tr.alertalk.net/webhook/receive', { phone_number: '5XXXXXXXXX', error_message: 'Kritik alarm: Disk dolu' }, { headers: { 'X-Webhook-Key': 'YOUR_WEBHOOK_KEY' } });
PowerShell — Invoke-RestMethod
# TLS 1.2 zorla (Windows Server icin gerekli) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $webhookKey = "YOUR_WEBHOOK_KEY" $phoneNumber = "5XXXXXXXXX" $message = "Kritik alarm: Servis down" $headers = @{ "X-Webhook-Key" = $webhookKey "Content-Type" = "application/json" } $body = @{ phone_number = $phoneNumber error_message = $message } | ConvertTo-Json try { $response = Invoke-RestMethod ` -Uri "https://tr.alertalk.net/webhook/receive" ` -Method Post ` -Headers $headers ` -Body ([System.Text.Encoding]::UTF8.GetBytes($body)) Write-Host "Basarili: $response" } catch { Write-Host "Hata: $($_.Exception.Message)" }
Bash — curl
#!/bin/bash WEBHOOK_KEY="YOUR_WEBHOOK_KEY" PHONE="5XXXXXXXXX" MESSAGE="Kritik alarm: Disk dolu" send_alert() { local phone="$1" local msg="$2" curl -s -X POST "https://tr.alertalk.net/webhook/receive" \ -H "Content-Type: application/json" \ -H "X-Webhook-Key: ${WEBHOOK_KEY}" \ -d "{\"phone_number\":\"${phone}\",\"error_message\":\"${msg}\"}" } # Kullanım send_alert "${PHONE}" "${MESSAGE}"
Örnek Senaryolar
🐙 GitHub Actions — Deploy başarısız olunca ara
.github/workflows/deploy.yml
name: Deploy on: push: branches: [main] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Deploy id: deploy run: ./deploy.sh - name: Alertalk — Deploy basarisiz oldu if: failure() run: | curl -s -X POST "https://tr.alertalk.net/webhook/receive" \ -H "Content-Type: application/json" \ -H "X-Webhook-Key: ${{ secrets.ALERTALK_WEBHOOK_KEY }}" \ -d '{"phone_number":"${{ secrets.ALERT_PHONE }}","error_message":"GitHub Actions: Deploy basarisiz oldu - ${{ github.repository }}"}'
Webhook key ve telefon numarasını GitHub Secrets'a ekleyin: Settings → Secrets → Actions → New secret
⏰ Linux Cron Job — Disk doluluk kontrolü
Bash — disk_check.sh
#!/bin/bash # /etc/cron.d/disk_check — her saat çalışır THRESHOLD=85 WEBHOOK_KEY="YOUR_WEBHOOK_KEY" PHONE="5XXXXXXXXX" HOSTNAME=$(hostname) USAGE=$(df / | awk 'NR==2 {print $5}' | tr -d '%') if [ "$USAGE" -gt "$THRESHOLD" ]; then curl -s -X POST "https://tr.alertalk.net/webhook/receive" \ -H "Content-Type: application/json" \ -H "X-Webhook-Key: ${WEBHOOK_KEY}" \ -d "{\"phone_number\":\"${PHONE}\",\"error_message\":\"${HOSTNAME} disk dolulugu kritik: %${USAGE}\"}" fi
crontab -e
# Her saat başı çalıştır 0 * * * * /bin/bash /opt/scripts/disk_check.sh
🐍 Python — Uygulama içi exception alarm
Python — alertalk_handler.py
import requests import logging import traceback class AlertalkHandler(logging.Handler): def __init__(self, webhook_key, phone_number): super().__init__(level=logging.CRITICAL) self.webhook_key = webhook_key self.phone_number = phone_number def emit(self, record): try: requests.post( "https://tr.alertalk.net/webhook/receive", json={ "phone_number": self.phone_number, "error_message": f"CRITICAL: {record.getMessage()[:200]}" }, headers={"X-Webhook-Key": self.webhook_key}, timeout=5 ) except: pass # Logger'a ekle logger = logging.getLogger() logger.addHandler(AlertalkHandler( webhook_key="YOUR_WEBHOOK_KEY", phone_number="5XXXXXXXXX" )) # CRITICAL log otomatik Alertalk'a gider logger.critical("Veritabani baglantisi koptu!")