riemann 中的自定义电子邮件主题和正文

Custom email subject and body in riemann

我在 riemann 中使用电子邮件提醒。我已经对 :subject 和 `:body' 的值进行了硬编码。我在这方面面临一些问题。我粘贴了我的黎曼代码和下面的错误。我不知道如何解决这个问题。

(let [email (mailer {:host "smtp.gmail.com"
                            :port 25
                            :user "user"
                            :pass "password"
                            :auth "true"
                            :subject "Welcome All to Coding"
                            :body "Hello Team, \n Welcome to my coding \n Thank You!"
                            :from "mygmail@gmail.com"})])

我收到以下错误

WARN [2015-07-25 02:10:17,640] defaultEventExecutorGroup-2-2 - riemann.config -
riemann.email$mailer$make_stream__7892$stream__7893@62aa5 threw
java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IF
n
        at riemann.email$email_event.invoke(email.clj:15)
        at riemann.email$mailer$make_stream__7892$stream__7893.invoke(email.clj:
69)
        at riemann.config$eval96$stream__101$fn__106.invoke(riemann_v1.con
fig:39)
        at riemann.config$eval96$stream__101.invoke(riemann_v1.config:39)
        at riemann.streams$smap$stream__3695$fn__3706.invoke(streams.clj:163)
        at riemann.streams$smap$stream__3695.invoke(streams.clj:163)
        at riemann.streams$fixed_time_window_fn$stream__3946$fn__3979.invoke(str
eams.clj:381)
        at riemann.streams$fixed_time_window_fn$stream__3946.invoke(streams.clj:
381)
        at riemann.config$eval96$stream__145$fn__150.invoke(riemann_v1.con
fig:27)
        at riemann.config$eval96$stream__145.invoke(riemann_v1.config:27)
        at riemann.core$stream_BANG_$fn__5678.invoke(core.clj:19)
        at riemann.core$stream_BANG_.invoke(core.clj:18)
        at riemann.transport$handle.invoke(transport.clj:159)
        at riemann.transport.tcp$tcp_handler.invoke(tcp.clj:93)
        at riemann.transport.tcp$gen_tcp_handler$fn__5904.invoke(tcp.clj:65)
        at riemann.transport.tcp.proxy$io.netty.channel.ChannelInboundHandlerAda
pter$ff19274a.channelRead(Unknown Source)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(Abst
ractChannelHandlerContext.java:333)
        at io.netty.channel.AbstractChannelHandlerContext.access0(AbstractCha
nnelHandlerContext.java:32)
        at io.netty.channel.AbstractChannelHandlerContext.run(AbstractChannelH
andlerContext.java:324)
        at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecuto
r.java:36)
        at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThread
EventExecutor.java:116)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorato
r.run(DefaultThreadFactory.java:137)
        at java.lang.Thread.run(Thread.java:745)

当我评论:subject:body的时候。我没有收到错误。

提前致谢

您必须为主题和正文提供函数,而不仅仅是字符串。来自 the docs

By default, riemann uses (subject events) and (body events) to format emails. You can set your own subject or body formatter functions by including :subject or :body in msg-opts. These formatting functions take a sequence of events and return a string.

(def email (mailer {} {:body (fn [events] 
                               (apply prn-str events))}))

因此,您可以使用常量字符串:

(fn [events] "Your Subject Text")