# Alertmanager Webhook Configuration for WebSMS
#
# This configuration shows how to send SMS alerts from Prometheus Alertmanager
# to WebSMS using the webhook receiver.
#
# Documentation: https://websms.co.nz/integrations/prometheus/
# API Endpoint: https://websms.co.nz/api/connexus/sms.php
#
# Replace the following placeholders:
#   - your-email@example.com: Your WebSMS account email
#   - your-password: Your WebSMS account password
#   - 6421234567: Recipient phone number (international format)

global:
  resolve_timeout: 5m

# Route configuration
# Route alerts based on severity labels to different receivers
route:
  # Default receiver for all alerts
  receiver: 'default'

  # Group alerts by alertname and job to avoid alert storms
  group_by: ['alertname', 'job']

  # Wait 30 seconds before sending the first notification
  group_wait: 30s

  # Wait 5 minutes before sending updated notifications
  group_interval: 5m

  # Wait 4 hours before repeating a notification
  repeat_interval: 4h

  # Child routes for specific alert routing
  routes:
    # Critical alerts go to SMS
    - match:
        severity: critical
      receiver: 'websms-critical'
      continue: false

    # High severity alerts also go to SMS during business hours
    - match:
        severity: high
      receiver: 'websms-high'
      continue: false

# Receiver definitions
receivers:
  # Default receiver (e.g., Slack, email)
  - name: 'default'
    # Configure your default notification channel here

  # WebSMS receiver for critical alerts
  - name: 'websms-critical'
    webhook_configs:
      - url: 'https://websms.co.nz/api/connexus/sms.php'
        http_config:
          basic_auth:
            username: 'your-email@example.com'
            password: 'your-password'
        # Send notifications when alerts resolve
        send_resolved: true
        # Max alerts per webhook (to prevent oversized payloads)
        max_alerts: 10

  # WebSMS receiver for high severity alerts
  - name: 'websms-high'
    webhook_configs:
      - url: 'https://websms.co.nz/api/connexus/sms.php'
        http_config:
          basic_auth:
            username: 'your-email@example.com'
            password: 'your-password'
        send_resolved: true
        max_alerts: 5

# Inhibition rules
# Suppress notifications when a more severe alert is firing
inhibit_rules:
  # If a critical alert is firing, suppress high severity alerts for the same alertname
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'high'
    equal: ['alertname', 'instance']

# Templates for alert messages (optional)
# You can customise the alert message format sent to WebSMS
# templates:
#   - '/etc/alertmanager/templates/*.tmpl'

# ---
# Example Prometheus Alert Rules
# Save this in your Prometheus rules directory (e.g., /etc/prometheus/rules/websms-alerts.yml)
# ---
# groups:
#   - name: websms-critical-alerts
#     rules:
#       # Alert when a service is down
#       - alert: ServiceDown
#         expr: up == 0
#         for: 1m
#         labels:
#           severity: critical
#         annotations:
#           summary: "Service {{ $labels.instance }} is down"
#           description: "{{ $labels.job }} on {{ $labels.instance }} has been down for more than 1 minute."
#
#       # Alert when container restarts frequently
#       - alert: ContainerRestarting
#         expr: increase(kube_pod_container_status_restarts_total[1h]) > 5
#         for: 5m
#         labels:
#           severity: critical
#         annotations:
#           summary: "Container {{ $labels.container }} is restarting frequently"
#           description: "Container {{ $labels.container }} in pod {{ $labels.pod }} has restarted more than 5 times in the last hour."
#
#       # Alert when memory usage is high
#       - alert: HighMemoryUsage
#         expr: (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes > 0.9
#         for: 5m
#         labels:
#           severity: critical
#         annotations:
#           summary: "High memory usage on {{ $labels.instance }}"
#           description: "Memory usage is above 90% on {{ $labels.instance }}."
#
#       # Alert when disk space is low
#       - alert: DiskSpaceLow
#         expr: (node_filesystem_avail_bytes / node_filesystem_size_bytes) < 0.1
#         for: 5m
#         labels:
#           severity: critical
#         annotations:
#           summary: "Low disk space on {{ $labels.instance }}"
#           description: "Disk space is below 10% on {{ $labels.instance }} mount {{ $labels.mountpoint }}."
#
#       # Alert when API latency is high
#       - alert: HighLatency
#         expr: histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m])) > 1
#         for: 5m
#         labels:
#           severity: high
#         annotations:
#           summary: "High latency on {{ $labels.job }}"
#           description: "99th percentile latency is above 1 second for {{ $labels.job }}."
#
#       # Alert when SSL certificate is expiring soon
#       - alert: SSLCertExpiringSoon
#         expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 7
#         for: 1h
#         labels:
#           severity: high
#         annotations:
#           summary: "SSL certificate expiring soon for {{ $labels.instance }}"
#           description: "SSL certificate for {{ $labels.instance }} expires in less than 7 days."
