0

当两个条件都满足时,我有 riemann 代码来触发电子邮件。所以我写了下面的代码。

(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))))

一旦我开始执行,我就会遇到错误clojure.lang.ArityException: Wrong number of args (3) passed to:

谁能建议我在这里使用AND操作的正确方法。

提前致谢

4

1 回答 1

0

你给 3 个参数count- 因此你得到错误。

... args (3) passed to: count为什么你会在基本信息超出我之前截断错误输出。

(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))))

从您的描述中不清楚,您是否打算这样做:

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

哪个算最后一个非零集合?


我想检查两个条件,我的 Status 应该是 Failed ,我的国家应该是 UK 。如果那时应该触发一封电子邮件

这有帮助吗?:

(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
于 2016-08-08T11:22:21.297 回答