简体   繁体   English

如何在黎曼使用AND运算

[英]How to use AND operation in Riemann

I have riemann code to trigger an email when both the condition were met . 当两个条件都满足时,我有riemann代码可以触发电子邮件。 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: 一旦开始执行clojure.lang.ArityException: Wrong number of args (3) passed to:我就遇到了以下错误clojure.lang.ArityException: Wrong number of args (3) passed to:

Can anyone please suggest me a right way to use AND operation here. 任何人都可以在这里建议我使用AND运算的正确方法。

Thanks in advance 提前致谢

you give 3 args to count - therefore you get the error. 您给3个参数count -因此您得到了错误。

why you would truncate the error output right before the essential information ... args (3) passed to: count is beyond me. 为什么在基本信息之前截断错误输出... 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))))

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 . 我想检查两个条件,我的身份应该为Failed,我的国家应该是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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM