func LinkToSMS(content string) (string, error) { links := g.Config().Api.Links uri := fmt.Sprintf("%s/store", links) req := httplib.Post(uri).SetTimeout(3*time.Second, 10*time.Second) req.Body([]byte(content)) return req.String() }
func heartbeat() { agentDirs, err := ListAgentDirs() if err != nil { return } hostname, err := utils.Hostname(g.Config().Hostname) if err != nil { return } heartbeatRequest := BuildHeartbeatRequest(hostname, agentDirs) if g.Config().Debug { log.Println("====>>>>") log.Println(heartbeatRequest) } bs, err := json.Marshal(heartbeatRequest) if err != nil { log.Println("encode heartbeat request fail", err) return } url := fmt.Sprintf("https://%s/heartbeat", g.Config().Server) httpRequest := httplib.Post(url).SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).SetTimeout(time.Second*10, time.Minute) httpRequest.Body(bs) httpResponse, err := httpRequest.Bytes() if err != nil { log.Printf("curl %s fail %v", url, err) return } var heartbeatResponse model.HeartbeatResponse err = json.Unmarshal(httpResponse, &heartbeatResponse) if err != nil { log.Println("decode heartbeat response fail", err) return } if g.Config().Debug { log.Println("<<<<====") log.Println(heartbeatResponse) } HandleHeartbeatResponse(&heartbeatResponse) }
func SendSms(sms *model.Sms) { defer func() { <-SmsWorkerChan }() url := g.Config().Api.Sms r := httplib.Post(url).SetTimeout(5*time.Second, 2*time.Minute) r.Param("tos", sms.Tos) r.Param("content", sms.Content) resp, err := r.String() if err != nil { log.Println(err) } proc.IncreSmsCount() if g.Config().Debug { log.Println("==sms==>>>>", sms) log.Println("<<<<==sms==", resp) } }
func SendMail(mail *model.Mail) { defer func() { <-MailWorkerChan }() url := g.Config().Api.Mail r := httplib.Post(url).SetTimeout(5*time.Second, 2*time.Minute) r.Param("tos", mail.Tos) r.Param("subject", mail.Subject) r.Param("content", mail.Content) resp, err := r.String() if err != nil { log.Println(err) } proc.IncreMailCount() if g.Config().Debug { log.Println("==mail==>>>>", mail) log.Println("<<<<==mail==", resp) } }
func heartbeat() { hostname, err := utils.Hostname(g.Config().Hostname) if err != nil { return } desiredAgents := ReadDesiredAgents() heartbeatRequest := BuildHeartbeatRequest(hostname, desiredAgents) logger.Debugln("===>>>", heartbeatRequest) bs, err := json.Marshal(heartbeatRequest) if err != nil { logger.Errorln("encode heartbeat request fail", err) return } url := fmt.Sprintf("http://%s/api/heartbeat", g.Config().Server) httpRequest := httplib.Post(url).SetTimeout(time.Second*10, time.Minute) httpRequest.Body(bs) httpResponse, err := httpRequest.Bytes() if err != nil { log.Printf("curl %s fail %v", url, err) return } var heartbeatResponse model.HeartbeatResponse err = json.Unmarshal(httpResponse, &heartbeatResponse) if err != nil { logger.Errorln("decode heartbeat response fail", err) return } logger.Debugln("<<<<====", heartbeatResponse) HandleHeartbeatResponse(&heartbeatResponse, desiredAgents) }
func SendServerchan(serverchan *model.Serverchan) { defer func() { <-ServerchanWorkerChan }() sckey := serverchan.Tos if len(sckey) > 5 { url := g.Config().Api.Serverchan url += "/" + sckey + ".send" r := httplib.Post(url).SetTimeout(5*time.Second, 2*time.Minute) r.Param("text", serverchan.Subject) r.Param("desp", serverchan.Content) resp, err := r.String() if err != nil { log.Println(err) } if g.Config().Debug { log.Println("==serverchan==>>>>", serverchan) log.Println("<<<<==serverchan==", resp) } } proc.IncreServerchanCount() }