From 7e1593e8a2c9b552f41d7bf06b820f52aa8c9212 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Wed, 28 Apr 2021 00:58:13 +0800 Subject: [PATCH 1/4] docs: add pushbullet service docs --- README.md | 24 ++++++++----- docs/home.md | 9 ++--- docs/install.md | 14 ++++++-- docs/services.md | 93 ++++++++++++++++++++++++++++++++++++------------ 4 files changed, 103 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 8884e8e..72621a6 100644 --- a/README.md +++ b/README.md @@ -24,14 +24,13 @@

- AboutDocumentationSupported ServicesInstallGithub ActionConfigurationContributing • - Show Your Support • + Show Your Support

--- @@ -45,7 +44,7 @@ And i can ship it everywhere with ease. Hence, the birth of PingMe. Everything is configurable via environment variables, and you can simply export the logs or messages to a variable which will be sent -as message. And most of all this serves as a swiss army knife sort of tool which supports multiple platforms. +as message, and most of all this serves as a swiss army knife sort of tool which supports multiple platforms. @@ -53,20 +52,28 @@ as message. And most of all this serves as a swiss army knife sort of tool which - *Discord* - *Email* - *Microsoft Teams* +- *Mattermost* +- *Pushover* +- *Pushbullet* - *RocketChat* - *Slack* - *Telegram* -- *Pushover* -- *Mattermost* - ## Install -### Linux & MacOs +### MacOS & Linux Homebrew ```bash brew install kha7iq/tap/pingme ``` +## Linux Binary +```bash +wget -q https://github.com/kha7iq/pingme/releases/download/v0.1.6/pingme_Linux_x86_64.tar.gz +tar -xf pingme_Linux_x86_64.tar.gz +chmod +x pingme +sudo mv pingme /usr/local/bin/pingme +``` + ### Go Get ```bash go get -u github.com/kha7iq/pingme @@ -91,7 +98,7 @@ Docker Registry ```bash docker pull khaliq/pingme:latest ``` -Gighub Registry +Github Registry ```bash docker pull ghcr.io/kha7iq/pingme:latest ``` @@ -132,6 +139,7 @@ COMMANDS: pushover Send message to pushover email Send an email mattermost Send message to mattermost + pushbullet Send message to pushbullet help, h Shows a list of commands or help for one command GLOBAL OPTIONS: diff --git a/docs/home.md b/docs/home.md index cd24cdc..d0cb0e4 100644 --- a/docs/home.md +++ b/docs/home.md @@ -33,24 +33,25 @@ ## About **PingMe** is a personal project to satisfy my needs of having alerts, most major platforms have integration to send alerts -but its not always useful, either you are stuck with one particular platform, or you have to do alot of integrations. I needed a small app +but it's not always useful, either you are stuck with one particular platform, or you have to do alot of integrations. I needed a small app which i can just call from my backup scripts, cron jobs, CI/CD pipelines or from anywhere to send a message with particular information. And i can ship it everywhere with ease. Hence, the birth of PingMe. Everything is configurable via environment variables, and you can simply export the logs or messages to a variable which will be sent -as message. And most of all this serves as a swiss army knife sort of tool which supports multiple platforms. +as message, and most of all this serves as a swiss army knife sort of tool which supports multiple platforms. ## Supported services - *Discord* - *Email* - *Microsoft Teams* +- *Mattermost* +- *Pushover* +- *Pushbullet* - *RocketChat* - *Slack* - *Telegram* -- *Pushover* -- *Mattermost* diff --git a/docs/install.md b/docs/install.md index 63a2870..61dc2b4 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,9 +1,17 @@ -## Linux & MacOs +## MacOS & Linux Homebrew ```bash brew install kha7iq/tap/pingme ``` +## Linux Binary +```bash +wget -q https://github.com/kha7iq/pingme/releases/download/v0.1.6/pingme_Linux_x86_64.tar.gz +tar -xf pingme_Linux_x86_64.tar.gz +chmod +x pingme +sudo mv +``` + ## Go Get ```bash go get -u github.com/kha7iq/pingme @@ -29,7 +37,7 @@ Checkout [release](https://github.com/kha7iq/pingme/releases) page for available ```bash docker pull khaliq/pingme:latest ``` -- Github Registry +- GitHub Registry ```bash docker pull ghcr.io/kha7iq/pingme:latest ``` @@ -39,7 +47,7 @@ docker run ghcr.io/kha7iq/pingme:latest ``` -## Github Action +## GitHub Action A github action is also available now for this app, you can find it on [Github Market Place](https://github.com/marketplace/actions/pingme-action) or from this [repository](https://github.com/kha7iq/pingme-action) on github. Usage examples for workflow are available in the repo. diff --git a/docs/services.md b/docs/services.md index 1d893e4..50eb2f3 100644 --- a/docs/services.md +++ b/docs/services.md @@ -19,7 +19,7 @@ Multiple channel ids can be used separated by comma ','. pingme telegram --token "0125:AAFHvnYf_ABC" --msg "This is a new message ✈" --channel="-1001001001,-1002002001" ``` -- Github Action +- GitHub Action ```yaml on: [push] @@ -37,8 +37,8 @@ jobs: env: TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} TELEGRAM_CHANNELS: ${{ secrets.TELEGRAM_CHANNELS }} - TELEGRAM_TITLE: 'Refrence: ${{ github.ref }}' - TELEGRAM_MESSAGE: 'Event is triggerd by ${{ github.event_name }}' + TELEGRAM_TITLE: 'Reference: ${{ github.ref }}' + TELEGRAM_MESSAGE: 'Event is triggered by ${{ github.event_name }}' with: # Chose the messaging platform. @@ -88,8 +88,8 @@ jobs: ROCKETCHAT_SERVER_URL: ${{ secrets.ROCKETCHAT_SERVER_URL }} ROCKETCHAT_CHANNELS: ${{ secrets.ROCKETCHAT_CHANNELS }} ROCKETCHAT_URL_SCHEME: "https" - ROCKETCHAT_TITLE: 'Refrence: ${{ github.ref }}' - ROCKETCHAT_MESSAGE: 'Event is triggerd by ${{ github.event_name }}' + ROCKETCHAT_TITLE: 'Reference: ${{ github.ref }}' + ROCKETCHAT_MESSAGE: 'Event is triggered by ${{ github.event_name }}' with: # Chose the messaging platform. # slack / telegram / rocketchat / teams / pushover / discord / email / mattermost @@ -114,7 +114,7 @@ jobs: pingme pushover --token '123' --user '12345567' --title 'some title' --msg 'some message' ``` -- Github Action +- GitHub Action ```yaml on: [push] @@ -132,8 +132,8 @@ jobs: env: PUSHOVER_TOKEN: ${{ secrets.PUSHOVER_TOKEN }} PUSHOVER_USER: ${{ secrets.PUSHOVER_USER }} - PUSHOVER_TITLE: 'Refrence: ${{ github.ref }}' - PUSHOVER_MESSAGE: 'Event is triggerd by ${{ github.event_name }}' + PUSHOVER_TITLE: 'Reference: ${{ github.ref }}' + PUSHOVER_MESSAGE: 'Event is triggered by ${{ github.event_name }}' with: # Chose the messaging platform. @@ -161,7 +161,7 @@ You can specify multiple channels by separating the value with ','. pingme mattermost --token '123' --channel '12345,567' --url 'localhost' --scheme 'http' --msg 'some message' ``` -- Github Action +- GitHub Action ```yaml on: @@ -179,11 +179,11 @@ jobs: uses: kha7iq/pingme-action@v1 env: MATTERMOST_TOKEN: ${{ secrets.MATTERMOST_TOKEN }} - ROCKETCHAT_SERVER_URL: ${{ secrets.ROCKETCHAT_SERVER_URL }} + MATTERMOST_SERVER_URL: ${{ secrets.MATTERMOST_SERVER_URL }} MATTERMOST_CHANNELS: ${{ secrets.MATTERMOST_CHANNELS }} MATTERMOST_CHANNELS: ${{ secrets.MATTERMOST_CHANNELS }} - MATTERMOST_TITLE: 'Refrence: ${{ github.ref }}' - MATTERMOST_MESSAGE: 'Event is triggerd by ${{ github.event_name }}' + MATTERMOST_TITLE: 'Reference: ${{ github.ref }}' + MATTERMOST_MESSAGE: 'Event is triggered by ${{ github.event_name }}' with: # Chose the messaging platform. # slack / telegram / rocketchat / teams / pushover / discord / email / mattermost @@ -227,10 +227,10 @@ jobs: - name: Ping me On uses: kha7iq/pingme-action@v1 env: - PUSHOVER_TOKEN: ${{ secrets.SLACK_TOKEN }} + SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }} SLACK_CHANNELS: ${{ secrets.SLACK_CHANNELS }} - SLACK_MSG_TITLE: 'Refrence: ${{ github.ref }}' - SLACK_MESSAGE: 'Event is triggerd by ${{ github.event_name }}' + SLACK_MSG_TITLE: 'Reference: ${{ github.ref }}' + SLACK_MESSAGE: 'Event is triggered by ${{ github.event_name }}' with: # Chose the messaging platform. # slack / telegram / rocketchat / teams / pushover / discord / email @@ -254,7 +254,7 @@ Multiple channel ids can be used separated by comma ','. pingme discord --token '123' --channel '1234567890' --msg 'some message' ``` -- Github Action +- GitHub Action ```yaml on: @@ -273,8 +273,8 @@ jobs: env: DISCORD_CHANNELS: ${{ secrets.DISCORD_CHANNELS }} DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} - DISCORD_TITLE: 'Refrence: ${{ github.ref }}' - DISCORD_MESSAGE: 'Event is triggerd by ${{ github.event_name }}' + DISCORD_TITLE: 'Reference: ${{ github.ref }}' + DISCORD_MESSAGE: 'Event is triggered by ${{ github.event_name }}' with: # Chose the messaging platform. # slack / telegram / rocketchat / teams / pushover / discord / email / mattermost @@ -298,7 +298,7 @@ you can add permissions for multiple channels to single webhook. pingme teams --webhook 'https://example.webhook.office.com/xx' --msg 'some message' ``` -- Github Action +- GitHub Action ```yaml on: [push] @@ -315,9 +315,8 @@ jobs: uses: kha7iq/pingme-action@v1 env: TEAMS_WEBHOOK: ${{ secrets.TEAMS_WEBHOOK }} - TELEGRAM_CHANNELS: ${{ secrets.TELEGRAM_CHANNELS }} - TEAMS_MSG_TITLE: 'Refrence: ${{ github.ref }}' - TEAMS_MESSAGE: 'Event is triggerd by ${{ github.event_name }}' + TEAMS_MSG_TITLE: 'Reference: ${{ github.ref }}' + TEAMS_MESSAGE: 'Event is triggered by ${{ github.event_name }}' with: # Chose the messaging platform. @@ -332,6 +331,56 @@ jobs: | TEAMS_MESSAGE | "" | | TEAMS_MSG_TITLE | "" | +## Pushbullet + +- SMS +```bash +pingme pushbullet --sms true --token "abcdefg" -d "adnroid" --msg "some message" --number "00123456789" +``` + +- Push notification +```bash +pingme pushbullet --token "abcdefg" -d "adnroid" --msg "some message" +``` + +- GitHub Action + +```yaml +on: [push] + +jobs: + pingme-job: + runs-on: ubuntu-latest + name: PingMe + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Ping me On + uses: kha7iq/pingme-action@v1 + env: + PUSHBULLET_TOKEN: ${{ secrets.PUSHBULLET_TOKEN }} + PUSHBULLET_DEVICE: ${{ secrets.PUSHBULLET_DEVICE }} + PUSHBULLET_TITLE: 'Reference: ${{ github.ref }}' + PUSHBULLET_MESSAGE: 'Event is triggered by ${{ github.event_name }}' + + with: + # Chose the messaging platform. + # slack / telegram / rocketchat / teams / pushover / discord / email + service: pushbullet +``` + +- **Variables** + +| Variables | Default Value | +| -------------------------- | :----------------: | +| PUSHBULLET_TOKEN | "" | +| PUSHBULLET_DEVICE | "" | +| PUSHBULLET_NUMBER | "" | +| PUSHBULLET_MESSAGE | "" | +| PUSHBULLET_SMS | "false" | +| PUSHBULLET_TITLE | "" | + ## Email Email uses username & password to authenticate for sending emails. From a7ff2e461ef0685e2a5b00bafe298b4526513f69 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Wed, 28 Apr 2021 00:58:50 +0800 Subject: [PATCH 2/4] fix: lint code --- cmd/mattermost.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/mattermost.go b/cmd/mattermost.go index 9f374ce..e858567 100644 --- a/cmd/mattermost.go +++ b/cmd/mattermost.go @@ -146,7 +146,6 @@ You can specify multiple channels by separating the value with ','.`, // toJson takes strings and convert them to json byte array func toJson(channel string, msg string) ([]byte, error) { - m := make(map[string]string, 2) m["channel_id"] = channel m["message"] = msg From 386c183c86b2ef088c5ee43ddec15eda441d3b00 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Wed, 28 Apr 2021 01:00:37 +0800 Subject: [PATCH 3/4] fix: exclude readme and license file from release --- .goreleaser.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index fa6ba45..086b712 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -40,9 +40,6 @@ archives: format_overrides: - goos: windows format: zip - files: - - README.md - - LICENSE.md brews: - tap: From 575cd2e6b97863ea46f5f3d50323b09ca255ba29 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Wed, 28 Apr 2021 01:01:19 +0800 Subject: [PATCH 4/4] feat: add new service pushbullet --- cmd/pushbullet.go | 137 ++++++++++++++++++++++++++++++++++++++++++++++ go.sum | 1 + main.go | 3 +- 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 cmd/pushbullet.go diff --git a/cmd/pushbullet.go b/cmd/pushbullet.go new file mode 100644 index 0000000..c19b9ef --- /dev/null +++ b/cmd/pushbullet.go @@ -0,0 +1,137 @@ +package cmd + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/nikoksr/notify" + "github.com/nikoksr/notify/service/pushbullet" + "github.com/urfave/cli/v2" +) + +// pushBullet struct holds data parsed via flags for pushbullet service. +type pushBullet struct { + Token string + Message string + Title string + Device string + PhoneNumber string + SMS bool +} + +// SendToPushBullet parse values from *cli.context and return *cli.Command. +// Values include pushbullet token, Device, phone number, Message and Title. +// If multiple devices are provided they the string is split with "," separator and +// each device is added to receiver. +func SendToPushBullet() *cli.Command { + var pushBulletOpts pushBullet + return &cli.Command{ + Name: "pushbullet", + Usage: "Send message to pushbullet", + Description: `Pushbullet uses API token to authenticate & send messages to defined devices. +Multiple device nicknames or numbers can be used separated by comma.`, + UsageText: "pingme pushbullet --token '123' --device 'Web123, myAndroid' --msg 'some message'\n" + + "pingme pushbullet --token '123' --sms true --device 'Web123' --msg 'some message' --number '00123456789'", + Flags: []cli.Flag{ + &cli.StringFlag{ + Destination: &pushBulletOpts.Token, + Name: "token", + Aliases: []string{"t"}, + Required: true, + Usage: "Token of pushbullet api used for sending message.", + EnvVars: []string{"PUSHBULLET_TOKEN"}, + }, + &cli.StringFlag{ + Destination: &pushBulletOpts.Device, + Name: "device", + Aliases: []string{"d"}, + Required: true, + Usage: "Device's nickname of pushbullet.", + EnvVars: []string{"PUSHBULLET_DEVICE"}, + }, + &cli.StringFlag{ + Destination: &pushBulletOpts.PhoneNumber, + Name: "number", + Aliases: []string{"n"}, + Usage: "Target phone number", + EnvVars: []string{"PUSHBULLET_NUMBER"}, + }, + &cli.StringFlag{ + Destination: &pushBulletOpts.Message, + Name: "msg", + Aliases: []string{"m"}, + Usage: "Message content.", + EnvVars: []string{"PUSHBULLET_MESSAGE"}, + }, + &cli.StringFlag{ + Destination: &pushBulletOpts.Title, + Name: "title", + Value: TimeValue, + Usage: "Title of the message.", + EnvVars: []string{"PUSHBULLET_TITLE"}, + }, + &cli.BoolFlag{ + Destination: &pushBulletOpts.SMS, + Name: "sms", + Value: false, + Usage: "To send sms message set the value to 'true'", + EnvVars: []string{"PUSHBULLET_SMS"}, + }, + }, + Action: func(ctx *cli.Context) error { + notifier := notify.New() + + switch pushBulletOpts.SMS { + case true: + pushBulletSmsSvc, err := pushbullet.NewSMS(pushBulletOpts.Token, pushBulletOpts.Device) + if err != nil { + return err + } + devices := strings.Split(pushBulletOpts.PhoneNumber, ",") + for _, v := range devices { + if len(v) <= 0 { + return fmt.Errorf(EmptyChannel) + } + pushBulletSmsSvc.AddReceivers(v) + + notifier.UseServices(pushBulletSmsSvc) + + if err := notifier.Send( + context.Background(), + pushBulletOpts.Title, + pushBulletOpts.Message, + ); err != nil { + return err + } + + } + default: + pushBulletSvc := pushbullet.New(pushBulletOpts.Token) + + devices := strings.Split(pushBulletOpts.Device, ",") + for _, v := range devices { + if len(v) <= 0 { + return fmt.Errorf(EmptyChannel) + } + pushBulletSvc.AddReceivers(v) + } + + notifier.UseServices(pushBulletSvc) + + if err := notifier.Send( + context.Background(), + pushBulletOpts.Title, + pushBulletOpts.Message, + ); err != nil { + return err + } + + } + + log.Println("Successfully sent!") + return nil + }, + } +} diff --git a/go.sum b/go.sum index 5df3046..42a79a1 100644 --- a/go.sum +++ b/go.sum @@ -32,6 +32,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/cschomburg/go-pushbullet v0.0.0-20171206132031-67759df45fbb h1:7X9nrm+LNWdxzQOiCjy0G51rNUxbH35IDHCjAMvogyM= github.com/cschomburg/go-pushbullet v0.0.0-20171206132031-67759df45fbb/go.mod h1:RfQ9wji3fjcSEsQ+uFCtIh3+BXgcZum8Kt3JxvzYzlk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/main.go b/main.go index 36064b5..e789cde 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ func main() { 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 variables and command line switches.Currently supported platforms include Slack, Telegram, -RocketChat, Discord, Pushover, Mattermost, Microsoft Teams and email address.` +RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams and email address.` // app.Commands contains the subcommands as functions which return []*cli.Command. app.Commands = []*cli.Command{ cmd.SendToTelegram(), @@ -32,6 +32,7 @@ RocketChat, Discord, Pushover, Mattermost, Microsoft Teams and email address.` cmd.SendToPushOver(), cmd.SendToEmail(), cmd.SendToMattermost(), + cmd.SendToPushBullet(), } err := app.Run(os.Args)