1

我正在尝试使用 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 中。

4

1 回答 1

0

来自文档

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

所以问题是您想从序列中的哪个事件中获取时间戳?如果您在序列中查找关键字,而不是该序列的成员之一,您将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 进行警报时,我个人的意见是将被警报的事物包装到固定的时间窗口中,并使用该窗口开始时的时间戳,尽管这主要是因为个人喜好。

于 2015-11-20T16:58:40.193 回答