3

i'm switching over from nagios to sensu. i'm using chef to automated the process. everything is working great except the mailer or actually, i narrowed it down to the "pipe" that is suppose to redirect the json output from the check to the handler. it doesn't. when i use

{
  "handlers": {
    "email": {
      "type": "pipe",
      "command": "mail -s \"sensu alert\" alert@example.com",
      "severities": [
        "ok",
        "critical"
      ]
    }
  }
}

i get a blank email. when i use the mailer.rb handler, i get no email whatsoever. i made sure to include mail to and mail from in the mailer.json. i see the logs have the correct information for the handler and email parameters.

so i've concluded the "pipe" isn't working. can anybody help with that? i would greatly appreciate it. i wish there was a sensu community, but it may be too new to have one.

4

6 回答 6

2

关于 mailer.rb,您是否检查了服务器日志(默认情况下/var/log/sensu/sensu-server.log)是否有错误?如果任何处理程序中有错误,它们将显示在这些日志中。

mailer.rb 需要几个 gem 才能运行。要了解您是否使用 sensu 的嵌入式 ruby​​,请检查/etc/default/sensuEMBEDDED_RUBY。如果这是错误的,您将需要确保您的系统 ruby​​ 安装了所有这些 gem(sensu-handler、mail、timeout)。如果设置为 true,对 sensu 的嵌入式 ruby​​ 执行相同操作:

/opt/sensu/embedded/bin/gem list

确保 gems 已安装,再试一次,并检查 sensu-server.log 是否有错误。

如果您有更多问题,实际上有一个社区 - 查看 Freenode 上的#sensu。

于 2013-08-02T20:43:10.510 回答
2

您可以编写自己的事件数据 JSON并将其通过 PIPE 传递,如下所示:

cat event.json | /opt/sensu/embedded/bin/ruby mailer.rb

获取 event.json 文件的最简单方法是从 sensu-server.log。

于 2013-12-12T11:06:04.850 回答
1

要使用 mailer.rb,您需要自己的邮件服务器!如果您发布 sensu 服务器日志,我想我可以帮助您。

于 2013-08-25T08:56:17.813 回答
0

我已经进行了一些测试,并且邮件到管道中使用 GNU mail/mailx(假设您使用的是 Ubuntu 或其他东西?)。

两种解决方案:

1)安装BSD邮件:

sudo apt-get install bsd-mailx

2)或稍微修改命令 get mail 以从标准输入读取,您需要执行以下操作:

{
  "handlers": {
    "email": {
      "type": "pipe",
      "command": " echo $(cat) > /tmp/mail.txt;  mail -s \"sensu alert\" alert@example.com < /tmp/mail.txt"
    }
  }
}

这个想法通常是您在脚本语言中从标准输入读取事件 json,然后提取您想要发送的 event.json 位。以上将通过电子邮件发送整个 json 文件。

于 2014-01-02T17:10:57.463 回答
0

您可以使用 sensu 邮件处理程序。请找到以下设置步骤:-

  1. sensu-install -p sensu-plugins-mailer
  2. apt-get install postifx
  3. /etc/init.d/postfix start
  4. cd /etc/sensu/conf.d/

当我们安装这个插件时会得到 3 个 ruby​​ 文件。

这次我们使用这个文件:- handler-mailer.rb

首先,我们需要在此位置 /etc/sensu/conf.d/ 创建处理程序文件:-

  1. vim 处理程序-mailer.json

    { "mailer": { "admin_gui": "http://127.0.0.1:3000/", "mail_from": "localhost", "mail_to": ["yourmailid-1","yourmailid-2"], "smtp_address": "localhost", "smtp_port": "25" } }

现在我们需要在 /etc/sensu/conf.d/ 这个位置创建一个邮件处理程序文件:-

  1. { "handlers": { "mymailer": { "type": "pipe", "command": "/opt/sensu/embedded/bin/handler-mailer.rb", "severities": [ "critical", "unknown" ] } } }

在上面的文件处理程序名称是 mymailer 我们需要在我们的检查中使用这个处理程序名称。

于 2017-03-31T07:41:41.877 回答
0

使用bin/handler-mailer-mailgun.rbbin/handler-mailer-ses.rbbin/handler-mailer.rb

例子:

echo '{
"id": "ef6b87d2-1f89-439f-8bea-33881436ab90",
"action": "create",
"timestamp": 1460172826,
"occurrences": 2,
"check": {
  "type": "standard",
  "total_state_change": 11,
  "history": ["0", "0", "1", "1", "2", "2"],
  "status": 2,
  "output": "No keepalive sent from client for 230 seconds (>=180)",
  "executed": 1460172826,
  "issued": 1460172826,
  "name": "keepalive",
  "thresholds": {
    "critical": 180,
    "warning": 120
  }
},
"client": {
  "timestamp": 1460172596,
  "version": "1.0.0",
  "socket": {
    "port": 3030,
    "bind": "127.0.0.1"
  },
  "subscriptions": [
    "production"
  ],
  "environment": "development",
  "address": "127.0.0.1",
  "name": "client-01"
} }' | /opt/sensu/embedded/bin/handler-mailer-mailgun.rb

输出:

mail -- sent alert for client-01/keepalive to your.email@example.com
于 2019-09-21T12:27:15.083 回答