I'm new to Riemann and Clojure. All I want to do is to send email notifications to three email groups when some service's TTL is expired. I created some sort of config file where I store a list of emails:
{
:email_group_1 (
"[email protected]"
"[email protected]"
)
:email_group_2 (
"[email protected]"
)
}
My riemann config looks like this:
(logging/init {:console true})
(import org.apache.log4j.Level)
(logging/set-level Level/DEBUG)
(require '[clojure.java.io :as io])
(import '[java.io PushbackReader])
(let [host "0.0.0.0"]
(tcp-server {:host host :port 60001})
(udp-server {:host host})
(ws-server {:host host :port 60003}))
(repl-server {:host "127.0.0.1"})
(def cwd (System/getProperty "user.dir"))
(def emails
(with-open [r (io/reader (str cwd "/etc/emails.clj"))]
(read (PushbackReader. r))))
(periodically-expire 5)
(def email (mailer))
(defn notify [& egroups]
(for [egroup egroups]
(rollup 1 60 (apply email (emails egroup)))))
(let [index (index)]
(streams
(default :ttl 60
index
(expired
(where (service "service_connect_active")
#(info "expired" %)
(notify :email_group_1 :email_group_2))))))
Code looks good (for me), but when this service is expired I get the following error:
09:45:39 riemann.1 | INFO [2015-05-08 10:45:39,313] Thread-5 - riemann.config - expired {:ttl 60, :time 357766884827/250, :state expired, :service service_connect_active, :host ava.local}
09:45:39 riemann.1 | WARN [2015-05-08 10:45:39,319] Thread-5 - riemann.config - clojure.lang.LazySeq@841649b8 threw
09:45:39 riemann.1 | java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn
09:45:39 riemann.1 | at riemann.config$eval66$stream__70$fn__75.invoke(riemann.development.config:34)
09:45:39 riemann.1 | at riemann.config$eval66$stream__70.invoke(riemann.development.config:45)
09:45:39 riemann.1 | at riemann.streams$match$stream__3514$fn__3525.invoke(streams.clj:1209)
09:45:39 riemann.1 | at riemann.streams$match$stream__3514.invoke(streams.clj:1209)
09:45:39 riemann.1 | at riemann.streams$default$stream__3731$fn__3742.invoke(streams.clj:1328)
09:45:39 riemann.1 | at riemann.streams$default$stream__3731.invoke(streams.clj:1328)
09:45:39 riemann.1 | at riemann.core$stream_BANG_$fn__4415.invoke(core.clj:19)
09:45:39 riemann.1 | at riemann.core$stream_BANG_.invoke(core.clj:18)
09:45:39 riemann.1 | at riemann.core$reaper$worker__4529$fn__4539.invoke(core.clj:303)
09:45:39 riemann.1 | at riemann.core$reaper$worker__4529.invoke(core.clj:297)
09:45:39 riemann.1 | at riemann.service.ThreadService$thread_service_runner__1973$fn__1974.invoke(service.clj:71)
09:45:39 riemann.1 | at riemann.service.ThreadService$thread_service_runner__1973.invoke(service.clj:70)
09:45:39 riemann.1 | at clojure.lang.AFn.run(AFn.java:22)
09:45:39 riemann.1 | at java.lang.Thread.run(Thread.java:745)
Could someone please help me? Thanks.
The "cannot to be cast to clojure.lang.IFn" error invariably points to something that is expecting a function being given something that cannot be treated as such...
(defn notify [& egroups]
(for [egroup egroups]
(rollup 1 60 (apply email (emails egroup)))))
This returns a for-generated LazySeq of rollup streams, not an actual stream (in Riemann a stream is-an IFn). So when Riemann tries to invoke the stream as an IFn your error occurs...
How about something like:
(defn notify [& egroups]
(rollup 1 60 (apply email (mapcat emails egroups))))
Here we just convert the list of groups to a list of emails upfront and then get on with our lives.
Alternatively if you really want multiple streams (avoiding shared To: lines for example), then apply them to the rollup.
(defn notify [& egroups]
(apply rollup 1 60 (map email (map emails groups))))
Hope this helps, I obviously don't have your whole config replicated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With