예제 #1
0
func main() {
	accountSid := ""
	authToken := ""
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+"
	to := "+"
	callbackParams := gotwilio.NewCallbackParameters("http://example.com")
	twilio.CallWithUrlCallbacks(from, to, callbackParams)
}
예제 #2
0
파일: sup.go 프로젝트: topscore/sup
func callDevTeam() {
	config := common.GetConfig()
	twilio := gotwilio.NewTwilioClient(config.TwilioSID, config.TwilioAuthToken)
	messageURL := "http://twimlets.com/message?Message%5B0%5D=SITE%20IS%20DOWN!"
	callbackParams := gotwilio.NewCallbackParameters(messageURL)

	for _, num := range config.Phones {
		fmt.Printf("!!! Calling %s\n", num)

		_, tException, err := twilio.CallWithUrlCallbacks(config.TwilioCallFrom, num, callbackParams)
		if tException != nil {
			panic(fmt.Sprintf("Twilio error: %+v\n", tException))
		}
		check(err)
	}
}
예제 #3
0
파일: alert.go 프로젝트: LunaNode/gobearmon
func alertInit() {
	alertFuncs = make(map[string]AlertFunc)

	alertFuncs["email"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		subject := fmt.Sprintf("Check %s: %s", result.Status, check.Name)

		var body string
		if result.Status == StatusOnline {
			body = fmt.Sprintf("Check [%s] is now online.", check.Name)
		} else {
			body = fmt.Sprintf("Check [%s] is now %s: %s", check.Name, result.Status, result.Message)
		}
		body += fmt.Sprintf("\n\nID: %d\nName: %s\nType: %s\nData: %s\n\ngobearmon", check.Id, check.Name, check.Type, check.Data)
		return mail(subject, body, data)
	}

	alertFuncs["http"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		resp, err := http.PostForm(data, url.Values{
			"check_id": {strconv.Itoa(int(check.Id))},
			"name":     {check.Name},
			"type":     {check.Type},
			"data":     {check.Data},
			"status":   {string(result.Status)},
			"message":  {result.Message},
		})
		if err != nil {
			return err
		}
		resp.Body.Close()
		return nil
	}

	alertFuncs["sms"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		var message string
		if result.Status == StatusOnline {
			message = fmt.Sprintf("Check [%s] is now online.", check.Name)
		} else {
			message = fmt.Sprintf("Check [%s] is now %s: %s", check.Name, result.Status, result.Message)
		}
		twilio := gotwilio.NewTwilioClient(cfg.Twilio.AccountSid, cfg.Twilio.AuthToken)
		resp, exception, err := twilio.SendSMS(cfg.Twilio.From, data, message, "", "")
		if err != nil {
			return err
		} else if exception != nil {
			return fmt.Errorf("error(%d/%d): %s (%s)", exception.Status, exception.Code, exception.Message, exception.MoreInfo)
		}
		db.Exec("INSERT INTO charges (check_id, type, data) VALUES (?, ?, ?)", check.Id, "sms", resp.Sid)
		return nil
	}

	alertFuncs["voice"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		message := fmt.Sprintf("This is a monitoring-related call from go bear mon . The check . %s . has been recorded . %s . Reason is . %s", check.Name, result.Status, result.Message)
		twilio := gotwilio.NewTwilioClient(cfg.Twilio.AccountSid, cfg.Twilio.AuthToken)
		params := gotwilio.NewCallbackParameters("http://twimlets.com/message?Message=" + url.QueryEscape(message))
		resp, exception, err := twilio.CallWithUrlCallbacks(cfg.Twilio.From, data, params)
		if err != nil {
			return err
		} else if exception != nil {
			return fmt.Errorf("error(%d/%d): %s (%s)", exception.Status, exception.Code, exception.Message, exception.MoreInfo)
		}
		db.Exec("INSERT INTO charges (check_id, type, data) VALUES (?, ?, ?)", check.Id, "voice", resp.Sid)
		return nil
	}
}