🔔
Nagios / Icinga
Notification command olarak tanımlayın. Host ve service alarmları anında sesli bildirime dönüşür. Nagios 4.x ve Icinga2 için ayrı config örnekleri verilmiştir.
Gereksinimler
- Alertalk hesabı — WebApi, Starter veya Pro plan (Free planda API & Webhook yoktur)
- Alertalk Webhook Key — API & Webhooks
- Nagios sunucusunda
curlkurulu olmalı - Nagios sunucusunun internete erişimi olmalı
curl kurulu değilse: apt install curl veya yum install curl
Kurulum
1
alertalk_notify.sh Script Oluşturun
Aşağıdaki scripti Nagios sunucusunda oluşturun:
/usr/local/nagios/libexec/alertalk_notify.sh
bash
#!/bin/bash
# Alertalk Voice Notification Script
# /usr/local/nagios/libexec/alertalk_notify.sh
WEBHOOK_KEY="YOUR_WEBHOOK_KEY"
PHONE_NUMBER="$1" # İlk argüman: telefon numarası
MESSAGE="$2" # İkinci argüman: alarm mesajı
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_NUMBER}\",\"error_message\":\"${MESSAGE}\"}" \
--max-time 10
exit 0İzin ver
chmod +x /usr/local/nagios/libexec/alertalk_notify.sh
chown nagios:nagios /usr/local/nagios/libexec/alertalk_notify.sh2
Command Tanımı Ekleyin
commands.cfg dosyasına ekleyin:
/usr/local/nagios/etc/objects/commands.cfg
nagios config
# Alertalk — Host Notification Command
define command {
command_name notify-host-by-alertalk
command_line /usr/local/nagios/libexec/alertalk_notify.sh \
"$CONTACTPAGER$" \
"Host: $HOSTALIAS$ - $HOSTSTATE$ - $HOSTOUTPUT$"
}
# Alertalk — Service Notification Command
define command {
command_name notify-service-by-alertalk
command_line /usr/local/nagios/libexec/alertalk_notify.sh \
"$CONTACTPAGER$" \
"Host: $HOSTALIAS$ Service: $SERVICEDESC$ - $SERVICESTATE$ - $SERVICEOUTPUT$"
}3
Contact Tanımı Ekleyin
contacts.cfg dosyasına Alertalk contact'ını ekleyin. pager alanına telefon numaranızı yazın:
/usr/local/nagios/etc/objects/contacts.cfg
nagios config
define contact {
contact_name alertalk-admin
alias Alertalk Voice Alert
pager 5XXXXXXXXX ; Telefon numarası (başında 0 olmadan)
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-alertalk
host_notification_commands notify-host-by-alertalk
}
Birden fazla numara: pager alanına
5XXXXXXXXX,5YYYYYYYYY şeklinde yazın.
4
Contact Group'a Ekleyin ve Nagios'u Yeniden Başlatın
nagios config — contactgroups.cfg
define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin, alertalk-admin
}bash
# Config doğrula
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Yeniden başlat
systemctl restart nagios1
NotificationCommand Tanımlayın
Icinga2 config dizininde alertalk.conf dosyası oluşturun:
/etc/icinga2/conf.d/alertalk.conf
icinga2 config
// Alertalk Notification Commands
object NotificationCommand "alertalk-host" {
command = [ "/bin/bash", "-c" ]
arguments += {
"--" = {
value = {{
var phone = macro("$user.pager$")
var msg = "Host: " + macro("$host.display_name$") + " - " + macro("$host.state$") + " - " + macro("$host.output$")
return "curl -s -X POST 'https://tr.alertalk.net/webhook/receive' " +
"-H 'Content-Type: application/json' " +
"-H 'X-Webhook-Key: YOUR_WEBHOOK_KEY' " +
"-d '{\"phone_number\":\"" + phone + "\",\"error_message\":\"" + msg + "\"}'"
}}
order = 0
}
}
}
object NotificationCommand "alertalk-service" {
command = [ "/bin/bash", "-c" ]
arguments += {
"--" = {
value = {{
var phone = macro("$user.pager$")
var msg = "Host: " + macro("$host.display_name$") + " Service: " + macro("$service.display_name$") + " - " + macro("$service.state$")
return "curl -s -X POST 'https://tr.alertalk.net/webhook/receive' " +
"-H 'Content-Type: application/json' " +
"-H 'X-Webhook-Key: YOUR_WEBHOOK_KEY' " +
"-d '{\"phone_number\":\"" + phone + "\",\"error_message\":\"" + msg + "\"}'"
}}
order = 0
}
}
}2
User Tanımlayın
icinga2 config — users.conf
object User "alertalk-admin" {
display_name = "Alertalk Voice Alert"
pager = "5XXXXXXXXX" // Telefon numarası
states = [ OK, Warning, Critical, Unknown ]
types = [ Problem, Recovery ]
}3
Notification Kuralı Ekleyin
icinga2 config — notifications.conf
// Tüm host alarmları için
apply Notification "alertalk-host" to Host {
command = "alertalk-host"
users = [ "alertalk-admin" ]
states = [ Down, Up ]
types = [ Problem, Recovery ]
assign where host.name
}
// Tüm service alarmları için
apply Notification "alertalk-service" to Service {
command = "alertalk-service"
users = [ "alertalk-admin" ]
states = [ Critical, Warning, Unknown, OK ]
types = [ Problem, Recovery ]
assign where service.name
}4
Icinga2'yi Yeniden Başlatın
bash
# Config doğrula
icinga2 daemon -C
# Yeniden başlat
systemctl restart icinga2Test Edin
Nagios/Icinga kurmadan önce scripti direkt çalıştırarak test edebilirsiniz:
bash — direkt test
# Nagios script'ini direkt çalıştır
/usr/local/nagios/libexec/alertalk_notify.sh \
"5XXXXXXXXX" \
"Test: Nagios entegrasyonu basarili"
# Ya da curl ile direkt test
curl -s -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":"Nagios test alarmi"}'
Entegrasyon tamamlandı!
Artık Nagios/Icinga alarmlarında sesli bildirim alacaksınız.
Makro Referansı
error_message alanında kullanabileceğiniz Nagios makroları:
Nagios 4.x — Makrolar
$HOSTALIAS$ # Host takma adı
$HOSTADDRESS$ # Host IP adresi
$HOSTSTATE$ # UP, DOWN, UNREACHABLE
$HOSTOUTPUT$ # Host check çıktısı
$SERVICEDESC$ # Servis adı
$SERVICESTATE$ # OK, WARNING, CRITICAL, UNKNOWN
$SERVICEOUTPUT$ # Servis check çıktısı
$CONTACTPAGER$ # Contact pager alanı (telefon numarası)
$NOTIFICATIONTYPE$ # PROBLEM, RECOVERY, ACK vb.Icinga2 — Makrolar
$host.display_name$ # Host görünen adı
$host.address$ # Host IP adresi
$host.state$ # Up, Down
$host.output$ # Check çıktısı
$service.display_name$ # Servis görünen adı
$service.state$ # OK, Warning, Critical, Unknown
$service.output$ # Servis check çıktısı
$user.pager$ # User pager alanı (telefon numarası)
$notification.type$ # Problem, Recovery, Acknowledgement