0

I have riemann code to trigger an email when both the condition were met . So I wrote a below code.

(let [email (mailer {....email configuration})]
        (streams
    (where (service "log")
        (smap
          (fn [events]
           (let [count-of-failures (count (filter #(= "failed" (:Status %)) events) and (filter #(= "UK" (:Country %)) events))] ;Calculate the count for matched value
              (event
              {
                 :status "Failure"
                 :metric  count-of-failures 
                 :total-fail (>= count-of-failures 2)})))

          (where (and (= (:status event) "Failure")
                      (:total-fail event))


            (email "xxx@xx.com")
             )prn))))

I am getting below error once I started to execute clojure.lang.ArityException: Wrong number of args (3) passed to:

Can anyone please suggest me a right way to use AND operation here.

Thanks in advance

Mangoski
  • 2,058
  • 5
  • 25
  • 43

1 Answers1

0

you give 3 args to count - therefore you get the error.

why you would truncate the error output right before the essential information ... args (3) passed to: count is beyond me.

(let [email (mailer {....email configuration})]
  (streams
   (where (service "log")
          (smap
           (fn [events]
             (let [count-of-failures (count ; <--- count only takes one argument
                                      (filter #(= "failed" (:Status %)) events)
                                      and
                                      (filter #(= "UK" (:Country %)) events))] ;Calculate the count for matched value
               (event
                {:status "Failure"
                 :metric  count-of-failures
                 :total-fail (>= count-of-failures 2)})))

           (where (and (= (:status event) "Failure")
                       (:total-fail event))
                  (email "xxx@xx.com")) prn))))

It's not clear from your description, did you mean to do:

(count (and (filter ...) (filter ...)) 

Which counts the the last not-nil collection ?


I want to check two condition my Status should be Failed and my country should be UK . If then an email should get triggered

Does that help? :

(def event {:Status "failed" :Country "UK"}) ; example1
(some #(and (= "failed" (:Status %)) (= (:Country %) "UK")) [event])
; => true
(def event {:Status "failed" :Country "US"}) ; example2
(some #(and (= "failed" (:Status %)) (= (:Country %) "UK")) [event])
; => nil
birdspider
  • 3,034
  • 1
  • 16
  • 25
  • `(let [count-of-failures (count (filter #(= "failed" (:Status %)) events)) and (count (filter #(= "UK" (:Country %)) events))] ` . Will this method work? – Mangoski Aug 08 '16 at 11:32
  • I want to check two condition my `Status` should be `Failed` and my `country` should be `UK` . If then an email should get triggered – Mangoski Aug 08 '16 at 11:42