updated documents

This commit is contained in:
Craig Yamato
2018-09-25 19:12:40 +00:00
parent eb3d0b5470
commit 1b83a3e15d
14 changed files with 1292 additions and 1316 deletions

View File

@ -41,17 +41,18 @@
<section>
<article>
<pre class="prettyprint source linenums"><code>/** Copyright (c) 2018 Craig Yamato */
<pre class="prettyprint source linenums"><code>// INDEX.JS
/** Copyright (c) 2018 Craig Yamato */
/**
* @fileoverview The SyslogPro module for sending syslog messages
* Most APIs will return a promise. These APIs can be used using
* `then(...)/catch(...)`
*
* Syslog formating classes can be used as input into a Syslog class to be used
* simultatniusly to the same Syslog server. The Syslog Class with a configured
* Syslog server target can also be used as the input into each of the formating
* classes so that they may run independtly.
* Syslog formatting classes can be used as input into a Syslog class to be used
* simultaneously to the same Syslog server. The Syslog Class with a configured
* Syslog server target can also be used as the input into each of the formatting
* classes so that they may run independently.
* @author Craig Yamato &lt;craig@kentik.com>
* @copyright (c) 2018 - Craig Yamato
* @version 0.1.0
@ -72,7 +73,7 @@ const fs = require("fs");
* @private
* @param {string} hex - The color hex code in the form of #FFFFFF or Number of
* the ANSI color code (30-37 Standard &amp; 0-255 Extended)
* @returns {Promise} - The formated ANSI color code
* @returns {Promise} - The formatted ANSI color code
* @throws {Error} - A Format Error
*/
function rgbToAnsi (hex, extendedColor) {
@ -137,11 +138,11 @@ function rgbToAnsi (hex, extendedColor) {
/**
* A class to work with syslog messages using UDP, TCP, or TLS transport.
* There is suport for Syslog message formating RFC-3164, RFC-5424 including
* There is support for Syslog message formatting RFC-3164, RFC-5424 including
* Structured Data, IBM LEEF (Log Event Extended Format), and HP CEF (Common
* Event Format).
* Syslog formating classes can be used as input into a Syslog class to be used
* simultatniusly to the same Syslog server. *
* Syslog formatting classes can be used as input into a Syslog class to be used
* simultaneously to the same Syslog server. *
* @requires moment
* @version 0.0.0
* @since 0.0.0
@ -154,27 +155,27 @@ class Syslog {
* @since 0.0.0
* @this Syslog
* @param {object} [options] - Options object
* >>>Transport Configuraton
* >>>Transport Configuration
* @param {string} [options.target='localhost'] - The IP Address|FQDN of the
* Syslog Server, this option if set will take prasdents over any target
* set in a formating object
* @param {string} [options.protocol='udp'] - L4 transport portocol
* (udp|tcp|tls), this option if set will take prasdents over any transport
* set in a formating object
* Syslog Server, this option if set will take presidents over any target
* set in a formatting object
* @param {string} [options.protocol='udp'] - L4 transport protocol
* (udp|tcp|tls), this option if set will take presidents over any transport
* set in a formatting object
* @param {number} [options.port=514] - IP port, this option if set will take
* prasdents over any IP Port set in a formating object
* presidents over any IP Port set in a formatting object
* @param {number} [options.tcpTimeout=10000] - Ignored for all other
* transports, this option if set will take prasdents over any timeout
* set in a formating object
* @param {string[]} [options.tlsServerCerts] - Array of authrized TLS server
* certificates file locations, this option if set will take prasdents
* over any certificates set in a formating object
* transports, this option if set will take presidents over any timeout
* set in a formatting object
* @param {string[]} [options.tlsServerCerts] - Array of authorized TLS server
* certificates file locations, this option if set will take presidents
* over any certificates set in a formatting object
* @param {string} [options.tlsClientCert] - Client TLS certificate file
* location that this client should use, this option if set will take
* prasdents over any certificates set in a formating object
* presidents over any certificates set in a formatting object
* @param {string} [options.tlsClientKey] - Client TLS key file
* location that this client should use, this option if set will take
* prasdents over any certificates set in a formating object
* presidents over any certificates set in a formatting object
* >>>Syslog Format Settings
* @param {string} [options.format='none'] - Valid syslog format options for
* this module are 'none', 'rfc3164', 'rfc5424', 'leef', 'cef'
@ -185,7 +186,7 @@ class Syslog {
* @param {LEEF} [options.leef] - {@link module:SyslogPro~LEEF|IBM LEEF
* (Log Event Extended Format) object}
* @param {CEF} [options.cef] - {@link module:SyslogPro~CEF|HP CEF
* (Common Event Format) formating object}
* (Common Event Format) formatting object}
*/
constructor (options) {
this.constructor__ = true;
@ -272,9 +273,9 @@ class Syslog {
}
/**
* Add a TLS server certificate which can be used to authentacat the server
* this syslog client is connecting too. This function will valadate the
* input as a file location straing and add it to an array of certificates
* Add a TLS server certificate which can be used to authenticate the server
* this syslog client is connecting too. This function will validate the
* input as a file location string and add it to an array of certificates
* @private
* @version 0.0.0
* @since 0.0.0
@ -290,7 +291,7 @@ class Syslog {
} else if (typeof certs === 'string') {
this.tlsServerCerts = [certs];
} else {
let errMsg = 'TYPE ERROR: Server Cert file loctions shoudl be a string';
let errMsg = 'TYPE ERROR: Server Cert file locations should be a string';
errMsg += ' or array of strings';
reject(new Error(errMsg));
}
@ -300,8 +301,8 @@ class Syslog {
/**
* Send the Syslog message over UDP
* @private
* @param {string} msg - The formated Syslog Message
* @returns {Promise} - The Syslog formated string sent
* @param {string} msg - The formatted Syslog Message
* @returns {Promise} - The Syslog formatted string sent
* @throws {Error} - Network Error
*/
udpMessage (msg) {
@ -329,8 +330,8 @@ class Syslog {
/**
* Send the Syslog message over TCP
* @private
* @param {string} msg - The formated Syslog Message
* @returns {Promise} - The Syslog formated string sent
* @param {string} msg - The formatted Syslog Message
* @returns {Promise} - The Syslog formatted string sent
* @throws {Error} - Timeout error for TCP and TLS connections
* @throws {Error} - Network Error
*/
@ -375,8 +376,8 @@ class Syslog {
/**
* Send the Syslog message over TLS
* @private
* @param {string} msg - The formated Syslog Message
* @returns {Promise} - The Syslog formated string sent
* @param {string} msg - The formatted Syslog Message
* @returns {Promise} - The Syslog formatted string sent
* @throws {Error} - Timeout error for TCP and TLS connections
* @throws {Error} - Network Error
*/
@ -421,7 +422,7 @@ class Syslog {
tlsOptions.ca = tlsOptionsCerts;
tlsOptions.rejectUnauthorized = true;
}
const client = tls.connect(tlsOptions, () => {
const client = tls.connect(tlsOptions, () => {
// Turn msg in to a UTF8 buffer
let msgBuffer = Buffer.from(msg, 'utf8');
client.write(msgBuffer, () => {
@ -429,7 +430,6 @@ class Syslog {
});
});
client.setTimeout(this.tcpTimeout);
// client.on('data', (data) => {});
client.on('end', () => {
resolve(msg);
});
@ -447,8 +447,8 @@ class Syslog {
* Send the Syslog message to the selected target Syslog server using the
* selected transport.
* @private
* @param {string} msg - The formated Syslog Message
* @returns {Promise} - The Syslog formated string sent
* @param {string} msg - The formatted Syslog Message
* @returns {Promise} - The Syslog formatted string sent
* @throws {Error} - Timeout error for TCP and TLS connections
* @throws {Error} - Network Error
*/
@ -484,7 +484,7 @@ class Syslog {
reject(reson);
});
} else {
let errorMsg = 'FORMAT ERROR: Protocol not reconized, should be ';
let errorMsg = 'FORMAT ERROR: Protocol not recognized, should be ';
errorMsg += 'udp|tcp|tls';
reject(new Error(errorMsg));
}
@ -493,38 +493,38 @@ class Syslog {
}
/**
* A class to work with RFC3164 formated syslog messages. The meesaging is fully configurabule and Ansi foreground
* colors can be added. Both ANSI 8 and ANSI 256 color are fully suported.
* A class to work with RFC3164 formatted syslog messages. The messaging is fully configurable and ANSI foreground
* colors can be added. Both ANSI 8 and ANSI 256 color are fully supported.
* Most APIs will return a promise. These APIs can be used using
* `then(...)/catch(...)`
*
* A Syslog class with a configured
* Syslog server target can also be used as the input into the formating
* classes so that it may run independtly.
* Syslog server target can also be used as the input into the formatting
* classes so that it may run independently.
*
* The RFC3164 Syslog logging format is ment to be used as a stream of log data
* from a service or applacation. This class is designed to be used in this
* fashion where new messages are writen to the class as needed.
* The RFC3164 Syslog logging format is meant to be used as a stream of log data
* from a service or application. This class is designed to be used in this
* fashion where new messages are written to the class as needed.
* @requires moment
* @version 0.0.0
* @since 0.0.0
*/
class RFC3164 {
/**
* Construct a new RFC3164 formated Syslog object with user options
* Construct a new RFC3164 formatted Syslog object with user options
* @public
* @this RFC3164
* @param {object} [options] - Options object
* @param {string} [options.applacationName='NodeJSLogger'] - Applacation
* @param {string} [options.applacationName='NodeJSLogger'] - Application
* @param {string} [options.hostname=os.hostname] - The name of this server
* @param {number} [options.facility=23] - Facility code to use sending this
* message
* @param {boolean} [options.color=false] - Apply color coding encoding tag
* with syslog message text
* @param {boolean} [options.extendedColor=false] - Use the extedned ANSI
* @param {boolean} [options.extendedColor=false] - Use the extended ANSI
* color set encoding tag with syslog message text
* @param {object} [options.colors] - User defended colors for
* severites
* severities
* @param {string} [options.colors.emergencyColor] - A RGB Hex coded color in the form
* of #FFFFFF or as or the ANSI color code number (30-37 Standard &amp; 0-255
* Extended)
@ -781,14 +781,14 @@ class RFC3164 {
});
}
/**
* Building a formated message. Returns a promise with a formated message
* Building a formatted message. Returns a promise with a formatted message
* @public
* @param {string} msg - The Syslog Message
* @param {object} [options] - Options object
* @param {number} [options.severity=7] - An array of structure
* @param {number} [options.colorCode=36] - The ANSI color code to use if
* message coloration is selected
* @returns {Promise} A Syslog formated string acording to the selected RFC
* @returns {Promise} A Syslog formatted string according to the selected RFC
* @throws {Error} A standard error object
*/
buildMessage (msg, options) {
@ -802,7 +802,7 @@ class RFC3164 {
reject(new Error(errMsg));
return;
}
let fmtMsg = ''; // Formated Syslog message string var
let fmtMsg = ''; // Formatted Syslog message string var
const newLine = '\n';
const newLineRegEx = /(\r|\n|(\r\n))/;
const escapeCode = '\u001B';
@ -810,7 +810,7 @@ class RFC3164 {
// The PRI is common to both RFC formats
const pri = (this.facility * 8) + severity;
// Remove any newline character
msg = msg.replace(newLineRegEx, '');
msg = msg.replace(newLineRegEx, '');
// Add requested color
if (this.color) {
options.msgColor = options.msgColor || 36;
@ -822,17 +822,16 @@ class RFC3164 {
colorCode += options.msgColor;
colorCode += 'm'; // ANSI Color Closer
} else {
colorCode = '[39m'; // Use terminal's defualt color
colorCode = '[39m'; // Use terminal's default color
}
msg = escapeCode + colorCode + msg + resetColor;
}
// RegEx to find a leading 0 in the day of a DateTime for RFC3164
// RFC3164 uses BSD timeformat
// RegEx to find a leading 0 in the day of a DateTime for RFC3164 RFC3164 uses BSD timeformat
const rfc3164DateRegEx = /((A|D|F|J|M|N|O|S)(a|c|e|p|o|u)(b|c|g|l|n|p|r|t|v|y)\s)0(\d\s\d\d:\d\d:\d\d)/;
const timestamp = moment()
.format('MMM DD hh:mm:ss')
.replace(rfc3164DateRegEx, '$1 $5');
// Build message
// Build message
fmtMsg = '&lt;' + pri + '>';
fmtMsg += timestamp;
fmtMsg += ' ' + this.hostname;
@ -843,16 +842,16 @@ class RFC3164 {
});
}
/**
* send a RFC5424 formated message. Returns a promise with the formated
* send a RFC5424 formatted message. Returns a promise with the formatted
* message that was sent. If no server connection was defined when the
* class was created a defualt Syslog connector will be used.
* class was created a default Syslog connector will be used.
* @see SyslogPro~Syslog
* @public
* @param {string} msg - The unformated Syslog message to send
* @param {string} msg - The unformatted Syslog message to send
* @param {object} [options] - Options object
* @param {number} [options.severity=7] - An array of structure
* @param {number} [options.colorCode=36] - The ANSI color code to use if
* @returns {Promise} A Syslog formated string acording to the selected RFC
* @returns {Promise} A Syslog formatted string according to the selected RFC
* @throws {Error} A standard error object
*/
send (msg, options) {
@ -876,11 +875,11 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 0 (Emergency)
* Send a syslog message with a security level of 0 (Emergency)
* @public
* @param {string} msg - The emergancy message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @param {string} msg - The emergency message to send to the Syslog server
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
emergency (msg) {
return this.send(msg, {
@ -889,21 +888,21 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 0 (Emergency)
* Send a syslog message with a security level of 0 (Emergency)
* @public
* @param {string} msg - The emergancy message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @param {string} msg - The emergency message to send to the Syslog server
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
emer (msg) {
return this.emergency(msg);
}
/**
* Send a syslog message with a secerity level of 1 (Alert)
* Send a syslog message with a severity level of 1 (Alert)
* @public
* @param {string} msg - The alert message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
alert (msg) {
return this.send(msg, {
@ -912,11 +911,11 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 2 (Critical)
* Send a syslog message with a severity level of 2 (Critical)
* @public
* @param {string} msg - The critical message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
critical (msg) {
return this.send(msg, {
@ -925,21 +924,21 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 2 (Critical)
* Send a syslog message with a severity level of 2 (Critical)
* @public
* @param {string} msg - The critical message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
crit (msg) {
return this.critical(msg);
}
/**
* Send a syslog message with a secerity level of 3 (Error)
* Send a syslog message with a severity level of 3 (Error)
* @public
* @param {string} msg - The error message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
error (msg) {
return this.send(msg, {
@ -948,21 +947,21 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 3 (Error)
* Send a syslog message with a severity level of 3 (Error)
* @public
* @param {string} msg - The error message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
err (msg) {
return this.error(msg);
}
/**
* Send a syslog message with a secerity level of 4 (Warning)
* Send a syslog message with a severity level of 4 (Warning)
* @public
* @param {string} msg - The warning message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
warning (msg) {
return this.send(msg, {
@ -971,21 +970,21 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 4 (Warning)
* Send a syslog message with a severity level of 4 (Warning)
* @public
* @param {string} msg - The warning message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
warn (msg) {
return this.warning(msg);
}
/**
* Send a syslog message with a secerity level of 5 (Notice)
* Send a syslog message with a severity level of 5 (Notice)
* @public
* @param {string} msg - The notice message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
notice (msg) {
return this.send(msg, {
@ -994,21 +993,21 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 5 (Notice)
* Send a syslog message with a severity level of 5 (Notice)
* @public
* @param {string} msg - The notice message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
note (msg) {
return this.notice(msg);
}
/**
* Send a syslog message with a secerity level of 6 (Informational)
* Send a syslog message with a severity level of 6 (Informational)
* @public
* @param {string} msg - The informational message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
informational (msg) {
return this.send(msg, {
@ -1017,31 +1016,31 @@ class RFC3164 {
});
}
/**
* Send a syslog message with a secerity level of 6 (Informational)
* Send a syslog message with a severity level of 6 (Informational)
* @public
* @param {string} msg - The informational message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
info (msg) {
return this.informational(msg);
}
/**
* Send a syslog message with a secerity level of 6 (Informational)
* Send a syslog message with a severity level of 6 (Informational)
* @public
* @param {string} msg - The informational message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
log (msg) {
return this.informational(msg);
}
/**
* Send a syslog message with a secerity level of 7 (Debug)
* Send a syslog message with a severity level of 7 (Debug)
* @public
* @param {string} msg - The debug message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
debug (msg) {
return this.send(msg, {
@ -1052,37 +1051,37 @@ class RFC3164 {
}
/**
* A class to work with RFC5424 formated syslog messages. The meesaging is fully configurabule and Ansi foreground
* colors can be added. Both ANSI 8 and ANSI 256 color are fully suported.
* A class to work with RFC5424 formatted syslog messages. The messaging is fully configurable and ANSI foreground
* colors can be added. Both ANSI 8 and ANSI 256 color are fully supported.
* Most APIs will return a promise. These APIs can be used using
* `then(...)/catch(...)`
*
* A Syslog class with a configured
* Syslog server target can also be used as the input into the formating
* classes so that it may run independtly.
* Syslog server target can also be used as the input into the formatting
* classes so that it may run independently.
*
* The RFC5424 Syslog logging format is ment to be used as a stream of log data
* from a service or applacation. This class is designed to be used in this
* fashion where new messages are writen to the class as needed.
* The RFC5424 Syslog logging format is meant to be used as a stream of log data
* from a service or application. This class is designed to be used in this
* fashion where new messages are written to the class as needed.
* @requires moment
* @version 0.0.0
* @since 0.0.0
*/
class RFC5424 {
/**
* Construct a new RFC5424 formated Syslog object with user options
* Construct a new RFC5424 formatted Syslog object with user options
* @public
* @this RFC5424
* @param {object} [options] - Options object
* @param {string} [options.applacationName='NodeJSLogger'] - Applacation
* @param {string} [options.applacationName='NodeJSLogger'] - Application
* @param {string} [options.hostname=os.hostname] - The name of this server
* @param {boolean} [options.timestamp=false] - Included a Timestamp
* @param {boolean} [options.timestampUTC=false] - RFC tandard is for
* @param {boolean} [options.timestampUTC=false] - RFC standard is for
* local time
* @param {boolean} [options.timestampMS=false] - Timestamp with ms
* resoltuion
* resolution
* @param {boolean} [options.timestampTZ=true] - Should the timestamp
* included timezone
* included time zone
* @param {boolean} [options.encludeStructuredData=false] - Included
* any provided structured data
* @param {boolean} [options.utf8BOM=true] - Included the UTF8
@ -1090,7 +1089,7 @@ class RFC5424 {
* @param {boolean} [options.extendedColor=false] - Included the UTF8
* encoding tag with syslog message text
* @param {object} [options.colors] - User defended colors for
* severites
* severities
* @param {string} [options.colors.emergencyColor] - A RGB Hex coded color in the form
* of #FFFFFF or as or the ANSI color code number (30-37 Standard &amp; 0-255
* Extended)
@ -1382,7 +1381,7 @@ class RFC5424 {
});
}
/**
* Building a formated message. Returns a promise with a formated message
* Building a formatted message. Returns a promise with a formatted message
* @public
* @param {string} msg - The Syslog Message
* @param {object} [options] - Options object
@ -1393,12 +1392,12 @@ class RFC5424 {
* this message
* @param {string[]} [options.structuredData] - An array of structure
* data strings conforming to the IETF/IANA defined SD-IDs or IANA
* registred SMI Network Management Private Enterprise Code SD-ID
* registered SMI Network Management Private Enterprise Code SD-ID
* conforming to the format
* [name@&lt;private enterprise number> parameter=value]
* @param {number} [options.colorCode=36] - The ANSI color code to use if
* message coloration is selected
* @returns {Promise} A Syslog formated string acording to the selected RFC
* @returns {Promise} A Syslog formatted string according to the selected RFC
* @throws {Error} A standard error object
*/
buildMessage (msg, options) {
@ -1424,7 +1423,7 @@ class RFC5424 {
// The PRI is common to both RFC formats
const pri = (facility * 8) + severity;
// Remove any newline character
msg = msg.replace(newLineRegEx, '');
msg = msg.replace(newLineRegEx, '');
// Add requested color
if (this.color) {
options.msgColor = options.msgColor || 36;
@ -1436,7 +1435,7 @@ class RFC5424 {
colorCode += options.msgColor;
colorCode += 'm'; // ANSI Color Closer
} else {
colorCode = '[39m'; // Use terminal's defualt color
colorCode = '[39m'; // Use terminal's default color
}
msg = escapeCode + colorCode + msg + resetColor;
}
@ -1483,7 +1482,7 @@ class RFC5424 {
timeQuality += ']';
msgStructuredData.push(timeQuality);
}
// Build Structured Data string
//Build Structured Data string
let structuredData = '-';
const sdElementCount = msgStructuredData.length;
if (this.encludeStructuredData &amp;&amp; sdElementCount > 0) {
@ -1523,13 +1522,13 @@ class RFC5424 {
});
}
/**
* send a RFC5424 formated message. Returns a promise with the formated
* send a RFC5424 formatted message. Returns a promise with the formatted
* message that was sent. If no server connection was defined when the
* class was created a defualt Syslog connector will be used.
* class was created a default Syslog connector will be used.
* @see SyslogPro~Syslog
* @public
* @param {string} msg - The unformated Syslog message to send
* @returns {Promise} A Syslog formated string acording to the selected RFC
* @param {string} msg - The unformatted Syslog message to send
* @returns {Promise} A Syslog formatted string according to the selected RFC
* @throws {Error} A standard error object
*/
send (msg, options) {
@ -1553,11 +1552,11 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 0 (Emergency)
* Send a syslog message with a severity level of 0 (Emergency)
* @public
* @param {string} msg - The emergancy message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @param {string} msg - The emergency message to send to the Syslog server
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
emergency (msg) {
return this.send(msg, {
@ -1566,21 +1565,21 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 0 (Emergency)
* Send a syslog message with a severity level of 0 (Emergency)
* @public
* @param {string} msg - The emergancy message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @param {string} msg - The emergency message to send to the Syslog server
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
emer (msg) {
return this.emergency(msg);
}
/**
* Send a syslog message with a secerity level of 1 (Alert)
* Send a syslog message with a severity level of 1 (Alert)
* @public
* @param {string} msg - The alert message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
alert (msg) {
return this.send(msg, {
@ -1589,11 +1588,11 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 2 (Critical)
* Send a syslog message with a severity level of 2 (Critical)
* @public
* @param {string} msg - The critical message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
critical (msg) {
return this.send(msg, {
@ -1602,21 +1601,21 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 2 (Critical)
* Send a syslog message with a severity level of 2 (Critical)
* @public
* @param {string} msg - The critical message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
crit (msg) {
return this.critical(msg);
}
/**
* Send a syslog message with a secerity level of 3 (Error)
* Send a syslog message with a severity level of 3 (Error)
* @public
* @param {string} msg - The error message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
error (msg) {
return this.send(msg, {
@ -1625,21 +1624,21 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 3 (Error)
* Send a syslog message with a severity level of 3 (Error)
* @public
* @param {string} msg - The error message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
err (msg) {
return this.error(msg);
}
/**
* Send a syslog message with a secerity level of 4 (Warning)
* Send a syslog message with a severity level of 4 (Warning)
* @public
* @param {string} msg - The warning message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
warning (msg) {
return this.send(msg, {
@ -1648,21 +1647,21 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 4 (Warning)
* Send a syslog message with a severity level of 4 (Warning)
* @public
* @param {string} msg - The warning message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
warn (msg) {
return this.warning(msg);
}
/**
* Send a syslog message with a secerity level of 5 (Notice)
* Send a syslog message with a severity level of 5 (Notice)
* @public
* @param {string} msg - The notice message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
notice (msg) {
return this.send(msg, {
@ -1671,21 +1670,21 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 5 (Notice)
* Send a syslog message with a severity level of 5 (Notice)
* @public
* @param {string} msg - The notice message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
note (msg) {
return this.notice(msg);
}
/**
* Send a syslog message with a secerity level of 6 (Informational)
* Send a syslog message with a severity level of 6 (Informational)
* @public
* @param {string} msg - The informational message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
informational (msg) {
return this.send(msg, {
@ -1694,31 +1693,31 @@ class RFC5424 {
});
}
/**
* Send a syslog message with a secerity level of 6 (Informational)
* Send a syslog message with a severity level of 6 (Informational)
* @public
* @param {string} msg - The informational message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
info (msg) {
return this.informational(msg);
}
/**
* Send a syslog message with a secerity level of 6 (Informational)
* Send a syslog message with a severity level of 6 (Informational)
* @public
* @param {string} msg - The informational message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
log (msg) {
return this.informational(msg);
}
/**
* Send a syslog message with a secerity level of 7 (Debug)
* Send a syslog message with a severity level of 7 (Debug)
* @public
* @param {string} msg - The debug message to send to the Syslog server
* @returns {Promise} - The formated syslog message sent to the Syslog server
* @throws {Error} - Any bubbled up error
* @returns {Promise} - The formatted syslog message sent to the Syslog server
* @throws {Error} - Any bubbled-up error
*/
debug (msg) {
return this.send(msg, {
@ -1732,34 +1731,34 @@ class RFC5424 {
* A class to work with IBM LEEF (Log Event Extended Format) messages this form
* of system messages are designed to work with security systems. Messages can
* be saved to file (Saving to file if not part of this module but a LEEF
* formated mesage produced by this module can be saved externaly to it) or
* formatted message produced by this module can be saved externally to it) or
* sent via Syslog.
* Most APIs will return a promise. These APIs can be used using
* `then(...)/catch(...)`
*
* A Syslog class with a configured Syslog server target can also be used as
* the input into the formating classes so that it may run independtly. The
* the input into the formatting classes so that it may run independently. The
* LEEF format is designed to send event data to a SIEM system and should not
* be as a logging stream. This class is ment to be used once per message.
* be as a logging stream. This class is meant to be used once per message.
* @requires moment
* @version 0.0.0
* @since 0.0.0
*/
class LEEF {
/**
* Construct a new LEEF formating object with user options
* Construct a new LEEF formatting object with user options
* @public
* @param {object} [options] - Options object
* @param {string} [options.vendor='unknown'] - The vendor of the system that
* genrated the event being reported
* generated the event being reported
* @param {string} [options.product='unknown'] - The product name of the
* system that genrated the event being reported
* @param {string} [options.version='unknown'] - The version name of the
* system that genrated the event being reported
* @param {string} [options.eventId='unknown'] - The eventId of the
* system that genrated the event being reported
* @param {object} [options.attrabute] - LEEF message attrabutes which
* defualts to all base attrabutes with null values, new attrabutes should
* @param {object} [options.attributes] - LEEF message attributes which
* defaults to all base attributes with null values, new attributes should
* be added as new elements to this object
* @param {boolean} [options.syslogHeader='true'] - Should the LEEF message
* include a Syslog header with Timestamp and source
@ -1783,7 +1782,7 @@ class LEEF {
this.syslogHeader = typeof options.syslogHeader === 'boolean'
? options.syslogHeader : true;
/** @type {object} */
this.attrabutes = options.attrabutes || {
this.attributes = options.attributes || {
cat: null,
devTime: null,
devTimeFormat: null,
@ -1841,9 +1840,9 @@ class LEEF {
}
}
/**
*Build a formated message
*Build a formatted message
* @public
* @return {Promise} - string with formated message
* @return {Promise} - string with formatted message
*/
buildMessage () {
return new Promise((resolve, reject) => {
@ -1854,9 +1853,9 @@ class LEEF {
fmtMsg += '|' + this.eventId;
fmtMsg += '|';
// Build LEEF Attrabuites
// Build LEEF Attributes
const Tab = '\x09';
const leefAttribs = Object.entries(this.attrabutes);
const leefAttribs = Object.entries(this.attributes);
const leefAttribsLen = leefAttribs.length;
for (let attrib = 0; attrib &lt; leefAttribsLen; attrib++) {
if (leefAttribs[attrib][1] !== null) {
@ -1896,36 +1895,36 @@ class LEEF {
* A class to work with HP CEF (Common Event Format) messages. This form
* of system messages are designed to work with security systems. Messages can
* be saved to file (Saving to file if not part of this module but a CEF
* formated mesage produced by this module can be saved externaly to it) or
* formatted message produced by this module can be saved externally to it) or
* sent via Syslog.
* Most APIs will return a promise. These APIs can be used using
* `then(...)/catch(...)`
*
* A Syslog class with a configured Syslog server target can also be used as
* the input into the formating classes so that it may run independtly. The CEF
* the input into the formatting classes so that it may run independently. The CEF
* format is designed to send event data to a SIEM system and should not be as
* a logging stream. This class is ment to be used once per message.
* a logging stream. This class is meant to be used once per message.
* @requires moment
* @version 0.0.0
* @since 0.0.0
*/
class CEF {
/**
* Construct a new CEF formating object with user options
* Construct a new CEF formatting object with user options
* @public
* @param {object} [options] - Options object
* @param {string} [options.deviceVendor='unknown'] - The vendor of the system
* that genrated the event being reported
* that generated the event being reported
* @param {string} [options.deviceProduct='unknown'] - The product name of the
* system that genrated the event being reported
* @param {string} [options.deviceVersion='unknown'] - The version name of the
* system that genrated the event being reported
* @param {string} [options.deviceEventClassId='unknown'] - The eventId of the
* system that genrated the event being reported
* @param {string} [options.name='unknown'] - Name of the service genrating
* @param {string} [options.name='unknown'] - Name of the service generating
* the notice
* @param {string} [options.severity='unknown'] - Severity of the notification
* @param {string} [options.extensions={}] - Any CEF Key=Value extentions
* @param {string} [options.extensions={}] - Any CEF Key=Value extensions
* @param {Syslog} [options.server=false] - A {@link module:SyslogPro~Syslog|
* Syslog server connection} that should be used to send messages directly
* from this class. @see SyslogPro~Syslog
@ -2118,8 +2117,8 @@ class CEF {
/**
* Validate this CEF object
* @public
* @return {Promise} - True if valadated
* @throws {Error} - First element to fail valadation
* @return {Promise} - True if validated
* @throws {Error} - First element to fail validation
*/
validate () {
return new Promise ((resolve, reject) => {
@ -2402,7 +2401,9 @@ module.exports = {
LEEF: LEEF,
CEF: CEF,
Syslog: Syslog
};</code></pre>
};
</code></pre>
</article>
</section>
@ -2416,7 +2417,7 @@ module.exports = {
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Sep 25 2018 18:22:00 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Sep 25 2018 19:11:53 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>