-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
144 lines (116 loc) · 3.45 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
logging "github.com/ipfs/go-log/v2"
"github.com/llifezou/ssv-notify/config"
"github.com/llifezou/ssv-notify/notify"
"github.com/llifezou/ssv-notify/ssv/liquidation"
"github.com/llifezou/ssv-notify/ssv/operator"
"github.com/spf13/cobra"
"os"
"os/signal"
"syscall"
)
var log = logging.Logger("main")
var (
configPath string
dir string
)
var rootCmd = &cobra.Command{
Use: "ssv-notify",
Short: "ssv-notify",
Long: `ssv monitoring notifications.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
},
}
func init() {
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "./config/config.yaml", "Path to configuration file")
scanClusterCmd.PersistentFlags().StringVarP(&dir, "dir", "d", "", "Save scan results")
}
func main() {
_ = logging.SetLogLevel("*", "INFO")
ssvToolsCmd.AddCommand(scanClusterCmd)
rootCmd.AddCommand(operatorMonitorCmd, liquidationMonitorCmd, liquidationBotCmd, ssvToolsCmd, AlarmTestCmd)
_ = rootCmd.Execute()
}
var liquidationMonitorCmd = &cobra.Command{
Use: "liquidation-monitor",
Short: "liquidation monitor",
Example: "./ssv-notify liquidation-monitor",
Run: func(cmd *cobra.Command, args []string) {
config.Init(configPath)
log.Info("liquidation monitor service start")
var shutdown = make(chan struct{})
go liquidation.StartLiquidationMonitor(shutdown)
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
close(shutdown)
log.Info("liquidation monitor service shutting down")
},
}
var operatorMonitorCmd = &cobra.Command{
Use: "operator-monitor",
Short: "operator monitor",
Example: "./ssv-notify operator-monitor",
Run: func(cmd *cobra.Command, args []string) {
config.Init(configPath)
log.Info("operator monitor service start")
var shutdown = make(chan struct{})
go operator.StartOperatorMonitor(shutdown)
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
close(shutdown)
log.Info("operator monitor service shutting down")
},
}
var ssvToolsCmd = &cobra.Command{
Use: "ssv-tools",
Short: "ssv tools",
Long: `./ssv-notify ssv-tools -h`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
},
}
var scanClusterCmd = &cobra.Command{
Use: "scan-cluster",
Short: "Scan cluster and calculate operational runway",
Example: "./ssv-notify ssv-tools scan-cluster",
Run: func(cmd *cobra.Command, args []string) {
config.Init(configPath)
log.Info("Start scanning")
err := liquidation.ScanAllSSVCluster(dir)
if err != nil {
log.Warnw("ScanAllSSVCluster failed", "err", err)
}
},
}
var AlarmTestCmd = &cobra.Command{
Use: "alarm-test",
Short: "Test alarms can be used",
Example: "./ssv-notify alarm-test",
Run: func(cmd *cobra.Command, args []string) {
config.Init(configPath)
log.Info("Start alarm test")
notifyClient, err := notify.NewNotify()
if err != nil {
log.Warn(err)
}
notifyClient.Send("alarm test!")
},
}
var liquidationBotCmd = &cobra.Command{
Use: "liquidation-bot",
Short: "liquidation bot",
Example: "./ssv-notify liquidation-bot",
Run: func(cmd *cobra.Command, args []string) {
config.Init(configPath)
log.Info("liquidation bot start")
var shutdown = make(chan struct{})
go liquidation.StartLiquidationBot(shutdown)
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
close(shutdown)
log.Info("liquidation bot shutting down")
},
}