You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

alertlistlogic.go 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package monitoring
  2. import (
  3. "context"
  4. "fmt"
  5. v1 "github.com/prometheus/client_golang/api/prometheus/v1"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  8. "k8s.io/apimachinery/pkg/util/json"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type AlertListLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewAlertListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AlertListLogic {
  17. return &AlertListLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. type AlertListResp struct {
  24. Mode int `json:"code"`
  25. Msg string `json:"msg"`
  26. Data map[string][]*v1.Alert `json:"data"`
  27. }
  28. func (l *AlertListLogic) AlertList(req *types.AlertListReq) (resp *types.AlertListResp, err error) {
  29. resp = &types.AlertListResp{
  30. AlertMap: make(map[string]interface{}),
  31. }
  32. // query server http url.
  33. var clusterArray []string
  34. sql := "select distinct tc.name from t_adapter ta,t_cluster tc where ta.id = tc.adapter_id and label = 'kubernetes' and ta.type = ?"
  35. if len(req.AdapterId) > 0 {
  36. sql = fmt.Sprintf("select distinct tc.name from t_adapter ta,t_cluster tc where ta.id = tc.adapter_id and label = 'kubernetes' and ta.type = ? and ta.id = %s", req.AdapterId)
  37. }
  38. if len(req.ClusterId) > 0 {
  39. sql = fmt.Sprintf("select distinct tc.name from t_adapter ta,t_cluster tc where ta.id = tc.adapter_id and label = 'kubernetes' and ta.type = ? and tc.id = %s", req.ClusterId)
  40. }
  41. l.svcCtx.DbEngin.Raw(sql, req.AlertType).Scan(&clusterArray)
  42. for _, clusterName := range clusterArray {
  43. getResult := l.svcCtx.RedisClient.Get(l.ctx, clusterName)
  44. if len(getResult.Val()) != 0 {
  45. var alerts []v1.Alert
  46. json.Unmarshal([]byte(getResult.Val()), &alerts)
  47. resp.AlertMap[clusterName] = alerts
  48. }
  49. }
  50. return resp, nil
  51. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.