Melora Hugues
bd14b3c731
All checks were successful
continuous-integration/drone/push Build is passing
This commit allows using an external unix exporter to send the messages instead of directly sending the messages to Telegram
26 lines
828 B
Go
26 lines
828 B
Go
package messager
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Sender interface {
|
|
SendMessage(message string) error
|
|
}
|
|
|
|
func FormatInitMsg(currentTime time.Time, publicIP net.IP, hostname string) string {
|
|
formattedHostname := fmt.Sprintf("`%s`", hostname)
|
|
formattedIP := strings.ReplaceAll(publicIP.String(), ".", "\\.")
|
|
return fmt.Sprintf(`\[Host %s\] %s
|
|
Public IP tracker initialized\. Current IP is %s`, formattedHostname, currentTime.Format(time.RFC1123), formattedIP)
|
|
}
|
|
|
|
func FormatUpdate(currentTime time.Time, publicIP net.IP, hostname string) string {
|
|
formattedHostname := fmt.Sprintf("`%s`", hostname)
|
|
formattedIP := strings.ReplaceAll(publicIP.String(), ".", "\\.")
|
|
return fmt.Sprintf(`\[Host %s\] %s
|
|
Public IP has changed, new IP is %s`, formattedHostname, currentTime.Format(time.RFC1123), formattedIP)
|
|
}
|