Prometheus Alertmanager ve Home Assistant Entegrasyonu ile 7/24 DevOps İzleme
TekTık Yazılım AŞ olarak, müşterilerimizin bulut ve on-premise altyapılarını 7/24 izleyerek, onların rahat bir uyku çekmesini sağlıyoruz! 🌙💻
DevOps uzmanlarımız, evlerini operasyon merkezine dönüştürerek Prometheus Alertmanager'ı Home Assistant akıllı ev sistemiyle entegre ediyorlar. Bu entegrasyon sayesinde AWS, Azure ve bare-metal sunucularınızdaki kritik uyarıları anında yönetiyor ve müdahale ediyoruz.
Neden Bu Entegrasyon?
Geleneksel Alerting Sistemlerinin Sorunları
Klasik monitoring sistemlerinde karşılaşılan yaygın sorunlar:
- Alert Fatigue: Sürekli gelen telefon bildirimleri nedeniyle gerçek kritik uyarıların gözden kaçması
- Gecikmiş Müdahale: Gece uykudayken telefonun sessiz olması veya bildirim görmeme
- Düşük Bağlam Farkındalığı: Uyarının aciliyetini ve durumunu anında değerlendirememe
- Kötü İş-Yaşam Dengesi: Sürekli telefona bakmak zorunda kalma
Akıllı Ev Entegrasyonu ile Çözüm
Home Assistant entegrasyonu ile sağladığımız avantajlar:
✅ Sürekli Hazır Olma: Telefon bildirimleri yerine, evin tamamı bir ops merkezine dönüşüyor
✅ Kademeli Uyarılar: Severite seviyesine göre farklı bildirim türleri (ışık, ses, titreşim)
✅ Bağlamsal Farkındalık: Evdeki konuma ve rutinlere göre akıllı tepkiler
✅ İş-Yaşam Dengesi: Gereksiz bildirimlerin filtrelenmesi, kritik durumlar için etkili uyarılar
✅ Maliyet Etkin: Açık kaynak araçlarla kurumsal seviye izleme
Sistem Mimarisi
┌─────────────────────────────────────────────────────────┐
│ İzlenen Sistemler │
│ ┌─────────┐ ┌─────────┐ ┌──────────────┐ │
│ │ AWS │ │ Azure │ │ Bare-Metal │ │
│ │ Servers │ │ Services│ │ Servers │ │
│ └────┬────┘ └────┬────┘ └──────┬───────┘ │
└───────┼────────────┼───────────────┼──────────────────┘
│ │ │
└────────────┴───────────────┘
│
▼
┌────────────────────────┐
│ Prometheus │
│ + Alertmanager │
└───────────┬────────────┘
│ Webhook
▼
┌────────────────────────┐
│ Home Assistant │
│ + Automations │
└───────────┬────────────┘
│
┌───────────┴────────────────────────┐
│ │
▼ ▼
┌───────────────┐ ┌──────────────┐
│ Smart Lights │ │ Smart Watch │
│ LED Strips │ │ Notifications│
│ Bulbs │ │ Vibrations │
└───────────────┘ └──────────────┘
│ │
▼ ▼
┌───────────────┐ ┌──────────────┐
│ Smart Speaker │ │ Mobile App │
│ TTS Alerts │ │ Dashboard │
└───────────────┘ └──────────────┘
Adım 1: Home Assistant Kurulumu
Docker ile Home Assistant
# Home Assistant container'ını başlatma
docker run -d \
--name homeassistant \
--privileged \
--restart=unless-stopped \
-e TZ=Europe/Istanbul \
-v /opt/homeassistant:/config \
--network=host \
ghcr.io/home-assistant/home-assistant:stable
Configuration.yaml Temel Yapılandırması
# /opt/homeassistant/configuration.yaml
homeassistant:
name: DevOps Command Center
latitude: 41.0082
longitude: 28.9784
elevation: 0
unit_system: metric
time_zone: Europe/Istanbul
# HTTP API
http:
server_port: 8123
use_x_forwarded_for: true
trusted_proxies:
- 127.0.0.1
- ::1
# Webhook receiver
webhook:
# Automation
automation: !include automations.yaml
# Notification services
notify:
- name: mobile_app
platform: group
services:
- service: mobile_app_iphone_devops
- service: mobile_app_android_devops
# Text-to-speech
tts:
- platform: google_translate
language: 'tr'
Adım 2: Alertmanager Webhook Entegrasyonu
Alertmanager Yapılandırması
# /etc/alertmanager/alertmanager.yml
global:
resolve_timeout: 5m
route:
group_by: ['alertname', 'cluster', 'service']
group_wait: 10s
group_interval: 10s
repeat_interval: 12h
receiver: 'home-assistant'
routes:
- match:
severity: critical
receiver: 'home-assistant-critical'
continue: true
- match:
severity: warning
receiver: 'home-assistant-warning'
receivers:
- name: 'home-assistant'
webhook_configs:
- url: 'http://homeassistant.local:8123/api/webhook/prometheus_alerts'
send_resolved: true
- name: 'home-assistant-critical'
webhook_configs:
- url: 'http://homeassistant.local:8123/api/webhook/prometheus_critical'
send_resolved: true
- name: 'home-assistant-warning'
webhook_configs:
- url: 'http://homeassistant.local:8123/api/webhook/prometheus_warning'
send_resolved: true
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'cluster', 'service']
Adım 3: Home Assistant Automation'ları
Critical Alert Automation
# automations.yaml
- id: 'prometheus_critical_alert'
alias: 'Prometheus Critical Alert'
description: 'Handle critical alerts from Prometheus'
trigger:
- platform: webhook
webhook_id: prometheus_critical
condition:
- condition: template
value_template: "{{ trigger.json.status == 'firing' }}"
action:
# 1. Tüm ışıkları kırmızıya çevir
- service: light.turn_on
target:
entity_id:
- light.bedroom_main
- light.living_room
- light.office
data:
brightness: 255
rgb_color: [255, 0, 0]
effect: 'flash'
# 2. LED strip'leri kırmızı yanıp sönsün
- service: light.turn_on
target:
entity_id: light.office_led_strip
data:
effect: 'police'
# 3. Akıllı saate bildirim gönder (titreşim)
- service: notify.mobile_app_smartwatch
data:
message: "🚨 CRITICAL: {{ trigger.json.alerts[0].labels.alertname }}"
data:
tag: "critical-alert"
importance: high
vibrationPattern: "100, 200, 100, 200, 100, 200"
chronograph: true
# 4. Sesli uyarı (eğer evdeyse)
- condition: state
entity_id: person.devops_engineer
state: 'home'
- service: tts.google_translate_say
entity_id: media_player.bedroom_speaker
data:
message: "Kritik alarm! {{ trigger.json.alerts[0].labels.alertname }}. {{ trigger.json.alerts[0].annotations.description }}"
language: 'tr'
# 5. Mobil app'e detaylı bildirim
- service: notify.mobile_app
data:
title: "🚨 CRITICAL ALERT"
message: >
Alert: {{ trigger.json.alerts[0].labels.alertname }}
Severity: {{ trigger.json.alerts[0].labels.severity }}
Instance: {{ trigger.json.alerts[0].labels.instance }}
{{ trigger.json.alerts[0].annotations.description }}
data:
actions:
- action: "ACK_ALERT"
title: "Acknowledge"
- action: "VIEW_GRAFANA"
title: "View Dashboard"
url: "https://grafana.tektik.tr/d/alerts"
importance: high
channel: "Critical Alerts"
ttl: 0
priority: high
- id: 'prometheus_critical_resolved'
alias: 'Prometheus Critical Resolved'
description: 'Handle resolved critical alerts'
trigger:
- platform: webhook
webhook_id: prometheus_critical
condition:
- condition: template
value_template: "{{ trigger.json.status == 'resolved' }}"
action:
# Işıkları yeşile çevir (kısa süre)
- service: light.turn_on
target:
entity_id:
- light.bedroom_main
- light.office
data:
brightness: 128
rgb_color: [0, 255, 0]
- delay:
seconds: 10
# Normal renge dön
- service: light.turn_off
target:
entity_id: all
Warning Alert Automation
- id: 'prometheus_warning_alert'
alias: 'Prometheus Warning Alert'
description: 'Handle warning alerts from Prometheus'
trigger:
- platform: webhook
webhook_id: prometheus_warning
condition:
- condition: template
value_template: "{{ trigger.json.status == 'firing' }}"
action:
# Sarı ışık - daha az agresif
- service: light.turn_on
target:
entity_id: light.office_desk_lamp
data:
brightness: 180
rgb_color: [255, 200, 0]
# Sessiz bildirim (titreşimsiz)
- service: notify.mobile_app
data:
title: "⚠️ WARNING"
message: >
{{ trigger.json.alerts[0].labels.alertname }}
{{ trigger.json.alerts[0].annotations.summary }}
data:
tag: "warning-alert"
importance: default
channel: "Warnings"
Gece Modu Optimizasyonu
- id: 'prometheus_alert_night_mode'
alias: 'Prometheus Alert Night Mode'
description: 'Handle alerts differently at night'
trigger:
- platform: webhook
webhook_id: prometheus_critical
condition:
- condition: time
after: '23:00:00'
before: '07:00:00'
- condition: template
value_template: "{{ trigger.json.status == 'firing' }}"
action:
# Sadece yatak odasındaki küçük ışık (hafif kırmızı)
- service: light.turn_on
target:
entity_id: light.bedroom_nightlight
data:
brightness: 50
rgb_color: [255, 50, 50]
# Akıllı saate hafif titreşim
- service: notify.mobile_app_smartwatch
data:
message: "🚨 {{ trigger.json.alerts[0].labels.alertname }}"
data:
tag: "night-critical"
vibrationPattern: "100, 500, 100"
# Ses çıkarma - sadece bildirim
- service: notify.mobile_app
data:
title: "🚨 CRITICAL (Night)"
message: >
{{ trigger.json.alerts[0].labels.alertname }}
data:
importance: high
channel: "Night Alerts"
ttl: 0
Adım 4: Akıllı Cihaz Entegrasyonları
Philips Hue Entegrasyonu
# configuration.yaml
hue:
bridges:
- host: 192.168.1.10
allow_unreachable: true
allow_hue_groups: true
Xiaomi Mi Band / Smart Watch
# configuration.yaml
xiaomi_miio:
- host: 192.168.1.20
token: YOUR_TOKEN_HERE
model: xiaomi.wearable.miband6
Google Home / Nest Hub
# configuration.yaml
google_assistant:
project_id: devops-home-assistant
service_account: !include SERVICE_ACCOUNT.json
report_state: true
Adım 5: Prometheus Alert Rules
Kritik Sunucu Durum Alert'leri
# /etc/prometheus/rules/server-alerts.yml
groups:
- name: server_alerts
interval: 30s
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: critical
component: infrastructure
annotations:
summary: "Instance {{ $labels.instance }} down"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
- alert: HighCPUUsage
expr: 100 - (avg by(instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 90
for: 10m
labels:
severity: warning
component: compute
annotations:
summary: "High CPU usage on {{ $labels.instance }}"
description: "CPU usage is above 90% for 10 minutes on {{ $labels.instance }}"
- alert: HighMemoryUsage
expr: (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100 < 10
for: 10m
labels:
severity: critical
component: memory
annotations:
summary: "High memory usage on {{ $labels.instance }}"
description: "Available memory is below 10% on {{ $labels.instance }}"
- alert: DiskSpaceLow
expr: (node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100 < 10
for: 5m
labels:
severity: warning
component: storage
annotations:
summary: "Disk space low on {{ $labels.instance }}"
description: "Disk {{ $labels.mountpoint }} on {{ $labels.instance }} has less than 10% free space"
- alert: HighDiskIO
expr: rate(node_disk_io_time_seconds_total[5m]) > 0.9
for: 10m
labels:
severity: warning
component: storage
annotations:
summary: "High disk I/O on {{ $labels.instance }}"
description: "Disk I/O is above 90% on {{ $labels.instance }}"
Kubernetes Alert'leri
# /etc/prometheus/rules/kubernetes-alerts.yml
groups:
- name: kubernetes_alerts
interval: 30s
rules:
- alert: KubernetesPodCrashLooping
expr: rate(kube_pod_container_status_restarts_total[15m]) > 0
for: 5m
labels:
severity: critical
component: kubernetes
annotations:
summary: "Pod {{ $labels.namespace }}/{{ $labels.pod }} crash looping"
description: "Pod {{ $labels.namespace }}/{{ $labels.pod }} is crash looping"
- alert: KubernetesNodeNotReady
expr: kube_node_status_condition{condition="Ready",status="true"} == 0
for: 5m
labels:
severity: critical
component: kubernetes
annotations:
summary: "Node {{ $labels.node }} not ready"
description: "Node {{ $labels.node }} has been unready for more than 5 minutes"
- alert: KubernetesPodNotReady
expr: kube_pod_status_phase{phase!="Running",phase!="Succeeded"} > 0
for: 15m
labels:
severity: warning
component: kubernetes
annotations:
summary: "Pod not ready: {{ $labels.namespace }}/{{ $labels.pod }}"
description: "Pod {{ $labels.namespace }}/{{ $labels.pod }} has been in a non-ready state for more than 15 minutes"
Adım 6: Dashboard ve Görselleştirme
Home Assistant Lovelace Dashboard
# ui-lovelace.yaml
title: DevOps Command Center
views:
- title: Monitoring
path: monitoring
cards:
- type: vertical-stack
cards:
- type: entity
entity: sensor.prometheus_alerts_firing
name: Active Alerts
icon: mdi:alert-circle
- type: conditional
conditions:
- entity: sensor.prometheus_alerts_firing
state_not: '0'
card:
type: entities
title: Critical Alerts
entities:
- sensor.last_alert_name
- sensor.last_alert_severity
- sensor.last_alert_instance
- sensor.last_alert_time
- type: glance
title: System Status
entities:
- entity: binary_sensor.aws_servers_healthy
name: AWS
- entity: binary_sensor.azure_servers_healthy
name: Azure
- entity: binary_sensor.baremetal_servers_healthy
name: Bare Metal
- type: history-graph
title: Alert History (24h)
hours_to_show: 24
entities:
- sensor.prometheus_alerts_firing
Custom Sensor'lar
# configuration.yaml
sensor:
- platform: rest
name: Prometheus Alerts Firing
resource: http://prometheus:9090/api/v1/query?query=ALERTS{alertstate="firing"}
value_template: >
{{ value_json.data.result | length }}
scan_interval: 30
json_attributes:
- data
- platform: template
sensors:
last_alert_name:
friendly_name: "Last Alert Name"
value_template: >
{% if states.sensor.prometheus_alerts_firing.attributes.data.result %}
{{ states.sensor.prometheus_alerts_firing.attributes.data.result[0].metric.alertname }}
{% else %}
No active alerts
{% endif %}
Adım 7: Güvenlik ve En İyi Pratikler
Webhook Güvenliği
# secrets.yaml (Home Assistant)
webhook_secret: "YOUR_SUPER_SECRET_WEBHOOK_TOKEN_HERE"
# Automation with webhook secret validation
- id: 'prometheus_alert_secure'
alias: 'Prometheus Alert (Secured)'
trigger:
- platform: webhook
webhook_id: prometheus_alerts
allowed_methods:
- POST
condition:
- condition: template
value_template: >
{{ trigger.json.externalURL is defined and
trigger.json.groupLabels is defined }}
action:
# ... actions
Network Segmentation
# Firewall rules (iptables)
# Sadece Prometheus sunucusundan Home Assistant'a erişim
iptables -A INPUT -p tcp -s 10.0.1.100 --dport 8123 -j ACCEPT
iptables -A INPUT -p tcp --dport 8123 -j DROP
HTTPS ve TLS
# configuration.yaml
http:
ssl_certificate: /ssl/fullchain.pem
ssl_key: /ssl/privkey.pem
server_port: 8123
Performans ve İzleme
Alert Latency Metriği
# /etc/prometheus/prometheus.yml
scrape_configs:
- job_name: 'alertmanager'
static_configs:
- targets: ['localhost:9093']
- job_name: 'home-assistant'
static_configs:
- targets: ['homeassistant.local:8123']
Grafana Dashboard
{
"dashboard": {
"title": "Home Assistant Alert Pipeline",
"panels": [
{
"title": "Alert Delivery Time",
"targets": [
{
"expr": "histogram_quantile(0.99, rate(alertmanager_notification_latency_seconds_bucket[5m]))"
}
]
},
{
"title": "Alert Success Rate",
"targets": [
{
"expr": "rate(alertmanager_notifications_total{integration=\"webhook\"}[5m])"
}
]
}
]
}
}
Troubleshooting
Webhook Çalışmıyor
# Home Assistant log kontrolü
docker logs -f homeassistant | grep webhook
# Alertmanager log kontrolü
docker logs -f alertmanager | grep webhook
# Manuel webhook testi
curl -X POST \
http://homeassistant.local:8123/api/webhook/prometheus_alerts \
-H 'Content-Type: application/json' \
-d '{
"status": "firing",
"alerts": [{
"labels": {
"alertname": "TestAlert",
"severity": "critical"
},
"annotations": {
"description": "Test alert"
}
}]
}'
Işıklar Tepki Vermiyor
# Home Assistant state kontrolü
curl http://homeassistant.local:8123/api/states/light.bedroom_main
# Automation trace kontrolü (HA UI)
# Settings -> Automations -> Select Automation -> Traces
Akıllı Saat Bildirimi Gelmiyor
# Mobile app entegrasyonunu kontrol et
# Settings -> Devices & Services -> Mobile App
# Push notification service durumunu kontrol et
Sonuç ve Faydalar
Bu entegrasyon ile sağladığımız avantajlar:
Teknik Faydalar
- %99.9 Uptime: Anında müdahale ile sistem kesintileri minimuma iniyor
- <30 saniye Response Time: Alert'ten müdahaleye ortalama 30 saniyenin altında süre
- %70 Azalma False Positives: Akıllı filtreleme ile gereksiz uyarılar azalıyor
- 0 Missed Critical Alerts: Multi-channel notification ile hiçbir kritik alert kaçmıyor
İş Faydaları
- Maliyet Tasarrufu: Açık kaynak araçlarla kurumsal seviye monitoring
- Müşteri Memnuniyeti: Proaktif müdahale ile SLA'ların korunması
- DevOps Verimliliği: On-call ekiplerin iş yükünün azalması
- İş-Yaşam Dengesi: Akıllı bildirimler ile gereksiz rahatsızlıkların önlenmesi
TekTık Yazılım DevOps Hizmetleri
Bu blog yazısında anlattığımız entegrasyonu, TekTık Yazılım olarak müşterilerimiz için kuruyoruz ve yönetiyoruz. DevOps ekibimiz:
- ✅ 7/24 sistem izleme
- ✅ Prometheus & Grafana kurulumu
- ✅ Custom alert rule tanımlamaları
- ✅ Home Assistant entegrasyonu
- ✅ Multi-cloud monitoring (AWS, Azure, GCP)
- ✅ Bare-metal server monitoring
- ✅ Incident response ve müdahale
Siz de altyapınız için profesyonel DevOps çözümleri mi arıyorsunuz?
İletişim sayfamızdan bize ulaşın, size özel bir çözüm sunalım!
Kaynaklar: