diff options
author | Huang, Jhih-Ming <jm@byzantine-lab.io> | 2020-08-17 18:33:28 +0800 |
---|---|---|
committer | Huang, Jhih-Ming <jm@byzantine-lab.io> | 2020-08-17 18:56:54 +0800 |
commit | 00c26ac3565cbf44364c67e42c2f76a29448f223 (patch) | |
tree | 3bf7d33c6e65b75a44240305c02e4f00dc0b9746 | |
parent | 25acfea5a4dbe1c135f171dd54bcdfca7bdb9df8 (diff) | |
download | tangerine-monitor-00c26ac3565cbf44364c67e42c2f76a29448f223.tar.gz tangerine-monitor-00c26ac3565cbf44364c67e42c2f76a29448f223.tar.zst tangerine-monitor-00c26ac3565cbf44364c67e42c2f76a29448f223.zip |
add skip list
-rw-r--r-- | main.go | 25 | ||||
-rw-r--r-- | monitor/notifier.go | 9 |
2 files changed, 33 insertions, 1 deletions
@@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strconv" + "bufio" "github.com/urfave/cli" "github.com/tangerine-network/tan-monitor/monitor" @@ -22,7 +23,20 @@ func init() { commandStart, } } +func getLines(path string) ([]string, error) { + file, err := os.Open(path) + if err != nil { + return nil, err + } + defer file.Close() + var lines []string + scanner := bufio.NewScanner(file) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + return lines, scanner.Err() +} var commandStart = cli.Command{ Name: "start", Usage: "Start monitor job", @@ -40,6 +54,11 @@ var commandStart = cli.Command{ Value: "./cc.txt", Usage: "Path to the cc list", }, + cli.StringFlag{ + Name: "skipList", + Value: "./skip-list.txt", + Usage: "Path to the skip list", + }, }, Action: func(ctx *cli.Context) error { if len(ctx.Args()) != 2 { @@ -55,6 +74,11 @@ var commandStart = cli.Command{ panic(err) } ccList, _ := ioutil.ReadFile(ctx.String("ccList")) + skipList, _ := getLines(ctx.String("skipList")) + fmt.Println("skip list:") + for _, skip := range skipList { + fmt.Println(skip) + } backend := monitor.NewBlockchainBackend(networkID) m := monitor.NewMonitor(networkID, backend, threshold) email := monitor.NewEmail( @@ -62,6 +86,7 @@ var commandStart = cli.Command{ string(emailPassword), "smtp-relay.gmail.com", string(ccList), + skipList, ) m.Register(email) m.Run() diff --git a/monitor/notifier.go b/monitor/notifier.go index 1db570d..e9cbfff 100644 --- a/monitor/notifier.go +++ b/monitor/notifier.go @@ -32,15 +32,17 @@ type Email struct { password string smtpServer string ccList string + skipList []string } // NewEmail is the Email constructor. -func NewEmail(sender, password, server, ccList string) Notifier { +func NewEmail(sender, password, server, ccList string, skipList []string) Notifier { e := Email{ sender: sender, password: password, smtpServer: server, ccList: ccList, + skipList: skipList, } return &e } @@ -48,6 +50,11 @@ func NewEmail(sender, password, server, ccList string) Notifier { func (e *Email) notify(n node, network string, notifyType uint, threshold string) { var subj string var body string + for _, skip := range e.skipList { + if(skip == n.email) { + return + } + } switch notifyType { case FINED: subj = "[Notification] Your Tangerine " + network + " Network Full Node is Fined" |