From d123678766b26b553c72a4c6e8d255afdd90ebe8 Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Sun, 10 May 2015 00:22:11 +0200 Subject: insert influxdb --- ebus-racket/inserter.rkt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ebus-racket/inserter.rkt') diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt index b234ad9..c4a693b 100755 --- a/ebus-racket/inserter.rkt +++ b/ebus-racket/inserter.rkt @@ -15,6 +15,7 @@ (define connect-port? (make-parameter null)) (define insert? (make-parameter #f)) (define baseurl? (make-parameter "http://localhost:8080/api/value")) +(define influxurl? (make-parameter "http://db.2.localnet.cc:8001/write/ZQYZHSLWEIWCMXIYQSKAOCFCFWEVFK")) ;; Send field and value to database server @@ -36,6 +37,18 @@ (else (error "server-error" url raw-value server-response)))))) +(define (insert-influxdb sensor-name datatype value) + (if (layer7-ersatzwert? value) + (log-inserter-info "Skipping Ersatzwert for ~a/~a" sensor-name datatype) + (let ([data (hash 'database "ebus" + 'points (list (hash 'name sensor-name + 'fields (hash 'value value + 'type (symbol->string datatype)))))]) + (log-inserter-info (format "influxdb: ~a~n" (jsexpr->string data))) + (define input-port (post-impure-port (string->url (influxurl?)) (string->bytes/utf-8 (jsexpr->string data)))) + (define server-response (read-line input-port)) + (log-inserter-info "Response: ~a" server-response)))) + (define (handle-packet packet) (for ([field packet]) (when (insert?) @@ -45,6 +58,7 @@ (log-inserter-error "TCP Read exception ~a" exn))] [exn:fail:network? (lambda (exn) (log-inserter-error "TCP Exception ~a" exn))]) + (apply insert-influxdb field) (apply insert-field field))))) (define-namespace-anchor repl-ns-anchor) -- cgit v1.2.1