首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向riemann事件注入新场

向riemann事件注入新场
EN

Stack Overflow用户
提问于 2017-11-15 15:59:42
回答 1查看 75关注 0票数 2

我可能不理解riemann/clojure中的一些关键概念。我试图解析字段:使用"aaa:1234.bbbb.cccc.ddddd"格式的事件服务,并使用"with“函数向事件添加新的字段pid。任何人都可以向我解释为什么riemann.config中的代码会抛出异常:

代码语言:javascript
复制
...
(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)"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-16 11:06:16

我猜(where (service ,,,))只是(where* (fn [event] (let [service (:service event)] ,,,)))where宏的语法糖,这就是为什么不能在where的主体中使用service的原因:它不是一个定义好的名称。

看看文档 for with,在我看来,您应该使用smap

代码语言:javascript
复制
(where (service #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)")
   (smap (fn [e] (assoc e :pid (str/replace (:service e) #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)" "$2")))))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47311961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档