Skip to content

Commit

Permalink
allow choosing attachment color
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancurrah committed May 1, 2020
1 parent 0c6392d commit 2f827fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ FROM alpine:latest as synology-notifications
EXPOSE 8080
ENV API_KEY=
ENV SLACK_WEBHOOK=
ENV SLACK_ATTACHMENT_COLOR=
ENV LISTEN_PORT=8080
RUN apk --no-cache add ca-certificates
COPY --from=builder synology-notifications/synology-notifications /
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# synology-notifications

Receive notifcations from Synology and forward them to the notifcation service of your choice
Receive notifications from Synology and forward them to the notification service of your choice

## Supported notifcation services
## Supported notification services

- Slack

## Service settings

Settings are supplied by setting envrionment variables
Settings are supplied by setting environment variables

- `API_KEY`: A minum of 32 character api key that Synology server needs to use to auth to this services api
- `API_KEY`: A minimum of 32 character api key that Synology server needs to use to auth to this services api
- `LISTEN_PORT`: Default `8080`. The port the service will listen on

## Slack settings

- `SLACK_WEBHOOK`: URL for the Slack web hook
- `SLACK_ATTACHMENT_COLOR`: Color to use for the attachments can use hex `#36a64f`

## Cmd

Expand All @@ -29,28 +30,28 @@ listening on port 8080
## Docker

```bash
docker run -e API_KEY='LO45UXS%amLAWJn6CwJ1koaXW&7pY9#Z' -e SLACK_WEBHOOK='https://slack.com/myWebHookUrl' ryancurrah/synology-notifications:latest
docker run -e API_KEY='LO45UXS%amLAWJn6CwJ1koaXW&7pY9#Z' -e SLACK_WEBHOOK='https://slack.com/myWebHookUrl' -p 8080:8080 ryancurrah/synology-notifications:latest
listening on port 8080
```

## Setting up Synology

1. Login to Diskstation
2. Go to `Control Pannel` > `Notification` > `SMS`
3. Check `Enable SMS Notifcations`
3. Check `Enable SMS Notifications`
4. Click `Add SMS Provider` to create a new SMS provider which will be the `synology-notifications` service. (**NOTE**: We will not actually be using `SMS`)
1. **Provider Name**: `synology-notifications`
2. **SMS URL**: `http://<ip address of synology-notifications service>:8080`
3. **HTTP Method**: `POST`
5. Click `Add` and set the `Parameter` to `api_key` and leave Value empty then click `Next`
6. Click `Add` and set the `Paramater` to `phone_number` and leave Value empty (**NOTE**: Synology requires this field to exist even though were not going to use it)
7. Click `Add` and set the `Paramater` to `message` set the Value to `Hello world` (Synology requires a sample value) and click `Next`
6. Click `Add` and set the `Parameter` to `phone_number` and leave Value empty (**NOTE**: Synology requires this field to exist even though were not going to use it)
7. Click `Add` and set the `Parameter` to `message` set the Value to `Hello world` (Synology requires a sample value) and click `Next`
8. Set the type of the `api_key` Parameter to `API Key`
9. Set the type of the `phone_number` Parameter to `Phone Number`
10. Set the type of the `message` Parameter to `Message content` and click `Apply`
11. Select `synology-notifications` from the `SMS service provider` dropdown
12. In the `API Key` field paste the API Key you choose for the service and click `Apply`
13. Test the notifcation service by clicking `Send a test SMS message`
13. Test the notification service by clicking `Send a test SMS message`

## Setting up Synology with screenshots

Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ type SynologyMessage struct {

type AppConfig struct {
ListenPort string `env:"LISTEN_PORT" envDefault:"8080"`
ApiKey string `env:"API_KEY,required"`
APIKey string `env:"API_KEY,required"`
}

type SlackConfig struct {
Webhook string `env:"SLACK_WEBHOOK,required"`
Color string `env:"SLACK_ATTACHMENT_COLOR" envDefault:"warning"`
}

// PostHandler send notifcations from synology to slack
// PostHandler send notifications from synology to slack
func PostHandler(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("api_key") != appConfig.ApiKey {
if r.Header.Get("api_key") != appConfig.APIKey {
http.Error(w, "invalid api key", http.StatusUnauthorized)
log.Printf("invalid api key")
return
Expand All @@ -51,7 +52,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
return
}

msg := slack.WebhookMessage{Attachments: []slack.Attachment{{Color: "warning", Text: fmt.Sprintf("%s", synologyMessage.Message)}}}
msg := slack.WebhookMessage{Attachments: []slack.Attachment{{Color: slackConfig.Color, Text: fmt.Sprintf("%s", synologyMessage.Message)}}}

err = slack.PostWebhook(slackConfig.Webhook, &msg)
if err != nil {
Expand All @@ -76,8 +77,8 @@ func main() {
panic(err)
}

if len(appConfig.ApiKey) < 32 {
panic(fmt.Errorf("api key not long enough it should be 32 characters long not %d", len(appConfig.ApiKey)))
if len(appConfig.APIKey) < 32 {
panic(fmt.Errorf("api key not long enough it should be 32 characters long not %d", len(appConfig.APIKey)))
}

mux := http.NewServeMux()
Expand Down

0 comments on commit 2f827fc

Please sign in to comment.