示例#1
0
// Run is the plugin's main loop
//iterates over received messages, checking against
//message hostname and delivering to the output if hostname is in our config.
func (o *EmailOutput) Run(runner pipeline.OutputRunner, helper pipeline.PluginHelper) (
	err error) {

	var (
		payload string
	)
	body := bytes.NewBuffer(nil)

	for pack := range runner.InChan() {
		payload = pack.Message.GetPayload()
		if len(payload) > 100 {
			payload = payload[:100]
		}
		body.WriteString(fmt.Sprintf("Subject: %s [%d] %s@%s: ",
			utils.TsTime(pack.Message.GetTimestamp()).Format(time.RFC3339),
			pack.Message.GetSeverity(), pack.Message.GetLogger(),
			pack.Message.GetHostname()))
		body.WriteString(payload)
		body.WriteString("\r\n\r\n")
		body.WriteString(pack.Message.GetPayload())
		pack.Recycle()
		err = o.sendMail(body.Bytes())
		body.Reset()
		if err != nil {
			return fmt.Errorf("error sending email: %s", err)
		}

	}
	return
}
示例#2
0
// Run is the plugin's main loop
//iterates over received messages, checking against
//message hostname and delivering to the output if hostname is in our config.
func (o *MantisOutput) Run(runner pipeline.OutputRunner, helper pipeline.PluginHelper) (
	err error) {

	var (
		short, long string
		//issue       int
	)

	for pack := range runner.InChan() {
		long = pack.Message.GetPayload()
		short = fmt.Sprintf("%s [%d] %s@%s: %s",
			utils.TsTime(pack.Message.GetTimestamp()).Format(time.RFC3339),
			pack.Message.GetSeverity(), pack.Message.GetLogger(),
			pack.Message.GetHostname(), long)
		pack.Recycle()
		if _, err = o.sender.Send(short, long); err != nil {
			return fmt.Errorf("error sending to %s: %s", o.sender.URL, err)
		}

	}
	return
}
示例#3
0
// Run is the plugin's main loop
//iterates over received messages, checking against
//message hostname and delivering to the output if hostname is in our config.
func (o *TwilioOutput) Run(runner pipeline.OutputRunner, helper pipeline.PluginHelper) (
	err error) {

	var (
		to, sms string
		exc     *gotwilio.Exception
	)

	for pack := range runner.InChan() {
		sms = fmt.Sprintf("%s [%d] %s@%s: %s",
			utils.TsTime(pack.Message.GetTimestamp()).Format(time.RFC3339),
			pack.Message.GetSeverity(), pack.Message.GetLogger(),
			pack.Message.GetHostname(), pack.Message.GetPayload())
		pack.Recycle()
		for _, to = range o.To {
			_, exc, err = o.client.SendSMS(o.From, to, sms, "", "")
			if err == nil && exc != nil {
				return fmt.Errorf("%s: %d\n%s", exc.Message, exc.Code, exc.MoreInfo)
			}
		}

	}
	return
}