添加查看monitor设备接口
This commit is contained in:
parent
ef1b2771cd
commit
510b725ade
|
|
@ -52,10 +52,37 @@ func SetUpToolGroup(router *gin.Engine) {
|
||||||
toolGroup.POST("/file_del", DelFile)
|
toolGroup.POST("/file_del", DelFile)
|
||||||
//服务器、设备状态接口
|
//服务器、设备状态接口
|
||||||
toolGroup.POST("/monitor", SetDeviceStatusV2)
|
toolGroup.POST("/monitor", SetDeviceStatusV2)
|
||||||
|
toolGroup.GET("/get_monitor_list", GetMonitorList) //获取设备监控列表
|
||||||
|
toolGroup.POST("/update_monitor", UpdateMonitor) //设置设备状态
|
||||||
|
toolGroup.POST("/del_monitor", DelMonitor) //删除设备监控
|
||||||
//发送邮件
|
//发送邮件
|
||||||
toolGroup.POST("/send_mail", SendMailTool)
|
toolGroup.POST("/send_mail", SendMailTool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMonitorList(c *gin.Context) {
|
||||||
|
id, _ := c.Get("id")
|
||||||
|
userId := int(id.(float64))
|
||||||
|
var resp proto.GeneralResp
|
||||||
|
monitorDeviceList, err := service.GetMonitorDeviceListWithStatus(userId)
|
||||||
|
if err != nil {
|
||||||
|
resp.Code = proto.OperationFailed
|
||||||
|
resp.Message = err.Error()
|
||||||
|
} else {
|
||||||
|
resp.Code = proto.SuccessCode
|
||||||
|
resp.Message = "success"
|
||||||
|
resp.Data = monitorDeviceList
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
|
}
|
||||||
|
func UpdateMonitor(c *gin.Context) {
|
||||||
|
id, _ := c.Get("id")
|
||||||
|
id1 := int(id.(float64))
|
||||||
|
}
|
||||||
|
func DelMonitor(c *gin.Context) {
|
||||||
|
id, _ := c.Get("id")
|
||||||
|
id1 := int(id.(float64))
|
||||||
|
}
|
||||||
|
|
||||||
func SetDeviceStatusV2(c *gin.Context) {
|
func SetDeviceStatusV2(c *gin.Context) {
|
||||||
// TODO
|
// TODO
|
||||||
var req SetDeviceStatusReq
|
var req SetDeviceStatusReq
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ type ConfigStruct struct {
|
||||||
MASTER_SERVER_DOMAIN string `json:"master_server_domain"` // 主服务器域名
|
MASTER_SERVER_DOMAIN string `json:"master_server_domain"` // 主服务器域名
|
||||||
USER_SYNC_TIME int `json:"user_sync_time"` // 用户数据同步时间,单位秒
|
USER_SYNC_TIME int `json:"user_sync_time"` // 用户数据同步时间,单位秒
|
||||||
SERVER_NAME string `json:"server_name"` // 服务器名称,用于区分不同服务器
|
SERVER_NAME string `json:"server_name"` // 服务器名称,用于区分不同服务器
|
||||||
|
MONITOR_SERVER_TOKEN string `json:"monitor_server_token"` // 监控服务器token,用于状态监控及邮件通知
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取配置文件
|
// 读取配置文件
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package proto
|
||||||
|
|
||||||
|
type GetMonitorDeviceStatus struct {
|
||||||
|
ID string `json:"id" form:"id"` //设备编码
|
||||||
|
Status string `json:"status" form:"status"` //设备状态
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -113,3 +114,26 @@ func CheckEmail(email string) bool {
|
||||||
reg := regexp.MustCompile(pattern)
|
reg := regexp.MustCompile(pattern)
|
||||||
return reg.MatchString(email)
|
return reg.MatchString(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取监控设备及状态
|
||||||
|
func GetMonitorDeviceListWithStatus(userId int) ([]proto.GetMonitorDeviceStatus, error) {
|
||||||
|
var deviceStatus []proto.GetMonitorDeviceStatus
|
||||||
|
user := GetUserByIDFromUserCenter(userId)
|
||||||
|
if user.Role != "admin" {
|
||||||
|
return deviceStatus, errors.New("user is not admin, can not get monitor device list")
|
||||||
|
} else {
|
||||||
|
devices := worker.GetRedisSetMembers(proto.Config.MONITOR_SERVER_TOKEN)
|
||||||
|
for _, device := range devices {
|
||||||
|
status := worker.GetRedis("monitor_" + device)
|
||||||
|
var deviceInfo proto.GetMonitorDeviceStatus
|
||||||
|
deviceInfo.ID = device
|
||||||
|
if status == "" {
|
||||||
|
deviceInfo.Status = "offline"
|
||||||
|
} else {
|
||||||
|
deviceInfo.Status = status
|
||||||
|
}
|
||||||
|
deviceStatus = append(deviceStatus, deviceInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceStatus, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue