Updated Jest Tests, Docs, and package.json

This commit is contained in:
Craig Yamato 2018-09-24 05:17:44 +00:00
parent 12b5a73d2a
commit f28a121da8
7 changed files with 7501 additions and 1612 deletions

76
.gitignore vendored Normal file
View File

@ -0,0 +1,76 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
# Test files
run.js

File diff suppressed because it is too large Load Diff

5684
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "SyslogPro",
"version": "0.0.0",
"version": "0.1.0",
"description": "A Syslog client which options for UDP, TCP, and TLS transport and suport for both RFC-3164 and RFC-5424 including Structured Data.",
"repository": "",
"author": {
@ -16,6 +16,10 @@
}
],
"license": "MIT",
"main": "index.js",
"engines": {
"node": ">=10.0.0"
},
"dependencies": {
"moment": "^2.22.2"
},
@ -27,14 +31,15 @@
},
"scripts": {
"test": "jest --colors --expand --logHeapUsage --runInBand",
"doc": "jsdoc *.js --destination ./docs/jsdoc --private --readme ./README.md --template ../../../node_modules/docdash"
"doc": "jsdoc *.js --destination ./docs/jsdoc --private --readme ./readme.md --template ./node_modules/docdash"
},
"jest": {
"collectCoverage": true,
"coverageDirectory": "coverage",
"coverageDirectory": "docs/coverage",
"coverageReporters": [
"json",
"text",
"text-summary",
"lcov"
],
"globals": {

46
readme.md Normal file
View File

@ -0,0 +1,46 @@
SyslogPro
=========
A pure Javascript Syslog module with support for RFC3164, RFC5424, IBM LEEF (Log Event Extended
Format), and HP CEF (Common Event Format) formatted messages. SyslogPro has
transport options of UDP, TCP, and TLS. TLS includes support for Server and
Client certificate authrization. For unformatedm and RFC messages there is
support for Basic and Extended ANSI coloring. RFC5424 Strucutred Data is also
encluded in the module. All 28 standard CEF Extentions are included in the
defualt CEF class. All 45 standard LEEF Atrabutes are included in the defualt
LEEF class. It is the goal of this project is for every relase to offer full
code covrage unit testing and documentation.
## Installation
`npm install SyslogPro`
## Usage
let SyslogPro = require('syslogpro');
let rfc3164Options = {
}
let rfc5424Options = {
}
let leefOptions = {
}
let cefOptions = {
}
let syslogOptions = {
}
let syslog = new SyslogPro.Syslog();
## Tests
`npm test`
## Contributing
Please try to stay close to the Google JS Style Guid, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

View File

@ -1,126 +0,0 @@
send (msg) {
return new Promise((resolve, reject) => {
if (typeof msg !== 'string') {
reject(new Error("TYPE ERROR: Syslog message must be a string"));
return;
}
// Test for target DNS and Address Family (IPv4/6) by looking up the DNS
const dnsOptions = {
verbatim: true
};
dnsPromises.lookup(this.target, dnsOptions)
.then((result) => {
// Turn msg in to a UTF8 buffer
const msgBuffer = Buffer.from(msg, 'utf8');
if (this.protocol === 'udp') {
// Do UDP transport
const dgram = require('dgram');
const udpType = result.family === 4 ? 'udp4' : 'udp6';
const udpClient = dgram.createSocket(udpType);
udpClient.send(msgBuffer, this.port, result.address, (error) => {
udpClient.close();
resolve(msg);
});
} else if (this.protocol === 'tcp') {
// Use TCP client
const net = require('net');
const tcpOptions = {
host: result.address,
port: this.port,
family: result.family
};
const client = net.createConnection(tcpOptions, () => {
client.write(msgBuffer, () => {
client.end();
});
});
client.setTimeout(this.tcpTimeout);
// client.on('data', (data) => {});
client.on('end', () => {
resolve(msg);
});
client.on('timeout', () => {
client.end();
reject(new Error('TIMEOUT ERROR: Syslog server TCP timeout'));
});
client.on('error', (error) => {
client.destroy();
reject(error);
});
} else if (this.protocol === 'tls') {
// Use a TLS client
const tls = require('tls');
const tlsOptions = {
host: this.target,
port: this.port,
family: result.family
};
if (typeof this.tlsClientKey === 'string'
&& typeof this.tlsClientCert === 'string') {
tlsOptions.key = fs.readFileSync(this.tlsClientKey);
tlsOptions.cert = fs.readFileSync(this.tlsClientCert);
} else if (typeof this.tlsClientKey !== 'string'
&& typeof this.tlsClientKey !== 'undefined') {
let errMsg = 'TYPE ERROR: TLS Client Key is not a file';
errMsg += 'location string';
reject(new Error(errMsg));
return;
} else if (typeof this.tlsClientCert !== 'string'
&& typeof this.tlsClientCert !== 'undefined') {
let errMsg = 'TYPE ERROR: TLS Client Cert is not a file';
errMsg += 'location string';
reject(new Error(errMsg));
return;
}
let tlsCerts = this.tlsServerCerts.length;
if (tlsCerts > 0) {
let tlsOptionsCerts = [];
for (let certIndex=0; certIndex<tlsCerts; certIndex++) {
if (typeof this.tlsServerCerts[certIndex] !== 'string') {
let errMsg = 'TYPE ERROR: TLS Server Cert is not a file';
errMsg += 'location string';
reject(new Error(errMsg));
}
let cert = fs.readFileSync(this.tlsServerCerts[certIndex]);
tlsOptionsCerts.push(cert);
}
tlsOptions.ca = tlsOptionsCerts;
tlsOptions.rejectUnauthorized = true;
}
const client = tls.connect(tlsOptions, () => {
client.write(msgBuffer, () => {
client.end();
});
});
client.setTimeout(this.tcpTimeout);
// client.on('data', (data) => {});
client.on('end', () => {
resolve(msg);
});
client.on('timeout', () => {
client.end();
reject(new Error('TIMEOUT ERROR: Syslog server TLS timeout'));
});
client.on('error', (error) => {
client.destroy();
reject(error);
});
} else {
reject(new Error('FORMAT ERROR: Protocol is not UDP|TCP|TLS'));
}
})
.catch((error) => {
reject(error); // Reject out of the sendMessage function promise
});
});
}
}

File diff suppressed because it is too large Load Diff