示例#1
0
func (n *notifier) sendPushoverNotification(token string, op notificationOp, userKey string, a *Alert) error {
	po, err := pushover.NewPushover(token, userKey)
	if err != nil {
		return err
	}

	// Validate credentials
	err = po.Validate()
	if err != nil {
		return err
	}

	status := "unknown"
	switch op {
	case notificationOpTrigger:
		status = "firing"
	case notificationOpResolve:
		status = "resolved"
	}
	alertname := html.EscapeString(a.Labels["alertname"])

	// Send pushover message
	_, _, err = po.Push(&pushover.Message{
		Title:   fmt.Sprintf("%s: %s", alertname, status),
		Message: a.Summary,
	})
	return err
}
示例#2
0
// NotifyPushover uses the Pushover API to send notifications about the current build
func (n *NotifyEntry) NotifyPushover(metadata NotifyMetaData, cfg *config.Config) error {
	verb := "succeeded"
	if metadata.EventType == "error" {
		verb = "failed"
	}

	message := &pushover.Message{
		Message:  fmt.Sprintf("The build for repo %s %s", metadata.Repository, verb),
		Title:    fmt.Sprintf("GoBuilder.me %s", verb),
		Url:      fmt.Sprintf("https://gobuilder.me/%s", metadata.Repository),
		UrlTitle: "Go to your build...",
		Priority: pushover.Normal,
	}

	p, err := pushover.NewPushover(cfg.Pushover.APIToken, n.Target)
	if err != nil {
		return err
	}

	_, _, err = p.Push(message)
	if err != nil {
		return err
	}

	return nil
}
示例#3
0
文件: main.go 项目: rosylilly/ppush
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	config := NewConfig()

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage:\n  ppush [pids]\n\n")
		flag.PrintDefaults()
	}
	flag.StringVar(&config.App, "a", config.App, "app token")
	flag.StringVar(&config.User, "u", config.User, "user token")
	flag.StringVar(&config.Message, "m", config.Message, "push message")
	flag.Parse()

	po, err := pushover.NewPushover(config.App, config.User)
	if err != nil {
		log.Fatal(err)
	}

	wg := new(sync.WaitGroup)

	pids := flag.Args()

	for _, pid := range pids {
		wg.Add(1)
		go checkPid(pid, wg)
	}

	wg.Wait()

	err = po.Message(config.Message)
	if err != nil {
		log.Fatal(err)
	}
}
示例#4
0
// New returns a new instance of Pushover
func New() (*pushover.Pushover, error) {
	if po.Enabled {
		p, err := pushover.NewPushover(po.Token, po.UserKey)
		return p, err
	}

	return nil, ErrPushoverDisabled
}
示例#5
0
func sendPushover(token string, userKey string, message string) error {

	po, err := pushover.NewPushover(token, userKey)
	if err != nil {
		return err
	}

	err = po.Message(message)
	if err != nil {
		return err
	}
	return nil
}
示例#6
0
func (n *notifier) sendPushoverNotification(token string, op notificationOp, userKey string, a *Alert) error {
	po, err := pushover.NewPushover(token, userKey)
	if err != nil {
		return err
	}

	// Validate credentials
	err = po.Validate()
	if err != nil {
		return err
	}

	status := "unknown"
	switch op {
	case notificationOpTrigger:
		status = "firing"
	case notificationOpResolve:
		status = "resolved"
	}
	alertname := html.EscapeString(a.Labels["alertname"])

	var pushoverPriority int = 2

	if priority, ok := a.Labels["pushover_priority"]; ok {
		switch priority {
		case "lowest":
			pushoverPriority = -2
		case "low":
			pushoverPriority = -1
		case "normal":
			pushoverPriority = 0
		case "high":
			pushoverPriority = 1
		default:
		case "emergency":
			pushoverPriority = 2
		}
	}

	// Send pushover message
	_, _, err = po.Push(&pushover.Message{
		Title:    fmt.Sprintf("%s: %s", alertname, status),
		Message:  a.Summary,
		Priority: pushoverPriority,
		Retry:    *pushoverRetryTimeout,
		Expire:   *pushoverExpireTimeout,
	})
	return err
}
示例#7
0
func (p *Pushover) Send(args *PushoverMessage, reply *PushoverResponse) error {
	papi, err := pushover.NewPushover(p.client, p.user)
	if err != nil {
		log.Printf("pushover.NewPushover error: %s", err)
		return err
	}

	message := pushover.Message{
		Message:  args.Message,
		Priority: args.Priority,
		Retry:    args.Retry,
	}

	if len(args.Title) > 0 {
		message.Title = args.Title
	}

	if len(args.URL) > 0 {
		message.Url = args.URL
	}

	if len(args.URLTitle) > 0 {
		message.UrlTitle = args.URLTitle
	}

	if args.Timestamp > 0 {
		message.Timestamp = args.Timestamp
	}

	// TODO(sissel): message.Sound
	// TODO(sissel): message.Device
	// TODO(sissel): message.Retry
	// TODO(sissel): message.Expire
	//
	request, _, err := papi.Push(&message)
	if err != nil {
		log.Printf("papi.Push() failed: %s", err)
		return err
	}

	reply.Request = request
	// TODO(sissel): What to do with receipt?
	return nil
}
func main() {
	token := os.Getenv("PUSHOVER_TOKEN")
	user := os.Getenv("PUSHOVER_USER")

	if len(token) == 0 || len(user) == 0 {
		fmt.Println("Environment variable `PUSHOVER_TOKEN` or `PUSHOVER_USER` was not defined")
		return
	}

	po, err := pushover.NewPushover(token, user)

	if err != nil {
		fmt.Println(err)
		return
	}

	go func() {
		// 1440 (24 * 60)
		for _ = range time.Tick(1 * time.Minute) {
			var last time.Time

			res, err := http.Get("http://www.atualizarboleto.com.br/")

			if err != nil {
				log.Println(err)
			}

			if res.StatusCode != http.StatusOK {
				notify(*po, res.Status, &last)
			}

			log.Printf("%s %s\n", res.Proto, res.Status)
		}
	}()

	select {}
}
示例#9
0
func pushoverAgent(in chan pmb.Message, token string, userKey string) {

	recentIds := make([]string, 0)

	po, err := pushover.NewPushover(token, userKey)
	if err != nil {
		logrus.Warnf("Error creating new Pushover instance: %s", err)
	}

MESSAGE:
	for {
		message := <-in

		messageText := message.Contents["message"].(string)
		messageId := message.Contents["notification-id"].(string)

		for _, val := range recentIds {
			if val == messageId {
				logrus.Warnf("Message with id %s already sent to Pushover, skipping", messageId)
				continue MESSAGE
			}
		}

		// record ID to debounce messages
		recentIds = append(recentIds, messageId)
		if len(recentIds) > 10 {
			recentIds = recentIds[1:]
		}

		err = po.Message(messageText)
		if err != nil {
			logrus.Warnf("Error sending Pushover notification: %s", err)
		}
	}

	return
}
示例#10
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	config := NewConfig()

	flag.StringVar(&config.User, "u", config.User, "user name")
	flag.StringVar(&config.Token, "t", config.Token, "token")
	flag.StringVar(&config.Message, "m", config.Message, "message")
	flag.Parse()

	po, err := pushover.NewPushover(config.Token, config.User)
	if err != nil {
		log.Fatal(err)
	}

	if config.Message == "" {
		config.Message = scan()
	}

	err = po.Message(config.Message)
	if err != nil {
		log.Fatal(err)
	}
}