appclacks / mirabelle

A stream processing engine for monitoring
Eclipse Public License 1.0
95 stars 5 forks source link

Custom action without params #31

Open faxm0dem opened 2 days ago

faxm0dem commented 2 days ago

I tried adding a cusom action without any parameters:

(defn now*
  "Sets the time of events to right now"
  [_ & children]
  (fn stream [event]
    (let [current-time (quot (System/currentTimeMillis) 1000)
          modevent (assoc event :time current-time)]
      (a/call-rescue modevent children))))

When I try to use it with the following stream:

(streams
  (stream {:name :now :default true}
    (custom :now (index [:host :service]))))

I get the following error message:

{\n :cause Key must be integer\n :via\n [{:type java.lang.IllegalArgumentException\n   :message Key must be integer\n   :at [clojure.lang.APersistentVector invoke APersistentVector.java 297]}]\n :trace\n [[clojure.lang.APersistentVector invoke APersistentVector.java 297]\n  [mirabelle.action$call_rescue invokeStatic action.clj 70]\n  [mirabelle.action$call_rescue invoke action.clj 67]\n  [abricot.core$now_STAR_$stream__254 invoke core.clj 51]\n  [mirabelle.action$call_rescue invokeStatic action.clj 70]\n  [mirabelle.action$call_rescue invoke action.clj 67]\n  [mirabelle.action$sdo_STAR_$stream__2325 invoke action.clj 418]\n  [mirabelle.stream$stream_BANG_ invokeStatic stream.clj 118]\n  [mirabelle.stream$stream_BANG_ invoke stream.clj 116]\n  [mirabelle.stream.StreamHandler push_BANG_ stream.clj 265]\n  [mirabelle.transport.tcp$gen_tcp_handler$handler_fn__13617 invoke tcp.clj 48]\n  [clojure.core$run_BANG_$fn__8880 invoke core.clj 7783]\n  [clojure.lang.ArrayChunk reduce ArrayChunk.java 58]\n  [clojure.core.protocols$fn__8244 invokeStatic protocols.clj 136]\n  [clojure.core.protocols$fn__8244 invoke protocols.clj 124]\n  [clojure.core.protocols$fn__8204$G__8199__8213 invoke protocols.clj 19]\n  [clojure.core.protocols$seq_reduce invokeStatic protocols.clj 31]\n  [clojure.core.protocols$fn__8236 invokeStatic protocols.clj 75]\n  [clojure.core.protocols$fn__8236 invoke protocols.clj
faxm0dem commented 2 days ago

If I add a dummy param like this:

(defn now*
  "Sets the time of events to right now"
  [_ _ & children]
  (fn stream [event]
    (let [current-time (quot (System/currentTimeMillis) 1000)
          modevent (assoc event :time current-time)]
      (a/call-rescue modevent children))))

And use it like this:

(streams
  (stream {:name :now :default true}
    (custom :now [0] (index [:host :service]))))

It works...