func Callback(event *model.Event, action *api.Action) string { if action.Url == "" { return "callback url is blank" } L := make([]string, 0) if len(event.PushedTags) > 0 { for k, v := range event.PushedTags { L = append(L, fmt.Sprintf("%s:%s", k, v)) } } tags := "" if len(L) > 0 { tags = strings.Join(L, ",") } req := httplib.Get(action.Url).SetTimeout(3*time.Second, 20*time.Second) req.Param("endpoint", event.Endpoint) req.Param("metric", event.Metric()) req.Param("func", event.Func()) req.Param("leftValue", fmt.Sprintf("%.3f", event.LeftValue)) req.Param("operator", event.Operator()) req.Param("rightValue", fmt.Sprintf("%.3f", event.RightValue())) req.Param("note", event.Note()) req.Param("status", event.Status) req.Param("step", fmt.Sprintf("%d", event.CurrentStep)) req.Param("priority", fmt.Sprintf("%d", event.Priority())) req.Param("time", event.FormattedTime()) req.Param("tpl_id", fmt.Sprintf("%d", event.TplId())) req.Param("exp_id", fmt.Sprintf("%d", event.ExpressionId())) req.Param("stra_id", fmt.Sprintf("%d", event.StrategyId())) req.Param("tags", tags) resp, e := req.String() success := "success" if e != nil { success = fmt.Sprintf("fail:%s", e.Error()) } message := fmt.Sprintf("curl %s %s. resp: %s", action.Url, success, resp) return message }
func CurlAction(id int) *Action { if id <= 0 { return nil } uri := fmt.Sprintf("%s/api/action/%d", g.Config().Api.Portal, id) req := httplib.Get(uri).SetTimeout(5*time.Second, 30*time.Second) var actionWrap ActionWrap err := req.ToJson(&actionWrap) if err != nil { log.Printf("curl %s fail: %v", uri, err) return nil } if actionWrap.Msg != "" { log.Printf("curl %s return msg: %v", uri, actionWrap.Msg) return nil } return actionWrap.Data }
func getIp() string { strUrl := g.Config().GetIpApi logger.Debug("REQUEST_URL:%s\n", strUrl) httpRequest := httplib.Get(strUrl).SetTimeout(3*time.Second, 10*time.Second) httpResponse, err := httpRequest.Bytes() if nil != err { logger.Errorln("GET_IP error", err) return "" } strIp := "" var resp g.ServletResponse err = json.Unmarshal(httpResponse, &resp) if err != nil { logger.Error("decode GET_IP response fail %v\n", err) } else if false == resp.Success { logger.Error("GET_IP fail %s\n", resp.Message) } else { strIp = resp.Message } logger.Infoln("RESPONSE_IP:", strIp) return strIp }
func CurlUic(team string) []*User { if team == "" { return []*User{} } uri := fmt.Sprintf("%s/team/users", g.Config().Api.Uic) req := httplib.Get(uri).SetTimeout(2*time.Second, 10*time.Second) req.Param("name", team) req.Param("token", g.Config().UicToken) var usersWrap UsersWrap err := req.ToJson(&usersWrap) if err != nil { log.Printf("curl %s fail: %v", uri, err) return nil } if usersWrap.Msg != "" { log.Printf("curl %s return msg: %v", uri, usersWrap.Msg) return nil } return usersWrap.Users }