我创建了与电子邮件通知非常相似的自定义电报通知。问题是它适用于主机和大多数服务,但不适用于所有服务。
我不会在*.sh
文件夹中发布文件,scripts
因为它可以工作!
在constants.conf
我添加了机器人令牌:
const TelegramBotToken = "MyTelegramToken"
我想在用户文件中管理电报频道或聊天 ID,所以我有users/user-my-username.conf
以下内容:
object User "my-username" {
import "generic-user"
display_name = "My Username"
groups = ["faxadmins"]
email = "my-username@domain.com"
vars.telegram_chat_id = "@my_channel"
}
在templates/templates.conf
我添加了以下代码:
template Host "generic-host-domain" {
import "generic-host"
vars.notification.mail.groups = ["domainadmins"]
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
template Service "generic-service-fax" {
import "generic-service"
vars.notification["telegram"] = {
users = [ "my-username" ]
}
}
在notifications
我有:
template Notification "telegram-host-notification" {
command = "telegram-host-notification"
period = "24x7"
}
template Notification "telegram-service-notification" {
command = "telegram-service-notification"
period = "24x7"
}
apply Notification "telegram-notification" to Host {
import "telegram-host-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
apply Notification "telegram-notification" to Service {
import "telegram-service-notification"
user_groups = host.vars.notification.telegram.groups
users = host.vars.notification.telegram.users
assign where host.vars.notification.telegram
}
这就是我所拥有的。正如我之前所说,它适用于某些服务,不适用于其他服务。我没有任何配置service
或host
文件telegram notification
。
为了测试我使用Icinga web2
. 转到主机中的特定服务并发送自定义通知。当我发送自定义通知时,我会检查日志文件以查看是否有任何错误,并显示completed
:
[2017-01-01 11:48:38 +0000] information/Notification: Sending reminder 'Problem' notification 'host-***!serviceName!telegram-notification for user 'my-username'
[2017-01-01 11:48:38 +0000] information/Notification: Completed sending 'Problem' notification 'host-***!serviceName!telegram-notification' for checkable 'host-***!serviceName' and user 'my-username'.
我应该注意到电子邮件按预期发送。12 个服务中有 2 个的电报通知存在问题。
知道罪魁祸首是什么吗?这里有什么问题?脚本(命令)的返回会影响这种行为吗?
任何服务中都没有 Telegram 配置。