Skip to content

Commit bf2fe64

Browse files
author
Matthew Peck
committed
add docker bits and readme
1 parent 6ced45d commit bf2fe64

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM alpine:3.3
2+
3+
RUN apk -U add ca-certificates ruby ruby-bundler ruby-dev ruby-io-console ruby-builder ruby-irb ruby-rdoc ruby-json build-base git
4+
5+
# Setup bundle user and directory
6+
RUN adduser -h /home/bundle -D bundle && \
7+
mkdir -p /home/bundle && \
8+
chown -R bundle /home/bundle
9+
10+
# Copy the bundle source to the image
11+
WORKDIR /home/bundle
12+
COPY . /home/bundle
13+
14+
# Install the bundle, and remove git and the build tooling to recover
15+
# some space
16+
RUN su bundle -c 'bundle install --path .bundle' && \
17+
apk del build-base && \
18+
apk del git && \
19+
rm -f /var/cache/apk/*
20+
21+
# Drop privileges
22+
USER bundle

README.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
`pagerduty`: The Cog PagerDuty Command Bundle
2+
=========================================
3+
4+
# TL;DR
5+
6+
!pagerduty:alert Customers complaining the site is down. Need help in #support
7+
!pagerduty:oncall
8+
!pagerduty:incidents
9+
!pagerduty:ack PHNRH53
10+
!pagerduty:resolve PHNRH53
11+
12+
# Overview
13+
14+
The `pagerduty` bundle adds five new commands: ack, resolve, alert, incidents
15+
and oncall.
16+
17+
* ack - Acknowledge triggered incidents
18+
`ack [-a | --as <pagerduty user email>] <incident id>`
19+
`ack` requires a pagerduty user's email address to acknowledge an
20+
incident. If `--as` is not passed ack will first look for an env
21+
var called `PAGERDUTY_EMAIL_FOR_<COG USER>` where `COG USER` is
22+
the Cog username for the user making the request. If that var
23+
isn't found it will fall back to `PAGERDUTY_DEFAULT_EMAIL`. If
24+
neither are found the command will fail.
25+
* resolve - Resolve incidents
26+
`resolve [-a | --as <pagerduty user email>] <incident id>`
27+
`resolve` works identically to `ack`. First looking for
28+
`PAGERDUTY_EMAIL_FOR_<COG USER>` and then `PAGERDUTY_DEFAULT_EMAIL`.
29+
* alert - Trigger an incident on a specific service.
30+
`alert [-s | --service <service name>] <msg>`
31+
Optionally you can set the `PAGERDUTY_DEFAULT_SERVICE_KEY` env var.
32+
`alert` will then trigger incidents on that service when no service
33+
is passed.
34+
* incidents - Get a list of incidents
35+
`incidents [-a | --acked] [-t | --triggered] [-r | --resolved] [-l | --limit]`
36+
Get a list of incidents based on the option or options passed. By default
37+
incidents will return only incidents in the `triggered` state.
38+
* oncall - Get a list of services with the current primary oncall
39+
`oncall [service name]`
40+
If a service is passed only the oncall for that service will be returned.
41+
Otherwise a list of services with their corresponding user will be returned.
42+
43+
# Permissions
44+
45+
pagerduty comes bundles with three permissions: pagerduty:alert, pagerduty:read,
46+
pagerduty:write. By default `oncall` is 'allowed'. To `alert` you will need the
47+
pagerduty:alert permission. To see incidents, pagerduty:read. And to `ack` or
48+
`resolve`, pagerduty:write.
49+
50+
# Configuration
51+
52+
pagerduty uses a few env vars to configure it. All commands require
53+
`PAGERDUTY_ACCOUNT_SUBDOMAIN` and `PAGERDUTY_ACCOUNT_TOKEN` to be set. That would
54+
be the subdomain for your PagerDuty account and the api token respectively.
55+
56+
`alert` has an optional var, `PAGERDUTY_DEFAULT_SERVICE_KEY`. This is the integration
57+
key found on the integration tab for the service on PagerDuty's web ui. If set, any
58+
alerts that don't specify a service will be sent here. Note that if the service key
59+
is not set or a service isn't passed to the command, it will fail.
60+
61+
`ack` and `resolve` have a couple extra vars. `PAGERDUTY_DEFAULT_EMAIL`, similar to
62+
`PAGERDUTY_DEFAULT_SERVICE_KEY`, `ack` and `resolve` will use this email as the
63+
requester when acking or resolving incidents. Additionally you may attach the
64+
requester to cog accounts. Using vars in the form, `PAGERDUTY_EMAIL_FOR_<COG USER>`
65+
you can specify which PagerDuty email is associated with which Cog user. So for
66+
example, if your Cog username is 'bob', you would set the var `PAGERDUTY_EMAIL_FOR_BOB`.
67+
Then whenever you `ack` or `resolve` the proper PagerDuty account is associated with the
68+
action.
69+
70+
# Installing
71+
72+
curl -O https://github.com/cogcmd/pagerduty/blob/master/config.yaml
73+
cogctl bundle install config.yaml
74+
75+
# Building
76+
77+
To build the Docker image, simply run:
78+
79+
$ rake image
80+
81+
Requires Docker and Rake.
82+

Rakefile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'yaml'
2+
3+
# Make sure we're running from the directory the Rakefile lives in since
4+
# many things (ie: docker build, config reading) use relative paths.
5+
Dir.chdir(File.dirname(__FILE__))
6+
7+
BUNDLE_CONFIG = YAML.load(File.read("config.yaml"))
8+
BUNDLE_IMAGE = "#{BUNDLE_CONFIG['docker']['image']}:#{BUNDLE_CONFIG['docker']['tag']}"
9+
10+
task :image do |t|
11+
args = [ "build", "-t", BUNDLE_IMAGE, "." ]
12+
sh "docker", *args
13+
end
14+
15+
task :push => [:image] do |t|
16+
args = [ "push", BUNDLE_IMAGE ]
17+
sh "docker", *args
18+
end

config.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
cog_bundle_version: 3
33

44
name: pagerduty
5-
version: 0.1.0
5+
version: 0.0.1
66
description: Interact with the pagerduty
7+
docker:
8+
image: cogcmd/pagerduty
9+
tag: 0.0.1
710
permissions:
811
- pagerduty:read
912
- pagerduty:write
@@ -83,7 +86,7 @@ commands:
8386
resolve:
8487
executable: /Users/mpeck/op/pagerduty/cog-command
8588
documentation: |
86-
pagerduty:resolve <incident id> - Resovle the incident
89+
pagerduty:resolve <incident id> - Resolve the incident
8790
pagerduty:resolve [-a | --as <pagerduty user email>] <incident id> Resolve the incident as the account specified by the email
8891
8992
Returns confirmation of resolution

0 commit comments

Comments
 (0)