【问题标题】:Injecting new field to riemann event为黎曼事件注入新领域
【发布时间】:2017-11-16 19:06:16
【问题描述】:

我可能不理解 riemann/clojure 中的一些关键概念。 我正在尝试从格式为"aaa:1234.bbbb.cccc.ddddd" 的事件解析字段:service,并使用函数“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)"

【问题讨论】:

    标签: clojure riemann


    【解决方案1】:

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

    查看documentation 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")))))
    

    【讨论】:

    • @user8173324 酷!那么请接受答案,让人们知道这个问题已经解决了:)
    猜你喜欢
    • 2016-02-14
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    相关资源
    最近更新 更多