                      :username "root"
                      :password "root"
                      :db "riemann"
-                     :series :service} opts)
+                     :series :service}
+                    opts)
+        series (:series opts)
         client (influx/make-client opts)]
-    (fn [event]
-      (when (:metric event)
-        (when (:service event)
-          (influx/post-points client (if-let [series (influxdb-series opts event)] series "riemann-events") [{ :name (:service event)
-                                                                                                               :host (if-let [hostname (:host event)] hostname "") 
-                                                                                                               :state (:state event)
-                                                                                                               :value (:metric event) }]))))))
+
+    (fn stream [events]
+      (let [events (if (sequential? events) events (list events))
+            points (events->points series events)]
+        (when-not (empty? points)
+          (doseq [[series points] points]
+            (influx/post-points client series points)))))))

  (:require [capacitor.core :as influx])
  (:use [clojure.string :only [join split]]))

(defn influxdb-series
  "Constructs a series name for an event."
  [opts event]
  ((:series opts) event))
 
(defn influxdb
  "Returns a function which accepts an event and sends it to InfluxDB.

  ;; For giving series name as the concatenation of :host and :service fields with dot separator.

  (influxdb {:host \"play.influxdb.org\" :port 8086 :series #(str (:host %) \".\" (:service %))})

  Options:


  :username       Name of the user who is allowed to push metrics to this DB.

  :password       Password of the corresponding user.

  :series         Function which takes an event and returns the InfluxDB series
                  name to use. Defaults to :service. If this function returns
                  nil, series names default to \"riemann-events\"."
  [opts]
  (let [opts (merge {:host "127.0.0.1"
                     :port 8086
