Merge pull request #5 from versus/Add-pushover-service

Add pushover service
pull/7/head
Khaliq 4 years ago committed by GitHub
commit e7acde5a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -95,6 +95,7 @@ COMMANDS:
slack Send message to slack slack Send message to slack
discord Send message to discord discord Send message to discord
teams Send message to microsoft teams teams Send message to microsoft teams
pushover Send message to pushover
email Send an email email Send an email
help, h Shows a list of commands or help for one command help, h Shows a list of commands or help for one command

@ -0,0 +1,83 @@
package cmd
import (
"fmt"
"log"
"strings"
"github.com/gregdel/pushover"
"github.com/urfave/cli/v2"
)
// pushOver struct holds data parsed via flags for pushover service
type pushOver struct {
Token string
Recipient string
Message string
Title string
}
// SendToPushOver parse values from *cli.context and return *cli.Command.
// Values include token, users, Message and Title.
// If multiple users are provided then the string is split with "," separator and
// each user is added to receiver.
func SendToPushOver() *cli.Command {
var pushOverOpts pushOver
return &cli.Command{
Name: "pushover",
Usage: "Send message to pushover",
UsageText: "pingme pushover --token '123' --user '12345,567' --message 'some message'",
Description: `Pushover uses token to authenticate application and user token to send messages to the user.
All configuration options are also available via environment variables.`,
Flags: []cli.Flag{
&cli.StringFlag{
Destination: &pushOverOpts.Token,
Name: "token",
Aliases: []string{"t"},
Required: true,
Usage: "Token of pushover application used for authenticate application.",
EnvVars: []string{"PUSHOVER_TOKEN"},
},
&cli.StringFlag{
Destination: &pushOverOpts.Recipient,
Name: "user",
Required: true,
Aliases: []string{"u"},
Usage: "User token used for sending message to user,if sending to multiple userss separate with ','.",
EnvVars: []string{"PUSHOVER_USER"},
},
&cli.StringFlag{
Destination: &pushOverOpts.Message,
Name: "msg",
Aliases: []string{"m"},
Usage: "Message content.",
EnvVars: []string{"PUSHOVER_MESSAGE"},
},
&cli.StringFlag{
Destination: &pushOverOpts.Title,
Name: "title",
Value: TimeValue,
Usage: "Title of the message.",
EnvVars: []string{"PUSHOVER_TITLE"},
},
},
Action: func(ctx *cli.Context) error {
app := pushover.New(pushOverOpts.Token)
message := pushover.NewMessageWithTitle(pushOverOpts.Message, pushOverOpts.Title)
users := strings.Split(pushOverOpts.Recipient, ",")
for _, v := range users {
if len(v) == 0 {
return fmt.Errorf(EmptyChannel)
}
recipient := pushover.NewRecipient(v)
responsePushOver, err := app.SendMessage(message, recipient)
if err != nil {
return err
}
log.Printf("Successfully sent!\n%v\n", responsePushOver)
}
return nil
},
}
}

@ -4,6 +4,7 @@ go 1.16
require ( require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888
github.com/nikoksr/notify v0.15.0 github.com/nikoksr/notify v0.15.0
github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0

@ -79,6 +79,8 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888 h1:rnBK/Xp+eaxlNrbMRoBTQ/m5c+jq41NSmqgFscNH7zY=
github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=

@ -20,7 +20,7 @@ func main() {
app.Description = `PingMe is a CLI tool which provides the ability to send messages or alerts to multiple app.Description = `PingMe is a CLI tool which provides the ability to send messages or alerts to multiple
messaging platforms and also email, everything is configurable via environment messaging platforms and also email, everything is configurable via environment
variables and command line switches.Currently supported platforms include Slack, Telegram, variables and command line switches.Currently supported platforms include Slack, Telegram,
RocketChat, Discord, Microsoft Teams and email address.` RocketChat, Discord, Pushover, Microsoft Teams and email address.`
// app.Commands contains the subcommands as functions which return []*cli.Command. // app.Commands contains the subcommands as functions which return []*cli.Command.
app.Commands = []*cli.Command{ app.Commands = []*cli.Command{
cmd.SendToTelegram(), cmd.SendToTelegram(),
@ -28,6 +28,7 @@ RocketChat, Discord, Microsoft Teams and email address.`
cmd.SendToSlack(), cmd.SendToSlack(),
cmd.SendToDiscord(), cmd.SendToDiscord(),
cmd.SendToTeams(), cmd.SendToTeams(),
cmd.SendToPushOver(),
cmd.SendToEmail(), cmd.SendToEmail(),
} }

Loading…
Cancel
Save