Search code examples
clojureriemann

Custom email subject and body in riemann


I am using email alert in riemann. I have hardecoded the value for :subject and `:body'. I am facing some issue in this. I pasted my riemann code and the error I got below. I don't know how to resolve this.

(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 "[email protected]"})])

I got the below error

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.access$700(AbstractCha
nnelHandlerContext.java:32)
        at io.netty.channel.AbstractChannelHandlerContext$8.run(AbstractChannelH
andlerContext.java:324)
        at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecuto
r.java:36)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.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)

When I commented the :subject and :body. I am not getting the error.

Thanks in advance


Solution

  • You have to provide functions for subject and body instead of just strings. From 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))}))
    

    So to just have a constant string you could use:

    (fn [events] "Your Subject Text")