package job

import (
	"fmt"
	"git.quantgroup.cn/DevOps/enoch/service/alarm"
	"github.com/robfig/cron"
	"github.com/vrg0/go-common/logger"
	"net"
	"os"
	"time"
)

/**
	报警定时任务，每分钟执行一次
 */
func AutoAlarm() {
	c := cron.New()

	err := c.AddFunc("@every 1m", func() {
		logger.Info("开始执行定时任务", time.Now().Minute())
		alarm.Load()
	})
	if err != nil {
		fmt.Print("err")
	}

	c.Start()
}

func CheckIp(ip string) bool {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	for _, address := range addrs {
		// 检查ip地址判断是否回环地址
		if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil {
				logger.Info(ipnet.IP.String())
				return  ipnet.IP.String() == ip
			}
		}
	}
	return false
}
