以下Clojure代码会导致NPE。从堆栈跟踪看来,这是在调用>=
时引起的。我似乎无法弄清楚为什么会这样。
(def service-thresholds
[{:service "cpu idle" :invert true :warning 50 :critital 10}
{:service "cpu user" :invert false :warning 80 :critical 90}])
(defn threshold-check
[thresholds]
(fn [e]
(or (first (for [threshold thresholds
:when (= (:service threshold) (:service e))]
(assoc e :state
(if (not (:invert threshold))
(condp <= (:metric e)
(:critical threshold) "critical"
(:warning threshold) "warning"
"ok")
(condp >= (:metric e)
(:critical threshold) "critical"
(:warning threshold) "warning"
"ok")))))
e)))
(println ((threshold-check service-thresholds) {:service "cpu idle" :metric 20 :state nil}))
答案 0 :(得分:3)
:critital
拼写不正确:critical
。