//counter query by endpoints func (this *DashBoardController) CounterQuery() { baseResp := this.BasicRespGen() _, err := this.SessionCheck() if err != nil { this.ResposeError(baseResp, err.Error()) return } endpoints := this.GetString("endpoints", "") endpointcheck, _ := regexp.Compile("^\\s*\\[\\s*\\]\\s*$") if endpoints == "" || endpointcheck.MatchString(endpoints) { this.ResposeError(baseResp, "query string is empty, please check it") return } rexstr, _ := regexp.Compile("^\\s*\\[\\s*|\\s*\\]\\s*$") endpointsArr := strings.Split(rexstr.ReplaceAllString(endpoints, ""), ",") limitNum, _ := this.GetInt("limit", 0) counters, err := dashboard.QueryCounterByEndpoints(endpointsArr, limitNum) switch { case err != nil: this.ResposeError(baseResp, err.Error()) return case len(counters) == 0: baseResp.Data["counters"] = []string{} default: baseResp.Data["counters"] = counters } this.ServeApiJson(baseResp) return }
func (this *DashBoardController) CounterQueryByHostGroup() { baseResp := this.BasicRespGen() _, err := this.SessionCheck() if err != nil { this.ResposeError(baseResp, err.Error()) return } hostgroups := this.GetString("hostgroups", "") hostgroupscheck, _ := regexp.Compile("^\\s*\\[\\s*\\]\\s*$") if hostgroups == "" || hostgroupscheck.MatchString(hostgroups) { this.ResposeError(baseResp, "query string is empty, please check it") return } rexstr, _ := regexp.Compile("^\\s*\\[\\s*|\\s*\\]\\s*$") hostgroupsArr := strings.Split(rexstr.ReplaceAllString(hostgroups, ""), ",") hosts, err := dashboard.GetHostsByHostGroupName(hostgroupsArr) if err != nil { this.ResposeError(baseResp, err.Error()) return } if len(hosts) > 0 { var endpoints []string for _, v := range hosts { endpoints = append(endpoints, fmt.Sprintf("\"%v\"", v.Hostname)) } limitNum, _ := this.GetInt("limit", 0) counters, err := dashboard.QueryCounterByEndpoints(endpoints, limitNum) if err != nil { this.ResposeError(baseResp, err.Error()) return } else if len(counters) > 0 { baseResp.Data["counters"] = counters } else { baseResp.Data["counters"] = []string{} } } this.ServeApiJson(baseResp) return }