修改系统获取方式
This commit is contained in:
parent
e03f012a6c
commit
27b3bfacbd
|
@ -22,7 +22,11 @@ var (
|
|||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, err)
|
||||
if logger != nil {
|
||||
logger.With(zap.String("capture agent", "错误信息")).Error("启动错误", zap.Error(err))
|
||||
} else {
|
||||
_, _ = fmt.Fprint(os.Stderr, err)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +40,6 @@ func NewStartCmd() *cobra.Command {
|
|||
cfg *config.AgentConfig
|
||||
err error
|
||||
)
|
||||
//ctx, cancel := context.WithCancel(context.Background())
|
||||
//defer cancel()
|
||||
configFileFlag, err := cmd.Flags().GetString("c")
|
||||
if err != nil {
|
||||
fmt.Println("get local config err: ", err)
|
||||
|
@ -62,35 +64,26 @@ func NewStartCmd() *cobra.Command {
|
|||
)
|
||||
err = ap.Connect()
|
||||
must(err)
|
||||
//defer ap.Close()
|
||||
//for _, v := range cfg.Funcs {
|
||||
// ap.SetDataTag(v.DataTag)
|
||||
//}
|
||||
ap.SetDataTag(18)
|
||||
node := monitor.GetHost()
|
||||
byteNode := node.ToByte()
|
||||
_ = generateAndSendData(ap, byteNode)
|
||||
|
||||
ticker := time.NewTicker(time.Duration(cfg.Delay) * time.Second)
|
||||
statTicker := time.NewTicker(time.Duration(cfg.Delay) * time.Second)
|
||||
nodeTicker := time.NewTicker(1 * time.Hour)
|
||||
count := 0
|
||||
//c := cron.New()
|
||||
//spec := fmt.Sprintf("*/%d * * * * *", cfg.Delay)
|
||||
//_, err = c.AddFunc(spec, func() {
|
||||
// stat := monitor.GetState().ToByte()
|
||||
// _ = generateAndSendData(ap, stat)
|
||||
// logger.With(
|
||||
// zap.String("agent", "发送状态信息"),
|
||||
// )
|
||||
//})
|
||||
//must(err)
|
||||
//c.Start()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
case <-statTicker.C:
|
||||
stat := monitor.GetState(node.NodeName).ToByte()
|
||||
go func() {
|
||||
_ = generateAndSendData(ap, stat)
|
||||
}()
|
||||
case <-nodeTicker.C:
|
||||
nodeInfo := monitor.GetHost().ToByte()
|
||||
go func() {
|
||||
_ = generateAndSendData(ap, nodeInfo)
|
||||
}()
|
||||
case errs := <-exitChannel:
|
||||
count++
|
||||
if count > 3 {
|
4
main.go
4
main.go
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"environmentCaptureAgent/config/cmd"
|
||||
"environmentCaptureAgent/cmd"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
|
@ -21,7 +21,7 @@ func init() {
|
|||
func main() {
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprint(os.Stderr, err.Error())
|
||||
_, _ = fmt.Fprint(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type testSt struct {
|
||||
input string
|
||||
output string
|
||||
}
|
||||
|
||||
func TestNotification(t *testing.T) {
|
||||
cases := []testSt{
|
||||
{
|
||||
input: "103.80.236.249/d5ce:d811:cdb8:067a:a873:2076:9521:9d2d",
|
||||
output: "103.****.249/d5ce:d811:****:9521:9d2d",
|
||||
},
|
||||
{
|
||||
input: "3.80.236.29/d5ce::cdb8:067a:a873:2076:9521:9d2d",
|
||||
output: "3.****.29/d5ce::****:9521:9d2d",
|
||||
},
|
||||
{
|
||||
input: "3.80.236.29/d5ce::cdb8:067a:a873:2076::9d2d",
|
||||
output: "3.****.29/d5ce::****::9d2d",
|
||||
},
|
||||
{
|
||||
input: "3.80.236.9/d5ce::cdb8:067a:a873:2076::9d2d",
|
||||
output: "3.****.9/d5ce::****::9d2d",
|
||||
},
|
||||
{
|
||||
input: "3.80.236.9/d5ce::cdb8:067a:a873:2076::9d2d",
|
||||
output: "3.****.9/d5ce::****::9d2d",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
assert.Equal(t, IPDesensitize(c.input), c.output)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue