drifter-sender

0.1.3 • Public • Published

drifter-sender

Stability: 1 - Experimental

NPM version

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 = require('drifter-sender');
 
var drifter = new Drifter({
    capability: '02hAozGflu',
    hostname: 'localhost',
    path: '/1/log',
    port: 4443,
    rejectUnauthorized: false
});
 
// optionally listen for responses from Drifter (expect 503)
drifter.on('data', function (data) {
    console.log(data);
});
 
// optionally listen for errors from Drifter
drifter.on('error', function (error) {
    console.log(error);
});
 
// optionally listen for reported telemetry
drifter.on('telemetry', function (telemetry) {
    console.log(telemetry);
});
 
drifter.send("uri=encoded&data=to_send");
// GET /1/log?02hAozGflu&uri=encoded&data=to_send HTTP/1.1\r\n
// Host: localhost\r\n
// \r\n
 
drifter.send("service=mysql&server=db15&unit=B&value=17");
// 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)

  • 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, or service=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().

Event: data

  • 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.

Event: error

  • function (error) {}
    • error: Object An error emitted by the TLS connection.
      • code: String An error code. For example ECONNREFUSED.

Emitted when the TLS connection emits an error.

Event: telemetry

  • 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

Package Sidebar

Install

npm i drifter-sender

Weekly Downloads

1

Version

0.1.3

License

MIT

Last publish

Collaborators

  • tristanls