|
|
|
@@ -0,0 +1,63 @@ |
|
|
|
package monitoring |
|
|
|
|
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"github.com/pkg/errors" |
|
|
|
v1 "github.com/prometheus/client_golang/api/prometheus/v1" |
|
|
|
tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" |
|
|
|
|
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" |
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" |
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx" |
|
|
|
) |
|
|
|
|
|
|
|
type AlertListLogic struct { |
|
|
|
logx.Logger |
|
|
|
ctx context.Context |
|
|
|
svcCtx *svc.ServiceContext |
|
|
|
} |
|
|
|
|
|
|
|
func NewAlertListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AlertListLogic { |
|
|
|
return &AlertListLogic{ |
|
|
|
Logger: logx.WithContext(ctx), |
|
|
|
ctx: ctx, |
|
|
|
svcCtx: svcCtx, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
type AlertListResp struct { |
|
|
|
Mode int `json:"code"` |
|
|
|
Msg string `json:"msg"` |
|
|
|
Data map[string][]*v1.Alert `json:"data"` |
|
|
|
} |
|
|
|
|
|
|
|
func (l *AlertListLogic) AlertList() (resp *types.AlertListResp, err error) { |
|
|
|
// todo: add your logic here and delete this line |
|
|
|
resp = &types.AlertListResp{} |
|
|
|
|
|
|
|
// query server http url. |
|
|
|
var serverArray []string |
|
|
|
l.svcCtx.DbEngin.Raw("select ta.server from t_adapter ta,t_cluster tc where ta.id = tc.adapter_id and label = 'kubernetes'").Scan(&serverArray) |
|
|
|
|
|
|
|
result := make(map[string][]*v1.Alert) |
|
|
|
for _, server := range serverArray { |
|
|
|
alertListResp := AlertListResp{} |
|
|
|
response, err := l.svcCtx.HttpClient.R(). |
|
|
|
SetResult(&alertListResp). |
|
|
|
ForceContentType("application/json"). |
|
|
|
Get(server + "/api/v1/alert/rule/list") |
|
|
|
if err != nil { |
|
|
|
logx.Error(response) |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if response.IsError() { |
|
|
|
return nil, errors.New(response.String()) |
|
|
|
} |
|
|
|
for k, v := range alertListResp.Data { |
|
|
|
result[k] = v |
|
|
|
} |
|
|
|
} |
|
|
|
tool.Convert(result, &resp.AlertMap) |
|
|
|
return resp, nil |
|
|
|
} |