Skip to content

Deploying Grafana OnCall (self-hosted) on Ubuntu 22.04 with Slack and SMS

Stand up self-hosted Grafana OnCall on Ubuntu 22.04 — Docker compose stack with Postgres, Redis, RabbitMQ, web UI, engine, plus Slack OAuth and Twilio SMS integration.

The first 2 a.m. page goes to whoever happened to be on the channel. You all agree to set up a rotation. Three weeks later there’s another incident — somebody was meant to be primary but their phone was on Do Not Disturb, the backup was on vacation, and the alert sat unacknowledged for 45 minutes. The post-mortem says “build a real on-call system.” You look at PagerDuty pricing per user per month and at the data-residency clause in your contract, and decide self-hosting is the path. Grafana OnCall, self-hosted, gives you rotations, escalation policies, Slack acknowledgement, SMS and voice via Twilio, and direct integration with your existing alerting stack — without the data-residency headache and without per-seat billing surprises.

What’s happening

Grafana OnCall has two halves: a Django-based engine that ingests alerts (from Grafana, Prometheus Alertmanager, generic webhooks), evaluates routing rules, runs the escalation policy, calls users via Twilio, and posts to Slack; and a React frontend that lives at /a/grafana-oncall-app/ inside Grafana itself. Behind the engine you need Postgres (state), Redis (caching + rate limits), RabbitMQ (Celery task queue for delayed escalations), and a worker pool. A Docker Compose deployment is the supported single-host topology — adequate for a team of 5-30 on-call engineers, low operational complexity.

The data residency story matters here: SMS and voice go out through Twilio (or your chosen provider), but the alert content, rotations, and audit history stay on your VM. The phone numbers configured for users are stored in your database, not in a vendor cloud.

How to verify

OnCall engine is healthy:

curl -s http://10.50.0.41:8080/health/
# expect: {"status": "OK"}

A test webhook reaches OnCall — pick one integration in the UI, copy its URL, then:

curl -X POST 'https://oncall.example.com/integrations/v1/webhook/<INTEGRATION_KEY>/' \
  -H 'Content-Type: application/json' \
  -d '{"alert_uid":"test-1","title":"Synthetic test","message":"Ignoring"}'

You should see the alert in the OnCall UI within 10 seconds and a corresponding Slack message if Slack is wired.

Twilio outbound — pick a test user, edit their notification policy to “SMS immediately”, and trigger the synthetic alert. Twilio’s logs at /Monitor/Logs/SMS show the outbound request and the carrier delivery status.

The fix

Save as /root/setup-oncall.sh and run on a fresh Ubuntu 22.04 VM. Installs Docker, generates secrets, writes the compose stack, configures NGINX with TLS in front, opens UFW. Slack OAuth and Twilio credentials are filled in after the stack is up via the OnCall admin UI.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Grafana OnCall self-hosted installer
### Docker Compose: engine + celery + postgres + redis + rabbitmq + web
### NGINX TLS front, UFW restrictive

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

# === EDIT ===
NODE_IP="10.50.0.41"
PUBLIC_DOMAIN="oncall.example.com"
GRAFANA_DOMAIN="grafana.example.com"
ONCALL_VERSION="v1.10.0"
ADMIN_EMAIL="ops@example.com"
# =============

echo
echo "========================================"
echo "Grafana OnCall ${PUBLIC_DOMAIN}"
echo "========================================"

export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y dist-upgrade
apt-get -y install curl wget ca-certificates gnupg lsb-release \
  ufw fail2ban unattended-upgrades chrony jq tar gzip \
  iproute2 net-tools dnsutils socat nginx certbot python3-certbot-nginx \
  htop iotop apt-transport-https

systemctl enable --now chrony

echo "==> Docker"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker

echo "==> UFW"
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable

echo "==> SSH hardening"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
systemctl restart ssh

cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban

cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTO'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
AUTO

mkdir -p /opt/oncall
cd /opt/oncall

echo "==> Generating secrets"
SECRET_KEY=$(openssl rand -hex 32)
MIRAGE_SECRET_KEY=$(openssl rand -hex 32)
DB_PASSWORD=$(openssl rand -hex 16)
RMQ_PASSWORD=$(openssl rand -hex 16)
REDIS_PASSWORD=$(openssl rand -hex 16)

cat > .env <<EOF
DOMAIN=${PUBLIC_DOMAIN}
BASE_URL=https://${PUBLIC_DOMAIN}
GRAFANA_DOMAIN=${GRAFANA_DOMAIN}
ONCALL_VERSION=${ONCALL_VERSION}

SECRET_KEY=${SECRET_KEY}
MIRAGE_SECRET_KEY=${MIRAGE_SECRET_KEY}
MIRAGE_CIPHER_IV=1234567890abcdef

DATABASE_TYPE=postgresql
DB_NAME=oncall
DB_USER=oncall
DB_PASSWORD=${DB_PASSWORD}
DB_HOST=postgres
DB_PORT=5432

REDIS_URI=redis://:${REDIS_PASSWORD}@redis:6379/0

RABBITMQ_URI=amqp://oncall:${RMQ_PASSWORD}@rabbitmq:5672

FEATURE_LIVE_SETTINGS_ENABLED=True
FEATURE_TELEGRAM_INTEGRATION_ENABLED=False
FEATURE_SLACK_INTEGRATION_ENABLED=True

# Filled in via the OnCall admin UI after first boot:
# TWILIO_ACCOUNT_SID
# TWILIO_AUTH_TOKEN
# TWILIO_NUMBER
# SLACK_CLIENT_OAUTH_ID
# SLACK_CLIENT_OAUTH_SECRET
# SLACK_SIGNING_SECRET
EOF
chmod 600 .env

echo "==> Writing compose file"
cat > compose.yml <<'COMPOSE'
services:
  postgres:
    image: postgres:15
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"]
      interval: 10s
      timeout: 5s
      retries: 10

  redis:
    image: redis:7
    restart: unless-stopped
    command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"]
    volumes:
      - redis_data:/data

  rabbitmq:
    image: rabbitmq:3.13-management
    restart: unless-stopped
    environment:
      RABBITMQ_DEFAULT_USER: oncall
      RABBITMQ_DEFAULT_PASS: ${RMQ_PASSWORD}
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq

  engine:
    image: grafana/oncall:${ONCALL_VERSION}
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
      rabbitmq:
        condition: service_started
    env_file: .env
    command: ["sh", "-c", "uwsgi --ini uwsgi.ini"]
    ports:
      - "127.0.0.1:8080:8080"

  celery:
    image: grafana/oncall:${ONCALL_VERSION}
    restart: unless-stopped
    depends_on:
      - engine
    env_file: .env
    command: ["sh", "-c", "./celery_with_exporter.sh"]

  oncall_db_migration:
    image: grafana/oncall:${ONCALL_VERSION}
    depends_on:
      postgres:
        condition: service_healthy
    env_file: .env
    command: ["python", "manage.py", "migrate", "--noinput"]
    restart: on-failure

volumes:
  postgres_data:
  redis_data:
  rabbitmq_data:
COMPOSE

echo "==> Pulling images"
docker compose pull

echo "==> Running DB migration"
docker compose run --rm oncall_db_migration

echo "==> Starting stack"
docker compose up -d

echo "==> Waiting for engine"
for i in {1..90}; do
  if curl -fs http://127.0.0.1:8080/health/ >/dev/null 2>&1; then break; fi
  sleep 2
done

echo "==> NGINX TLS"
cat > /etc/nginx/sites-available/oncall <<EOF
server {
  listen 80;
  server_name ${PUBLIC_DOMAIN};
  location /.well-known/acme-challenge/ { root /var/www/html; }
  location / { return 301 https://\$host\$request_uri; }
}

server {
  listen 443 ssl http2;
  server_name ${PUBLIC_DOMAIN};
  ssl_certificate /etc/letsencrypt/live/${PUBLIC_DOMAIN}/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/${PUBLIC_DOMAIN}/privkey.pem;
  ssl_protocols TLSv1.2 TLSv1.3;

  client_max_body_size 50m;
  proxy_read_timeout 120s;

  # Webhook integrations
  location /integrations/ {
    proxy_set_header Host \$host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_pass http://127.0.0.1:8080;
  }

  # Slack interactivity callback
  location /api/internal/v1/slack/ {
    proxy_set_header Host \$host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_pass http://127.0.0.1:8080;
  }

  # Everything else (API + admin)
  location / {
    proxy_set_header Host \$host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_pass http://127.0.0.1:8080;
  }
}
EOF
ln -sf /etc/nginx/sites-available/oncall /etc/nginx/sites-enabled/oncall
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl reload nginx

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
docker compose ps
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|8080)\b' || true
echo
echo "Next: certbot --nginx -d ${PUBLIC_DOMAIN}"
echo "Then in Grafana, install the OnCall plugin and point it at:"
echo "  https://${PUBLIC_DOMAIN}/api/internal/v1/"

After the stack is up and TLS is issued, install the OnCall plugin in Grafana:

grafana-cli plugins install grafana-oncall-app
systemctl restart grafana-server

In Grafana, go to Plugins → OnCall → Configuration. Paste the OnCall API URL (https://oncall.example.com/api/internal/v1/) and the auto-generated invitation token (visible in the OnCall engine logs on first boot: docker compose logs engine | grep "INVITATION TOKEN"). Grafana and OnCall now share user identity via Grafana’s existing SSO.

Slack integration

Create a Slack app at api.slack.com/apps → “From an app manifest”. The manifest:

display_information:
  name: Grafana OnCall
features:
  bot_user:
    display_name: Grafana OnCall
    always_online: true
oauth_config:
  redirect_urls:
    - https://oncall.example.com/api/internal/v1/slack/install/
  scopes:
    bot:
      - chat:write
      - chat:write.public
      - im:write
      - im:history
      - groups:write
      - users:read
      - users:read.email
      - team:read
      - channels:read
      - channels:history
      - reactions:write
settings:
  interactivity:
    is_enabled: true
    request_url: https://oncall.example.com/api/internal/v1/slack/interactive_api_endpoint/
  event_subscriptions:
    request_url: https://oncall.example.com/api/internal/v1/slack/event_api_endpoint/
    bot_events:
      - app_mention
      - message.channels
      - message.im

In the OnCall web UI → Environment → Slack: paste the OAuth Client ID, Client Secret, and Signing Secret from the Slack app’s “Basic Information” tab. Hit Save, then “Connect Slack workspace” — OAuth confirms the install.

Twilio integration

In OnCall web UI → Environment → Phone calls / SMS:

Twilio Account SID:  ACxxxxxxxxxxxxxxxxxxxxxxx
Twilio Auth Token:   xxxxxxxxxxxxxxxxxxxxxx
Twilio number:       +1xxxxxxxxxx
Twilio Verify SID:   VAxxxxxxxxxxxxxxxxxxxx  (optional, for E.164 verification)

In Twilio’s console, set the messaging webhook for that number to https://oncall.example.com/api/internal/v1/twilioapp/sms/ (so SMS acknowledgements route back). Voice webhook: https://oncall.example.com/api/internal/v1/twilioapp/voice/.

Wiring Prometheus Alertmanager

In OnCall, create an integration of type “Alertmanager” — it generates a unique webhook URL like https://oncall.example.com/integrations/v1/alertmanager/<KEY>/. In Alertmanager:

route:
  receiver: oncall
  group_by: [alertname, severity]
  group_wait: 10s
  group_interval: 30s
  repeat_interval: 4h

receivers:
  - name: oncall
    webhook_configs:
      - url: https://oncall.example.com/integrations/v1/alertmanager/<KEY>/
        send_resolved: true

Create a schedule (Schedules → New), a rotation (typically 1-week primary/secondary alternating), an escalation chain (“Page primary → wait 5 min → notify secondary → wait 5 min → mass-page channel”), and route the Alertmanager integration to that escalation chain. The first synthetic test should now ring your phone within 30 seconds of an unacknowledged alert.

Run paging and on-call orchestration on Stack Harbor’s managed cloud compute with rotation review, Slack workspace integration, and Twilio cost monitoring under environment management — or scope it together if you want the on-call infrastructure built and operated for you.