2017-11-15 11 views
2

리만/클루저의 주요 개념을 이해하지 못하고 있습니다. 형식 : "aaa:1234.bbbb.cccc.ddddd" 인 이벤트의 field : service를 구문 분석하고 "with"기능을 사용하여 이벤트에 새 필드 pid를 추가하려고합니다. 당신이 where의 본문에 service를 사용할 수없는 이유입니다 (where* (fn [event] (let [service (:service event)] ,,,)))where 매크로에 의해 단지 문법 설탕을 내가 (where (service ,,,)) 생각리먼 이벤트에 새 필드 삽입

... 
(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)" 

답변

1

된다 riemann.config이 코드가 예외를 던지는 이유 아무도 나에게 설명 할 수 : 정의 된 이름이 아닙니다. 함께

documentation 보면, 그것은 나에게 보인다는 smap을 사용해야합니다 조언

(where (service #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)") 
    (smap (fn [e] (assoc e :pid (str/replace (:service e) #"(\w+):(\d+)\.(\w+)\.(\w+)\.(\w+)" "$2"))))) 
+0

예, 감사합니다, 그것은 작동 : – user8173324

+0

user8173324 @ 멋진! 사람들이이 질문을 해결할 수 있도록 답변을 수락하십시오 :) –