56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.tordarus.net/Tordarus/adverr"
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
)
|
|
|
|
var (
|
|
interval = 1 * time.Minute
|
|
telegramToken string
|
|
chatID int64
|
|
)
|
|
|
|
func main() {
|
|
if i, ok := os.LookupEnv("POLL_INTERVAL"); ok {
|
|
if interval2, err := time.ParseDuration(i); err == nil {
|
|
interval = interval2
|
|
}
|
|
}
|
|
|
|
if tt, ok := os.LookupEnv("TELEGRAM_API_TOKEN"); ok {
|
|
telegramToken = tt
|
|
}
|
|
|
|
if id, ok := os.LookupEnv("TELEGRAM_CHAT_ID"); ok {
|
|
if chatId2, err := strconv.Atoi(id); err == nil {
|
|
chatID = int64(chatId2)
|
|
}
|
|
}
|
|
|
|
bot, err := tgbotapi.NewBotAPI(telegramToken)
|
|
if err != nil {
|
|
adverr.Fatalln(err, 1)
|
|
}
|
|
|
|
for state := range filterChanges(mdstat()) {
|
|
str := state.String()
|
|
fmt.Println(str)
|
|
message := tgbotapi.NewMessage(chatID, fmt.Sprintf("Der Zustand des RAID Systems %s hat sich verändert:\n\n%s", state.Name, str))
|
|
message.Entities = append(message.Entities, tgbotapi.MessageEntity{
|
|
Type: "code",
|
|
Offset: len("Der Zustand des RAID Systems %s hat sich verändert:\n\n"),
|
|
Length: len(str),
|
|
})
|
|
_, err := bot.Send(message)
|
|
if err != nil {
|
|
adverr.Println(err)
|
|
}
|
|
}
|
|
}
|