clojure - Event count at certain time interval in riemann -
i have check number of count appearing in event @ each interval of every 30 seconds. if count greater 5 means, need trigger email.
i using below code, email didn't triggered.
(let [userindex1 (default :ttl 300 (update-index (index)))] (streams prn userindex1)) (streams (where (and (service "system_log") (not (expired? event))) ; fixed-time-window sends vector of events out every 30 seconds (fixed-time-window 30 ; smap passes events function (smap (fn [events] ;calculate no of count of events failure (let [numberoffailure (count (filter #(="ie" (:description %)) events))] {:status "login failures" :metric numberoffailure :totalfail (boolean(numberoffailure > 5))} (streams prn numberoffailure)))) ;check if variable status true if condition satisfied trigger email (let [email (mailer {:host "smtp.gmail.com" :port 25 :user "aaaaa" :pass "bbbbb" :auth "true" :subject (fn [events] (clojure.string/join ", " (map :service events))) :from "abc@gmail.com"})] (streams (where (and (:status "login failures") (:totalfail true)) (email "123@gmail.com"))))))) where going wrong?
there couple of issues here. i'll try address of them, post minimal working example:
the first fn passed smap should return event. event can created
eventorassoc'ing 1 of received events. in sample plain map created (which not work, it's not proper event), that's lost becausestreamscalled (which afaik should called @ top level). instead of:(smap (fn [events] (let [numberoffailure ...] {:status "login failures" :metric numberoffailure :totalfail (boolean ...)} (streams prn numberoffailure))) ...)you should like:
(smap (fn [events] (let [numberoffailure ...] (event {:status "login failures" :metric numberoffailure :totalfail (boolean ...)})) ...)to calculate
totalfailremember need use prefix notation call>, must(> totalfail 5). ,booleannot needed,>return boolean.i initialize mailer out of top-level
streamscall, enclosing scope usingletordef. should work is.you should pass last
wherechildren stream smap, must second argument smap. let's recall smap docs:(smap f & children) streaming map. calls children (f event), whenever (f event) non-nil. prefer (adjust f) , (combine f). example: (smap :metric prn) ; prints metric of each event. (smap #(assoc % :state "ok") index) ; indexes each event state "ok"the last
whereshould not enclosedstreams, ,andsentence must work onevent, must be:(where (and (= (:status event) "login failures") (:total-fail event)) (email "123@gmail.com"))the
:subjectfnmailershould passed part of second map, explained inmailerdocumentationthere's open issue on
fixed-time-windowmakes bit unreliable: doesn't fire time window due waits until new event fired, might want use different windowing strategy until get's fixed.
here goes full minimal working example based on yours:
(let [email (mailer {:host "localhost" :port 1025 :from "abc@gmail.com"})] (streams (where (and (service "system_log") (not (expired? event))) (fixed-time-window 5 (smap (fn [events] (let [count-of-failures (count (filter #(= "ie" (:description %)) events))] (event {:status "login failures" :metric count-of-failures :total-fail (>= count-of-failures 2)}))) (where (and (= (:status event) "login failures") (:total-fail event)) (email "hello123@gmail.com")))))))
Comments
Post a Comment