2

我创建了与电子邮件通知非常相似的自定义电报通知。问题是它适用于主机和大多数服务,但不适用于所有服务。

我不会在*.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
}

这就是我所拥有的。正如我之前所说,它适用于某些服务,不适用于其他服务。我没有任何配置servicehost文件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 配置。

4

1 回答 1

1

由于降价解析器,某些电报命令可能会失败。我遇到过这个问题:如果服务名称有一个下划线('_'),那么解析器会抱怨没有关闭markdown标签并且不会发送消息

于 2017-09-04T11:52:09.487 回答