Merge pull request #9 from terra-project/develop

[Feature] append webhook feature
This commit is contained in:
yys 2019-08-09 12:37:42 +09:00 committed by GitHub
commit 4eb07ae492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -27,6 +27,9 @@ var configCmd = &cobra.Command{
TriggerInterval: "5",
FeeAmount: "1000000uluna",
WebHookURL: "",
WebHookDataKey: "text",
}
if _, err := os.Stat(g.KeyDir); os.IsNotExist(err) {

View File

@ -39,6 +39,9 @@ type SantaApp struct {
TriggerInterval string `json:"trigger_interval" yaml:"trigger_interval"`
FeeAmount string `json:"fee_amount" yaml:"fee_amount"`
WebHookURL string `json:"webhook_url" yaml:"webhook_url"`
WebHookDataKey string `json:"webhook_data_key" yaml:"webhook_data_key"`
Version string `yaml:"version,omitempty"`
Commit string `yaml:"commit,omitempty"`
Branch string `yaml:"branch,omitempty"`

View File

@ -1,8 +1,11 @@
package utils
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"os"
"strconv"
@ -80,6 +83,21 @@ func (app SantaApp) ListenNewBLock(isTest bool) {
txHash, err := app.SendTx(blockEvent.Block.ChainID)
if err != nil {
log.Printf("[Fail] to send tx: %s", err.Error())
if app.WebHookURL != "" && app.WebHookDataKey != "" {
notiBody, err := json.Marshal(map[string]string{
app.WebHookDataKey: fmt.Sprintf("[Fail] sending tx: %s", err.Error()),
})
if err != nil {
continue
}
// send notification to slack
http.Post(app.WebHookURL, "application/json", bytes.NewBuffer(notiBody))
continue
}
}
log.Printf("[Success] Height: %d,\tTxHash: %s\n", blockEvent.Block.Height, txHash)