drifter-sender
Stability: 1 - Experimental
Send messages (logs, telemetry, or events) to Drifter.
Overview
drifter-sender
is a Node.js module for sending messages (logs, telemetry, or events) to Drifter. It encodes the message as a query string and issues an HTTPS GET request to the specified destination.
Usage
"use strict"; var Drifter = ; var drifter = capability: '02hAozGflu' hostname: 'localhost' path: '/1/log' port: 4443 rejectUnauthorized: false; // optionally listen for responses from Drifter (expect 503)drifter; // optionally listen for errors from Drifterdrifter; // optionally listen for reported telemetrydrifter; drifter;// GET /1/log?02hAozGflu&uri=encoded&data=to_send HTTP/1.1\r\n// Host: localhost\r\n// \r\n drifter;// GET /1/log?02hAozGflu&service=mysql&server=db15&unit=B&value=17 HTTP/1.1\r\n// Host: localhost\r\n// \r\n
Tests
npm test
Documentation
- new Drifter(config)
- drifter.connect()
- drifter.send(message)
- drifter.sendMessages()
- Event 'data'
- Event 'error'
- Event 'telemetry'
new Drifter(config)
config
: Object (Default: undefined)capability
: String The capability string to use.hostname
: String Drifter hostname to connect to.path
: String Drifter path to connect to.port
: Number (Default: 443) Port to connect to.rejectUnauthorized
: Boolean (Default: true) If true, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails.
Creates a new Drifter sender instance.
Drifter sender communicates only via TLS.
drifter.connect()
CAUTION: reserved for internal use
Creates a TLS connection to self.hostname:self.port
and sends all the messages in the buffer.
drifter.send(message)
message
: String URI encoded data to send. For example:foo=bar
, orservice=mysql&server=db15&unit=B&value=17
Pushes message
onto a local buffer to send to Drifter server. If a connection currently doesn't exist, it starts connecting. Once Drifter sender is connected, it sends all the messages in the buffer.
drifter.sendMessages()
CAUTION: reserved for internal use
If there are messages in the buffer, sends the message to self.hostname:self.port
via HTTPS over the currently open connection. The request looks like:
GET <self.path>?<self.capability>&<message> HTTP/1.1\r\n
HOST: <self.hostname>\r\n
\r\n
If there are more messages in the buffer to send, schedules the next invocation of drifter.sendMessages()
via setImmediate()
.
data
Event: function (data) {}
data
: String Any data returned by Drifter server.
Emitted when Drifter server acknowledges receipt of a message. Expected response is an HTTP response HTTP/1.1 503 Service Unavailable
with associated headers.
error
Event: function (error) {}
error
: Object An error emitted by the TLS connection.code
: String An error code. For exampleECONNREFUSED
.
Emitted when the TLS connection emits an error.
telemetry
Event: function (telemetry) {}
telemetry
: String A self-describing querystring encoded telemetry string.
Emitted when Drifter sender has telemetry to report. For example:
module=drifter-sender&module_version=0.0.0&target_type=timer&operation=secure_connect&unit=ns&value=3713603