Skip to content

Commit 14eed06

Browse files
chrisobjpweber
authored andcommitted
Extract Slack webhook values to config (#6)
* Fix Dockerfile build paths Signed-off-by: Chris O'Brien <chrisob91@gmail.com> * Move Slack webhook config to env vars Signed-off-by: Chris O'Brien <chrisob91@gmail.com> * Add new env vars to README Signed-off-by: Chris O'Brien <chrisob91@gmail.com>
1 parent 6968124 commit 14eed06

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM golang:1.11.3-alpine3.8 AS build
2-
COPY . /go/src/app
2+
COPY . /go/src/github.com/jpweber/cole
33

4-
WORKDIR /go/src/app
4+
WORKDIR /go/src/github.com/jpweber/cole
55
RUN apk --update upgrade && \
66
apk add ca-certificates && \
77
update-ca-certificates && \
@@ -15,5 +15,5 @@ RUN apk --update upgrade && \
1515
apk add ca-certificates && \
1616
update-ca-certificates && \
1717
rm -rf /var/cache/apk/*
18-
COPY --from=build /go/src/app/app /cole
18+
COPY --from=build /go/src/github.com/jpweber/cole/app /cole
1919
CMD ["/cole"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ There is a forthcoming blog post on [jpweber.io](http://jpweber.io/blog
6666
# Interval = 10
6767
# HTTPEndpoint = "https://hooks.slack.com/services/..."
6868
# HTTPMethod = "POST"
69+
# SlackChannel = "#general"
70+
# SlackUsername = "Cole - DeadManSwitch Monitor"
71+
# SlackIcon = ":monkey_face:"
6972

7073

7174
# PagerDuty
@@ -83,6 +86,9 @@ PDIntegrationKey = "5353fb993888441811111111111"
8386
* `HTTP_METHOD`
8487
* `EMAIL_ADDR`
8588
* `PD_KEY`
89+
* `SLACK_CHANNEL`
90+
* `SLACK_USERNAME`
91+
* `SLACK_ICON`
8692
8793
## Example Prometheus Alert Manager config
8894

configuration/configuration.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type Conf struct {
1414
HTTPMethod string `env:"HTTP_METHOD" envDefault:"POST"`
1515
EmailAddress string `env:"EMAIL_ADDR"`
1616
PDIntegrationKey string `env:"PD_KEY"`
17+
SlackChannel string `env:"SLACK_CHANNEL" envDefault:"#general"`
18+
SlackUsername string `env:"SLACK_USERNAME" envDefault:"Cole - DeadManSwitch Monitor"`
19+
SlackIcon string `env:"SLACK_ICON" envDefault:":monkey_face:"`
1720
}
1821

1922
// Reads info from config file

notifier/notifier.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func (n *NotificationSet) slack() {
7979
log.Println("slack method")
8080
payload := slack.Payload{
8181
Text: "Missed DeadManSwitch Alert - " + n.Message.CommonAnnotations["message"],
82-
Username: "Cole - DeadManSwitch Monitor",
83-
Channel: "#general",
84-
IconEmoji: ":monkey_face:",
82+
Username: n.Config.SlackUsername,
83+
Channel: n.Config.SlackChannel,
84+
IconEmoji: n.Config.SlackIcon,
8585
}
8686
jsonBody, err := json.Marshal(payload)
8787
if err != nil {

0 commit comments

Comments
 (0)