Documentation ¶
Index ¶
- Constants
- Variables
- type Alertmanager
- type Bot
- type BotChatStore
- type BotOption
- func WithAddr(addr string) BotOption
- func WithAlertmanager(alertmanager Alertmanager) BotOption
- func WithCommandEvent(callback func(command string)) BotOption
- func WithDeletePeriod(deletePeriod float64) BotOption
- func WithEnvironments(environmentsToUse string) BotOption
- func WithExtraAdmins(ids ...int) BotOption
- func WithFetchPeriod(fetchPeriod float64) BotOption
- func WithLogger(l log.Logger) BotOption
- func WithProjects(projectsToUse string) BotOption
- func WithRevision(r string) BotOption
- func WithStartTime(st time.Time) BotOption
- func WithTemplates(alertmanager *url.URL, templatePaths ...string) BotOption
- type ChatInfo
- type ChatStore
- func (s *ChatStore) AddChat(c *telebot.Chat, allEnvs []string, allPrs []string) error
- func (s *ChatStore) Get(id telebot.ChatID) (*telebot.Chat, error, *store.KVPair)
- func (s *ChatStore) List() ([]ChatInfo, error)
- func (s *ChatStore) MuteEnvironments(c *telebot.Chat, envsToMute []string, allEnvs []string) error
- func (s *ChatStore) MuteProjects(c *telebot.Chat, prsToMute []string, allPrs []string) error
- func (s *ChatStore) MutedEnvironments(c *telebot.Chat) ([]string, error)
- func (s *ChatStore) MutedProjects(c *telebot.Chat) ([]string, error)
- func (s *ChatStore) RemoveChat(c *telebot.Chat) error
- func (s *ChatStore) UnmuteEnvironment(c *telebot.Chat, envToUnmute string, allEnvs []string) error
- func (s *ChatStore) UnmuteProject(c *telebot.Chat, prToUnmute string, allPrs []string) error
- type Telebot
Constants ¶
const ( CommandStart = "/start" CommandStop = "/stop" CommandHelp = "/help" CommandChats = "/chats" CommandID = "/id" CommandStatus = "/status" CommandAlerts = "/alerts" CommandSilences = "/silences" CommandMute = "/mute" CommandMuteDel = "/mute_del" CommandEnvironments = "/environments" CommandProjects = "/projects" CommandMutedEnvs = "/muted_envs" CommandMutedPrs = "/muted_prs" ProjectAndEnvironmentMuteRegexp = `/mute environment\[(\w+(\s*,\s*\w+)*)\],[ ]?project\[(\w+(\s*,\s*\w+)*)\]` MuteProjectRegexp = `/mute project\[(\w+(\s*,\s*\w+)*)\]` MuteEnvironmentRegexp = `/mute environment\[(\w+(\s*,\s*\w+)*)\]` ProjectAndEnvironmentUnmuteRegexp = `/mute_del environment\[(\w+(\s*,\s*\w+)*)\],[ ]?project\[(\w+(\s*,\s*\w+)*)\]` UnmuteProjectRegexp = `/mute_del project\[(\w+(\s*,\s*\w+)*)\]` UnmuteEnvironmentRegexp = `/mute_del environment\[(\w+(\s*,\s*\w+)*)\]` EnvironmentValuesRegexp = `environment\[(.*?)\]` ProjectValuesRegexp = `project\[(.*?)\]` ResponseHelp = ` I'm a Prometheus AlertManager Bot for Telegram. I will notify you about alerts. You can also ask me about my ` + CommandStatus + `, ` + CommandAlerts + ` & ` + CommandSilences + ` Available commands: ` + CommandStart + ` - Subscribe for alerts. ` + CommandStop + ` - Unsubscribe for alerts. ` + CommandStatus + ` - Print the current status. ` + CommandAlerts + ` - List all alerts. ` + CommandSilences + ` - List all silences. ` + CommandChats + ` - List all users and group chats that subscribed. ` + CommandID + ` - Send the senders Telegram ID (works for all Telegram users). ` + CommandMute + ` - Mute environments and/or projects. ` + CommandMuteDel + ` - Delete mute. ` + CommandEnvironments + ` - List all environments for alerts. ` + CommandProjects + ` - List all projects for alerts. ` + CommandMutedEnvs + ` - List all muted environments. ` + CommandMutedPrs + ` - List all muted projects. ` )
Variables ¶
var ChatNotFoundErr = errors.New("chat not found in store")
ChatNotFoundErr returned by the store if a chat isn't found.
Functions ¶
This section is empty.
Types ¶
type Alertmanager ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot runs the alertmanager telegram.
func NewBotWithTelegram ¶
func (*Bot) Run ¶
func (b *Bot) Run(ctx context.Context, webhooks <-chan alertmanager.TelegramWebhook) error
Run the telegram and listen to messages send to the telegram.
func (*Bot) SendAdminMessage ¶
SendAdminMessage to the admin's ID with a message.
type BotChatStore ¶
type BotChatStore interface { List() ([]ChatInfo, error) Get(telebot.ChatID) (*telebot.Chat, error, *store.KVPair) AddChat(*telebot.Chat, []string, []string) error RemoveChat(*telebot.Chat) error MuteEnvironments(*telebot.Chat, []string, []string) error MuteProjects(*telebot.Chat, []string, []string) error UnmuteEnvironment(*telebot.Chat, string, []string) error UnmuteProject(*telebot.Chat, string, []string) error MutedEnvironments(*telebot.Chat) ([]string, error) MutedProjects(*telebot.Chat) ([]string, error) }
BotChatStore is all the Bot needs to store and read.
type BotOption ¶
BotOption passed to NewBot to change the default instance.
func WithAddr ¶
WithAddr sets the internal listening addr of the bot's web server receiving webhooks.
func WithAlertmanager ¶
func WithAlertmanager(alertmanager Alertmanager) BotOption
func WithCommandEvent ¶
WithCommandEvent sets a func to call whenever commands are handled.
func WithDeletePeriod ¶
WithDeletePeriod allows to define period of deleting messages
func WithEnvironments ¶
WithEnvironments allows to define environments that are monitored by Prometheus
func WithExtraAdmins ¶
WithExtraAdmins allows the specified additional user IDs to issue admin commands to the bot.
func WithFetchPeriod ¶
WithFetchPeriod allows to define scheduler period for fetching messages from store
func WithLogger ¶
WithLogger sets the logger for the Bot as an option.
func WithProjects ¶
WithProjects allows to define projects that are monitored by Prometheus
func WithRevision ¶
WithRevision is setting the Bot's revision for status commands.
func WithStartTime ¶
WithStartTime is setting the Bot's start time for status commands.
type ChatInfo ¶
type ChatInfo struct { Chat *telebot.Chat AlertEnvironments []string AlertProjects []string MutedEnvironments []string MutedProjects []string }
func (*ChatInfo) MuteEnvironments ¶
func (*ChatInfo) MuteProjects ¶
func (*ChatInfo) UnmuteEnvironment ¶
func (*ChatInfo) UnmuteProject ¶
type ChatStore ¶
type ChatStore struct {
// contains filtered or unexported fields
}
ChatStore writes the users to a libkv store backend.
func NewChatStore ¶
NewChatStore stores telegram chats in the provided kv backend.
func (*ChatStore) MuteEnvironments ¶
func (*ChatStore) MuteProjects ¶
func (*ChatStore) MutedEnvironments ¶
func (*ChatStore) MutedProjects ¶
func (*ChatStore) RemoveChat ¶
RemoveChat Remove a telegram chat from the kv backend.