-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from yubiuser/development
v2.4.0
- Loading branch information
Showing
10 changed files
with
191 additions
and
77 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"encoding/json" | ||
) | ||
|
||
type GotifyMessage struct { | ||
Title string `json:"title"` | ||
Message string `json:"message"` | ||
} | ||
|
||
func sendGotify(message string, title string) { | ||
// Send a message to Gotify | ||
|
||
response, err := http.PostForm(glb_arguments.GotifyURL+"/message?token="+glb_arguments.GotifyToken, | ||
url.Values{"message": {message}, "title": {title}}) | ||
if err != nil { | ||
logger.Error().Err(err).Str("reporter", "Gotify").Msg("") | ||
return | ||
m := GotifyMessage{ | ||
Title: title, | ||
Message: message, | ||
} | ||
|
||
defer response.Body.Close() | ||
|
||
statusCode := response.StatusCode | ||
|
||
body, err := io.ReadAll(response.Body) | ||
messageJSON, err := json.Marshal(m) | ||
if err != nil { | ||
logger.Error().Err(err).Str("reporter", "Gotify").Msg("") | ||
logger.Error().Err(err).Str("reporter", "Gotify").Msg("Faild to marshal JSON") | ||
return | ||
} | ||
|
||
logger.Debug().Str("reporter", "Gotify").Msgf("Gotify response statusCode: %d", statusCode) | ||
logger.Debug().Str("reporter", "Gotify").Msgf("Gotify response body: %s", string(body)) | ||
|
||
// Log non successfull status codes | ||
if statusCode == 200 { | ||
logger.Debug().Str("reporter", "Gotify").Msgf("Gotify message delivered") | ||
} else { | ||
logger.Error().Str("reporter", "Gotify").Msgf("Pushing gotify message failed.") | ||
logger.Error().Str("reporter", "Gotify").Msgf("Gotify response body: %s", string(body)) | ||
} | ||
sendhttpMessage("Gotify", glb_arguments.GotifyURL+"/message?token="+glb_arguments.GotifyToken, messageJSON) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// Adapted from https://github.com/mdeheij/mattergo | ||
|
||
// Message is a chat message to be sent using a webhook | ||
type MattermostMessage struct { | ||
Username string `json:"username"` | ||
Channel string `json:"channel"` | ||
Text string `json:"text"` | ||
} | ||
|
||
// Send a message to a Mattermost chat channel | ||
func sendMattermost(message string, title string) { | ||
|
||
m := MattermostMessage{ | ||
Username: glb_arguments.MattermostUser, | ||
Channel: glb_arguments.MattermostChannel, | ||
Text: "##### " + title + "\n" + message, | ||
} | ||
|
||
messageJSON, err := json.Marshal(m) | ||
if err != nil { | ||
logger.Error().Err(err).Str("reporter", "Mattermost").Msg("Faild to marshal JSON") | ||
return | ||
} | ||
|
||
sendhttpMessage("Mattermost", glb_arguments.MattermostURL, messageJSON) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
package main | ||
|
||
import "github.com/gregdel/pushover" | ||
|
||
func sendPushover(message string, title string) { | ||
// Create a new pushover app with an API token | ||
app := pushover.New(glb_arguments.PushoverAPIToken) | ||
|
||
// Create a new recipient (user key) | ||
recipient := pushover.NewRecipient(glb_arguments.PushoverUserKey) | ||
import ( | ||
"encoding/json" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type PushoverMessage struct { | ||
Token string `json:"token"` | ||
User string `json:"user"` | ||
Title string `json:"title"` | ||
Message string `json:"message"` | ||
Timestamp string `json:"timestamp"` | ||
} | ||
|
||
// Create the message to send | ||
pushmessage := pushover.NewMessageWithTitle(message, title) | ||
func sendPushover(timestamp time.Time, message string, title string) { | ||
// Send a message to Pushover | ||
|
||
// Send the message to the recipient | ||
response, err := app.SendMessage(pushmessage, recipient) | ||
if err != nil { | ||
logger.Error().Err(err).Str("reporter", "Pushover").Msg("") | ||
return | ||
} | ||
if response != nil { | ||
logger.Debug().Str("reporter", "Pushover").Msgf("%s", response) | ||
m := PushoverMessage{ | ||
Token: glb_arguments.PushoverAPIToken, | ||
User: glb_arguments.PushoverUserKey, | ||
Title: title, | ||
Message: message, | ||
Timestamp: strconv.FormatInt(timestamp.Unix(), 10), | ||
} | ||
|
||
if response.Status == 1 { | ||
// Pushover returns 1 if the message request to the API was valid | ||
// https://pushover.net/api#response | ||
logger.Debug().Str("reporter", "Pushover").Msgf("Pushover message delivered") | ||
messageJSON, err := json.Marshal(m) | ||
if err != nil { | ||
logger.Error().Err(err).Str("reporter", "Pushover").Msg("Faild to marshal JSON") | ||
return | ||
} | ||
|
||
// if response Status !=1 | ||
logger.Error().Str("reporter", "Pushover").Msg("Pushover message not delivered") | ||
sendhttpMessage("Pushover", "https://api.pushover.net/1/messages.json", messageJSON) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters