/
keenio.clj
35 lines (31 loc) · 1.1 KB
/
keenio.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns riemann.keenio
"Forwards events to Keen IO"
(:require [clj-http.client :as client])
(:require [cheshire.core :as json]))
(def ^:private event-url
"https://api.keen.io/3.0/projects/")
(defn post
"POST to Keen IO."
[collection project-id write-key request]
(let [final-event-url
(str event-url project-id "/events/" collection)]
(client/post final-event-url
{:body (json/generate-string request)
:query-params { "api_key" write-key }
:socket-timeout 5000
:conn-timeout 5000
:content-type :json
:accept :json
:throw-entire-message? true})))
(defn keenio
"Creates a keen adapter. Takes your Keen project id and write key, and
returns a function that accepts an event and sends it to Keen IO. The full
event will be sent.
```clojure
(streams
(let [kio (keenio \"COLLECTION_NAME\" \"PROJECT_ID\" \"WRITE_KEY\")]
(where (state \"error\") kio)))
```"
[collection project-id write-key]
(fn [event]
(post collection project-id write-key event)))