Skip to content

Commit

Permalink
Better text messages and some logging for nexmo
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Corso committed Nov 21, 2016
1 parent dfb32e9 commit 9ecd3e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ _testmain.go
config.yaml

gin-bin
bin
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ func main() {
return
}

// Concatenate common labels to form the alert string.
text := strings.Join(data.CommonLabels.Values(), " | ")
if len(text) > 160 {
text = text[:160]
var text string
if len(data.Alerts) > 1 {
text = fmt.Sprintf("Firing: %d, Resolved: %d", len(data.Alerts.Firing()), len(data.Alerts.Resolved()))
} else if len(data.Alerts) == 1 {
alert := data.Alerts[0]
tuples := []string{}
for k, v := range alert.Labels {
tuples = append(tuples, k+"= "+v)
}
text = strings.ToUpper(data.Status) + " \n" + strings.Join(tuples, "\n")
} else {
text = "Alert \n" + strings.Join(data.CommonLabels.Values(), " | ")
}

message := Message{
Expand Down
15 changes: 13 additions & 2 deletions nexmo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main

import "gopkg.in/njern/gonexmo.v1"
import (
"encoding/json"
"log"

"gopkg.in/njern/gonexmo.v1"
)

type Nexmo struct{}

Expand All @@ -19,7 +24,13 @@ func (*Nexmo) Send(message Message) (err error) {
Text: message.Text,
Class: nexmo.Standard,
}
_, err = nexmoClient.SMS.Send(msg)
response, err := nexmoClient.SMS.Send(msg)
if err != nil {
return err
}

js0n, _ := json.Marshal(response)
log.Println(string(js0n))
}
return
}

0 comments on commit 9ecd3e4

Please sign in to comment.