Update Slack usergroups based on PagerDuty schedules
10K+
Update your Slack user groups based on your PagerDuty Schedules.
Provided with API credentials and some configuration, PagerBot will automatically update Slack user group membership and post a message to channels you select informing everyone who's currently on the rotation.
PagerBot matches PagerDuty users to Slack users by their email addresses, so your users must have the same email address in Slack as in PagerDuty. PagerBot will log warnings for any users it finds in PagerDuty but not in Slack.
Use goenv to install dependencies:
goenv local
Compile the pagerbot binary:
go build
You should have a nice pagerbot binary ready to go.
Cross-compiling can be done with gox:
# install gox
go get github.com/mitchellh/gox
# build binaries
gox -osarch "linux/amd64" -ldflags "-extldflags '-static'" -output "dist/{{.OS}}_{{.Arch}}/pagerbot"
You can also download pre-built binaries from the releases page.
OAuth & Permissions:
OAuth Access Token (requires workspace admin)echo "SLACK_TOKEN=<token>" >> .secrets.envecho "PAGERDUTY_KEY=<key>" >> .secrets.envecho "PAGERDUTY_ORG=<org>" >> .secrets.envA basic configuration file will look like
api_keys:
slack: "$SLACK_TOKEN" # Slack OAuth Access Token
pagerduty:
org: "$PAGERDUTY_ORG" # PagerDuty subdomain
key: "$PAGERDUTY_KEY" # PagerDuty API key
groups:
- name: firefighter # name of the Slack user group to update
schedules: # one or more PagerDuty schedule IDs
- PAAAAAA
- PBBBBBB
update_message: # optional update message (%s is a comma delimited members list)
message: ":fire_engine: @paas-oncall shift change: %s :fire_engine:"
channels: # one or more channels to post the message to
- paas
This config specifies the use of environment variables which pagerbot will interpolate at runtime, allowing you to inject secrets and env vars.
Specify the config when launching pagerbot:
./pagerbot --config /path/to/config.yml --env-file /path/to/.secrets.env
It's recommended to run PagerBot using a package manager or container platform.
The included Dockerfile uses a multi-stage build to compile pagebot and package it in a small alpine-based Docker image for use in production:
# build and tag image
docker build -t karlkfi/pagerbot:latest .
# run locally in docker
docker run --env-file .secrets.env karlkfi/pagerbot:latest
# push to a docker image registry
docker push karlkfi/pagerbot:latest
Once a Docker image is built, it can be deployed to Kubernetes using encrypted secret management:
# interpolate and base64 encode the secrets into a k8s secret
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: pagerbot-secrets
type: Opaque
data:
slack-token: "$(grep 'SLACK_TOKEN' .secrets.env | cut -d'=' -f2 | tr -d '\n' | base64)"
pagerduty-key: "$(grep 'PAGERDUTY_KEY' .secrets.env | cut -d'=' -f2 | tr -d '\n' | base64)"
pagerduty-org: "$(grep 'PAGERDUTY_ORG' .secrets.env | cut -d'=' -f2 | tr -d '\n' | base64)"
EOF
# create pagerbot deployment
kubectl apply -f deployments/kubernetes/deployment.yml
Content type
Image
Digest
Size
6 MB
Last updated
over 6 years ago
docker pull karlkfi/pagerbot