Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
1bcad97ed2 | |||
c2a9618f27 | |||
8dab976cba |
@@ -13,12 +13,11 @@ import (
|
|||||||
// offlineMonitoring
|
// offlineMonitoring
|
||||||
// @description: 离线监听任务
|
// @description: 离线监听任务
|
||||||
func offlineMonitoring() {
|
func offlineMonitoring() {
|
||||||
for {
|
|
||||||
devices, err := client.WireguardClient.Devices()
|
devices, err := client.WireguardClient.Devices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
time.Sleep(5 * time.Minute) // 休眠五分钟再执行
|
time.Sleep(5 * time.Minute) // 休眠五分钟再执行
|
||||||
offlineMonitoring()
|
offlineMonitoring()
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 遍历客户端数据,并渲染数据信息
|
// 遍历客户端数据,并渲染数据信息
|
||||||
@@ -42,18 +41,17 @@ func offlineMonitoring() {
|
|||||||
isOnline := time.Since(p.LastHandshakeTime).Minutes() < 3
|
isOnline := time.Since(p.LastHandshakeTime).Minutes() < 3
|
||||||
|
|
||||||
// 未离线
|
// 未离线
|
||||||
if !isOnline {
|
if isOnline {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
content := fmt.Sprintf("客户端:%s\r\n", clientInfo.Name)
|
content := fmt.Sprintf("客户端:%s\r\n", clientInfo.Name)
|
||||||
content += fmt.Sprintf("客户端IP:%s\r\n", ipAllocation)
|
content += fmt.Sprintf("客户端IP:%s\r\n", ipAllocation)
|
||||||
content += fmt.Sprintf("端点IP:%s", p.Endpoint.String())
|
content += fmt.Sprintf("端点IP:%s\r\n", p.Endpoint.String())
|
||||||
content += fmt.Sprintf("最后握手时间:%s\r\n", p.LastHandshakeTime.Format("2006-01-02 15:04:05"))
|
content += fmt.Sprintf("最后握手时间:%s\r\n", p.LastHandshakeTime.Format("2006-01-02 15:04:05"))
|
||||||
content += fmt.Sprintf("离线时间:%s\r\n", time.Now().Format("2006-01-02 15:04:05"))
|
|
||||||
|
|
||||||
// 离线并且配置了邮箱,准备发送邮件
|
// 离线并且配置了邮箱,准备发送邮件
|
||||||
err = utils.Mail().SendMail(clientInfo.Email, fmt.Sprintf("客户端离线通知"), content, "")
|
err = utils.Mail().SendMail(clientInfo.Email, fmt.Sprintf("客户端[%s]离线通知", clientInfo.Name), content, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("发送离线通知邮件失败: %v", err.Error())
|
log.Errorf("发送离线通知邮件失败: %v", err.Error())
|
||||||
continue
|
continue
|
||||||
@@ -61,5 +59,5 @@ func offlineMonitoring() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user