【问题标题】:Custom body message in riemann email黎曼电子邮件中的自定义正文消息
【发布时间】:2016-02-22 19:45:01
【问题描述】:

我正在尝试使用 riemann 在电子邮件的正文部分创建自定义消息。 我无法动态附加该字段。

黎曼配置:

(let [email (mailer 
              {:host "XXXXX" :port XX :user "XXX" :pass "XXX" :auth "true"
               :subject (fn [events] "Team")
               :body (fn [events] 
                       (apply str "Hello Team, now the time is" (:timestamp event) "Thank You!"))
               :from "xxx@gmail.com"})]

我的输出:

Hello Team, now the time is Thank You!

我的预期输出:

Hello Team, now the time is 12:13:45 Thank You!.

我的时间戳没有附加在 :body 中。

【问题讨论】:

  • 您的参数是events,而您从event 读取(缺少s)。先从(pr-str events) 开始,看看你会得到什么。
  • 我尝试使用(pr-str events) 我得到了事件:timestamp. 但是当我尝试使用(apply str "Hello Team, now the time is" (:timestamp events) "Thank You!")). 时,我没有得到:timestamp 的值被附加到我的字符串中。
  • 请将 pr-str 添加到问题中

标签: clojure riemann


【解决方案1】:

来自the docs

这些格式化函数采用一系列 事件并返回一个字符串。

所以问题是您想从序列中的哪个事件中获取时间戳?如果您在序列中查找关键字,而不是该序列的成员之一,您将默认返回 nil

core> (:asdf '(1 2 3))
nil

如果您将apply str 转换为其他几个字符串,它将无效,因为str 将忽略它。这是你的输出来自哪里。这是一个类似的示例函数:

core> (let [body-fn (fn [events]
                        (apply str "Hello Team, now the time is"
                               (:timestamp events)
                               "Thank You!"))]
        (body-fn [{:timestamp 42} {:timestamp 43}]))
"Hello Team, now the time isThank You!"

如果我们从第一个事件中选择时间戳:

core> (let [body-fn (fn [events]
                        (apply str "Hello Team, now the time is"
                               (:timestamp (first events))
                               "Thank You!"))]
        (body-fn [{:timestamp 42} {:timestamp 43}]))
"Hello Team, now the time is42Thank You!"

当通过 riemann 发出警报时,我个人的看法是将被警报的事物包装到固定的时间窗口中,并使用该窗口开始时的时间戳,尽管这主要是因为个人喜好。

【讨论】:

  • 我已经用这种方法 (:timestamp (first events)) 更新了我的代码,但我仍然没有得到我传递给 riemann 的值。
  • 您是否仍然收到带有字符串“Hello Team,现在是时候谢谢您!”的电子邮件了? (这表明它仍然为零)或者您根本没有收到电子邮件?
  • 我收到了电子邮件,但我仍然只收到这个字符串“你好团队,现在是时候谢谢你了!”,我的自定义字段 :timestamp 值没有附加到我的消息中
猜你喜欢
  • 2018-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多