mirror of https://github.com/certusone/santa.git
append webhook feature
This commit is contained in:
parent
83f4a3be35
commit
da30e9987f
|
@ -27,6 +27,9 @@ var configCmd = &cobra.Command{
|
|||
|
||||
TriggerInterval: "5",
|
||||
FeeAmount: "1000000uluna",
|
||||
|
||||
WebHookURL: "",
|
||||
WebHookDataKey: "text",
|
||||
}
|
||||
|
||||
if _, err := os.Stat(g.KeyDir); os.IsNotExist(err) {
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue