gotify
This commit is contained in:
parent
026915fdec
commit
ded5c332e2
@ -81,7 +81,7 @@ func (c *TCPClient) StartClient() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for message := range c.TCPServer.CmdChan {
|
for message := range c.TCPServer.CmdChan {
|
||||||
Log.Infof("Received DX Command: %s", message)
|
Log.Infof("Received Command: %s", message)
|
||||||
message := message + "\n"
|
message := message + "\n"
|
||||||
c.WriteString(message)
|
c.WriteString(message)
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ func (c *TCPClient) ReadLine() {
|
|||||||
c.Write([]byte(c.Login + "\r\n"))
|
c.Write([]byte(c.Login + "\r\n"))
|
||||||
c.SetFilters()
|
c.SetFilters()
|
||||||
if Cfg.Cluster.Command != "" {
|
if Cfg.Cluster.Command != "" {
|
||||||
c.WriteString(Cfg.Cluster.Command)
|
c.WriteString(Cfg.Cluster.Command + "\n\r")
|
||||||
}
|
}
|
||||||
Log.Info("Start receiving spots")
|
Log.Info("Start receiving spots")
|
||||||
} else if strings.Contains(message, "Error reading from server: read tcp") {
|
} else if strings.Contains(message, "Error reading from server: read tcp") {
|
||||||
|
10
config.go
10
config.go
@ -44,6 +44,16 @@ type Config struct {
|
|||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
Port string `yaml:"port"`
|
Port string `yaml:"port"`
|
||||||
} `yaml:"telnetserver"`
|
} `yaml:"telnetserver"`
|
||||||
|
|
||||||
|
Gotify struct {
|
||||||
|
Enable bool `yaml:"enable"`
|
||||||
|
URL string `yaml:"url"`
|
||||||
|
Token string `yaml:"token"`
|
||||||
|
NewDXCC bool `yaml:"NewDXCC"`
|
||||||
|
NewBand bool `yaml:"NewBand"`
|
||||||
|
NewMode bool `yaml:"NewMode"`
|
||||||
|
NewBandAndMode bool `yaml:"NewBandAndMode"`
|
||||||
|
} `yaml:"gotify"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(configPath string) *Config {
|
func NewConfig(configPath string) *Config {
|
||||||
|
14
config.yml
14
config.yml
@ -8,13 +8,13 @@ sqlite:
|
|||||||
sqlite_path: 'C:\Perso\Seafile\Radio\Logs\Log4OM\F4BPO.SQLite' # SQLite Db oath of Log4OM
|
sqlite_path: 'C:\Perso\Seafile\Radio\Logs\Log4OM\F4BPO.SQLite' # SQLite Db oath of Log4OM
|
||||||
callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone
|
callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone
|
||||||
cluster:
|
cluster:
|
||||||
server: cluster.f4bpo.com # dxc.k0xm.net
|
server: dxc.k0xm.net # dxc.k0xm.net
|
||||||
port: 7300
|
port: 7300
|
||||||
login: f4bpo
|
login: f4bpo
|
||||||
skimmer: true
|
skimmer: true
|
||||||
ft8: false
|
ft8: false
|
||||||
ft4: false
|
ft4: false
|
||||||
command: #SET/NOFILTER
|
command: SET/NOFILTER
|
||||||
login_prompt: "Please enter your call:"
|
login_prompt: "Please enter your call:"
|
||||||
flex:
|
flex:
|
||||||
discovery: true # Radio must be on same LAN than the program
|
discovery: true # Radio must be on same LAN than the program
|
||||||
@ -22,4 +22,12 @@ flex:
|
|||||||
spot_life: 600 #seconds
|
spot_life: 600 #seconds
|
||||||
telnetserver: # Log4OM must be connected to this server ie: localhost:7301 if on same machine as this program else ip:7301
|
telnetserver: # Log4OM must be connected to this server ie: localhost:7301 if on same machine as this program else ip:7301
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
port: 7301
|
port: 7301
|
||||||
|
gotify:
|
||||||
|
enable: true
|
||||||
|
url: https://gotify.rouggy.com/message
|
||||||
|
token: ALaGS4MVMWTEMcP
|
||||||
|
newDxcc: true
|
||||||
|
NewBand: false
|
||||||
|
NewMode: false
|
||||||
|
NewBandAndMode: true
|
@ -209,6 +209,9 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
|
|||||||
flexSpot.BackgroundColor = "#ff000000"
|
flexSpot.BackgroundColor = "#ff000000"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send notification to Gotify
|
||||||
|
Gotify(flexSpot)
|
||||||
|
|
||||||
flexSpot.Comment = strings.ReplaceAll(flexSpot.Comment, " ", "\u00A0")
|
flexSpot.Comment = strings.ReplaceAll(flexSpot.Comment, " ", "\u00A0")
|
||||||
|
|
||||||
srcFlexSpot, err := fc.Repo.FindDXSameBand(flexSpot)
|
srcFlexSpot, err := fc.Repo.FindDXSameBand(flexSpot)
|
||||||
|
72
gotify.go
Normal file
72
gotify.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GotifyMessage struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Priority int `json:"priority"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Gotify(spot FlexSpot) {
|
||||||
|
|
||||||
|
if Cfg.Gotify.Enable {
|
||||||
|
|
||||||
|
message := fmt.Sprintf("DX: %s\nFrom: %s\nFreq: %s\nMode: %s\n", spot.DX, spot.Source, spot.FrequencyMhz, spot.Mode)
|
||||||
|
|
||||||
|
gotifyMsg := GotifyMessage{
|
||||||
|
Title: "",
|
||||||
|
Message: message,
|
||||||
|
Priority: 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
if spot.NewDXCC && Cfg.Gotify.NewDXCC {
|
||||||
|
title := "FlexDXCluster New DXCC"
|
||||||
|
gotifyMsg.Title = title
|
||||||
|
gotifyMsg.Message = message
|
||||||
|
sendToGotify(gotifyMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if spot.NewBand && spot.NewMode && Cfg.Gotify.NewBandAndMode {
|
||||||
|
title := "FlexDXCluster New Mode & Band"
|
||||||
|
gotifyMsg.Title = title
|
||||||
|
gotifyMsg.Message = message
|
||||||
|
sendToGotify(gotifyMsg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendToGotify(mess GotifyMessage) {
|
||||||
|
jsonData, err := json.Marshal(mess)
|
||||||
|
if err != nil {
|
||||||
|
Log.Errorln("Error marshaling JSON:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", Cfg.Gotify.URL, bytes.NewBuffer(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
Log.Errorln("Error creating request:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Add("Authorization", "Bearer "+Cfg.Gotify.Token)
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
Log.Errorln("Error sending request:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
Log.Errorln("Gotify server returned non-OK status:", resp.Status)
|
||||||
|
} else {
|
||||||
|
Log.Println("Push successfully sent to Gotify")
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user