实现连通性变化发送通知功能

This commit is contained in:
GoEdgeLab
2021-09-18 14:21:56 +08:00
parent e61461e63c
commit d176d15a83
3 changed files with 7 additions and 5 deletions

View File

@@ -48,6 +48,7 @@ const (
MessageTypeReportNodeInactive MessageType = "ReportNodeInactive" // 区域监控节点节点不活跃
MessageTypeReportNodeActive MessageType = "ReportNodeActive" // 区域监控节点活跃
MessageTypeConnectivity MessageType = "Connectivity"
)
type MessageDAO dbs.DAO

View File

@@ -175,8 +175,9 @@ func (this *ReportResultDAO) FindAvgLevelWithTarget(tx *dbs.Tx, taskType reporte
return "", nil
}
// FindConnectivityWithTarget 获取某个对象的连通率
func (this *ReportResultDAO) FindConnectivityWithTarget(tx *dbs.Tx, taskType reporterconfigs.TaskType, targetId int64, groupId int64) (float64, error) {
// FindConnectivityWithTargetPercent 获取某个对象的连通率
// 返回值在0-100
func (this *ReportResultDAO) FindConnectivityWithTargetPercent(tx *dbs.Tx, taskType reporterconfigs.TaskType, targetId int64, groupId int64) (float64, error) {
var query = this.Query(tx).
Attr("type", taskType).
Attr("targetId", targetId)
@@ -195,7 +196,7 @@ func (this *ReportResultDAO) FindConnectivityWithTarget(tx *dbs.Tx, taskType rep
return 0, err
}
if total == 0 {
return 1, nil
return 100, nil
}
// 连通的数量
@@ -217,5 +218,5 @@ func (this *ReportResultDAO) FindConnectivityWithTarget(tx *dbs.Tx, taskType rep
if err != nil {
return 0, err
}
return float64(countConnected) / float64(total), nil
return float64(countConnected) * 100 / float64(total), nil
}

File diff suppressed because one or more lines are too long