Exemplo n.º 1
0
func (a *SMSAction) Do(n notices.Notice) (err error) {
	if mylog.Debugging {
		defer func() { mylog.Debugf("exit SMSAction.Do  %+v", err) }()
	}

	text := util.ExpandFromMap(a.ActionData.Template, n)
	mylog.Debug("SMSAction text to send:", text)
	msg := fmt.Sprintf(`{"to":["tel:%s"], "message": %q}`, a.Parameters["to"], text)
	mylog.Debug("SMSAction msg to send:", msg)
	req, err := http.NewRequest("POST", config.SMSEndpoint(), strings.NewReader(msg))
	if err != nil {
		mylog.Alert("SMSAction.Do", err)
	}
	req.Header.Add("API_KEY", config.APIKey())
	req.Header.Add("API_SECRET", config.APISecret())
	req.Header.Add("Content-Type", "application/json")
	mylog.Debug("SMSAction.Do msg:", msg)
	resp, err := httpClient.Do(req)
	if err != nil {
		mylog.Alert("SMSAction.Do", err)
		return err
	}
	respDump, err := httputil.DumpResponse(resp, true)
	mylog.Debugf("SMSAction.Do server response: (%q,%v)\n", string(respDump), err)
	return err
}
Exemplo n.º 2
0
func (a *UpdateAction) Do(n notices.Notice) (err error) {

	// A litle (or very) dirty. Add "hidden" parameters as notification data
	// and remove them after executing template (better copy first level fields in a new map?)
	n["__attrName"] = a.ActionData.Parameters["name"]
	n["__attrValue"] = a.ActionData.Parameters["value"]
	n["__attrType"] = a.ActionData.Parameters["type"]
	text := util.ExpandFromMap(updateTemplateText, n)
	mylog.Debug("UpdateAction text to send:", text)
	delete(n, "__attrName")
	delete(n, "__attrValue")
	delete(n, "__attrType")

	req, err := http.NewRequest("POST", config.UpdateEndpoint(), strings.NewReader(text))
	if err != nil {
		mylog.Alert("UpdateAction.Do", err)
	}
	req.Header.Add("Content-Type", "application/json")
	resp, err := httpClient.Do(req)
	if err != nil {
		mylog.Alert("UpdateAction.Do", err)
		return err
	}
	respDump, err := httputil.DumpResponse(resp, true)
	mylog.Debugf("UpdateAction.Do server response: (%q,%v)\n", string(respDump), err)
	return err
}
Exemplo n.º 3
0
func (a *EmailAction) Do(n notices.Notice) (err error) {
	if mylog.Debugging {
		mylog.Debugf("enter EmailAction.Do %+v %+v", a, n)
		defer func() { mylog.Debugf("exit EmailAction.Do  %+v", err) }()
	}

	text := util.ExpandFromMap(a.ActionData.Template, n)
	mylog.Debugf("text to send %q", text)
	err = smtp.SendMail(config.SMTPServer(), nil,
		a.Parameters["from"],
		[]string{a.Parameters["to"]},
		[]byte(text))
	if err != nil {
		mylog.Alert("EmailAction.Do", err)
	}
	return err
}