我可能不理解riemann/clojure中的一些关键概念。我试图解析字段:使用"aaa:1234.bbbb.cccc.ddddd"格式的事件服务,并使用"with“函数向事件添加新的字段pid。任何人都可以向我解释为什么riemann.config中的代码会抛出异常:
...
(let [index (default :ttl 300 (update-index (index)))]
; Inbound events will be passed to these streams:
(streams
index
(where (service #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)")
(with :pid (str/replace service #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)" "$2")
)
)
...
user=> (riemann.bin/reload!)
#error {
:cause "Unable to resolve symbol: service in this context"
:via
[{:type clojure.lang.Compiler$CompilerException
:message "java.lang.RuntimeException: Unable to resolve symbol: service in this context, compiling:(/etc/riemann/riemann.config:73:19)"发布于 2017-11-16 11:06:16
我猜(where (service ,,,))只是(where* (fn [event] (let [service (:service event)] ,,,)))的where宏的语法糖,这就是为什么不能在where的主体中使用service的原因:它不是一个定义好的名称。
看看文档 for with,在我看来,您应该使用smap
(where (service #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)")
(smap (fn [e] (assoc e :pid (str/replace (:service e) #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)" "$2")))))https://stackoverflow.com/questions/47311961
复制相似问题