Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: AlexRRR/node-nsca
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nedeco/node-nsca
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 19 commits
  • 9 files changed
  • 1 contributor

Commits on Feb 17, 2015

  1. Copy the full SHA
    8dbf0b5 View commit details
  2. add package.json

    ned-jm committed Feb 17, 2015
    Copy the full SHA
    b6fdee7 View commit details

Commits on Feb 23, 2015

  1. Copy the full SHA
    17e9d78 View commit details
  2. add 3DES support

    probably not working, needs tesing!
    ned-jm committed Feb 23, 2015
    Copy the full SHA
    4e1330f View commit details

Commits on Feb 24, 2015

  1. enable debug logs

    ned-jm committed Feb 24, 2015
    Copy the full SHA
    a55b9e2 View commit details
  2. Copy the full SHA
    bc6886d View commit details
  3. Copy the full SHA
    b1dcfaa View commit details
  4. restructure package

    ned-jm committed Feb 24, 2015
    Copy the full SHA
    d6978eb View commit details

Commits on Feb 26, 2015

  1. remove debug log

    ned-jm committed Feb 26, 2015
    Copy the full SHA
    b0e0594 View commit details

Commits on Feb 27, 2015

  1. Copy the full SHA
    606ecf8 View commit details

Commits on Mar 2, 2015

  1. enable encryption modes, readd mcrypt dependency, remove custom des3 …

    …encryption and node-forge dependency
    ned-jm committed Mar 2, 2015
    Copy the full SHA
    1995159 View commit details

Commits on Sep 15, 2015

  1. update mcrypt dependencies

    ned-jm committed Sep 15, 2015
    Copy the full SHA
    b861dfe View commit details
  2. Copy the full SHA
    13fc42e View commit details

Commits on Sep 21, 2015

  1. remove mcrypt dependency

    it does not (yet) build on node 4.x.x
    removing mcrypt means we can no longer use encryption
    ned-jm committed Sep 21, 2015
    Copy the full SHA
    e73f309 View commit details

Commits on Nov 2, 2016

  1. Revert "remove mcrypt dependency"

    This reverts commit 638aa89.
    ned-jm committed Nov 2, 2016
    Copy the full SHA
    9b4a32a View commit details
  2. cleanup

    ned-jm committed Nov 2, 2016
    Copy the full SHA
    7455740 View commit details
  3. bump mcrypt version

    ned-jm committed Nov 2, 2016
    Copy the full SHA
    5daa768 View commit details

Commits on Nov 3, 2016

  1. don't mix quote styles

    ned-jm committed Nov 3, 2016
    Copy the full SHA
    9b9ac9d View commit details

Commits on Nov 7, 2016

  1. fix iv size

    using buf.toString(enc, start, end) isn't reliable because the resulting string (utf-8)
    has varying byte lengths, depending on the bytes/characters to be encoded as a string
    ned-jm committed Nov 7, 2016
    Copy the full SHA
    4ad139d View commit details
Showing with 313 additions and 201 deletions.
  1. +2 −24 .gitignore
  2. +49 −8 README.md
  3. +0 −23 crypto.js
  4. +0 −77 index.js
  5. +53 −0 lib/crypto.js
  6. +69 −0 lib/xor.js
  7. +116 −0 nsca.js
  8. +24 −0 package.json
  9. +0 −69 xor.js
26 changes: 2 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
node_modules
.DS_Store
57 changes: 49 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
node-nsca
=========
# node-nsca

A node module for sending nagios nsca checks

currently supports clear text only and XOR modes only.
Encryption coming soon!

````javascript
var n = new Notifier(HOST, PORT, SECRET, ENCRYPTION);
n.send("localhost", "centos check",0,"Looks Good!");
````JavaScript
var nsca = require("nsca");
var noti = new nsca.Notifier(HOST, PORT, PASSWORD, ENCRYPTION_MODE);
noti.send("localhost", "centos check", nsca.OK, "Looks Good!");
````

# Encryption modes

You can use the integer defined in your `nsca.cfg`,
or use one of these keywords:

```JavaScript
nsca.ENCRYPT_NONE
nsca.ENCRYPT_XOR
nsca.ENCRYPT_DES
nsca.ENCRYPT_3DES
nsca.ENCRYPT_CAST128
nsca.ENCRYPT_CAST256
nsca.ENCRYPT_XTEA
nsca.ENCRYPT_3WAY // NOT AVAILABLE
nsca.ENCRYPT_BLOWFISH
nsca.ENCRYPT_TWOFISH
nsca.ENCRYPT_LOKI97
nsca.ENCRYPT_RC2
nsca.ENCRYPT_ARCFOUR
nsca.ENCRYPT_RC6
nsca.ENCRYPT_RIJNDAEL128
nsca.ENCRYPT_RIJNDAEL192
nsca.ENCRYPT_RIJNDAEL256
nsca.ENCRYPT_MARS // NOT AVAILABLE
nsca.ENCRYPT_PANAMA
nsca.ENCRYPT_WAKE
nsca.ENCRYPT_SERPENT
nsca.ENCRYPT_IDEA
nsca.ENCRYPT_ENIGMA
nsca.ENCRYPT_GOST
nsca.ENCRYPT_SAFER64 // NOT AVAILABLE
nsca.ENCRYPT_SAFER128 // NOT AVAILABLE
nsca.ENCRYPT_SAFERPLUS
```

# NSCA status

```JavaScript
nsca.OK
nsca.WARN
nsca.FAIL
nsca.UNKNOWN
```
23 changes: 0 additions & 23 deletions crypto.js

This file was deleted.

77 changes: 0 additions & 77 deletions index.js

This file was deleted.

53 changes: 53 additions & 0 deletions lib/crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var MCrypt = require("mcrypt").MCrypt;
var XorEncoder = require("./xor");

var ciphers = [
"des",
"tripledes",
"cast-128",
"cast-256",
"xtea",
/*3-WAY*/ undefined,
"blowfish",
"twofish",
"loki97",
"rc2",
"arcfour",
"rijndael-128",
"rijndael-192",
"rijndael-256",
/*MARS*/ undefined,
/*PANAMA*/ undefined,
"wake",
"serpent",
/*IDEA*/ undefined,
"enigma",
"gost",
/*SAFER-sk64*/ undefined,
/*SAFER-sk128*/ undefined,
"saferplus",
];

function Crypter(enc, key, iv) {
this.key = key;
this.iv = iv;
if (enc === 1) {
this.encryption = new XorEncoder();
} else {
var cipher = ciphers[enc - 2];
if (cipher) {
this.encryption = new MCrypt(cipher, "cfb");
} else {
throw new Error("unsupported encryption mode: " + enc + "!");
}
}
}

Crypter.prototype.encode = function(msg) {
this.encryption.validateKeySize(false);
this.encryption.open(this.key, this.iv);
return this.encryption.encrypt(msg);
};


module.exports = Crypter;
69 changes: 69 additions & 0 deletions lib/xor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function XorEncoder() {
this.key = "";
this.iv = "";
}

XorEncoder.prototype.validateKeySize = function() {

};

XorEncoder.prototype.open = function(key, iv) {
this.key = key;
this.iv = iv;
};


XorEncoder.prototype.encrypt = function(buffer) {
var encoding = "binary";
var value = buffer.toString(encoding);
String.prototype.repeat = function(n) {
var str = "";
for (var i = 0; i < n; i++) {
str += this;
}
return str;
};

function repeatString(toExtend, base) {
var timesToRepeat = Math.ceil(base.length / toExtend.length);
return toExtend.repeat(timesToRepeat);
}


function charArray(value) {
var map = Array.prototype.map;
var chars = map.call(value, function(x) {
return x.charCodeAt(0);
});
return chars;
}

function joinCharCodes(a) {
// var finalstring = "";
// a.map(function(x){
// finalstring = finalstring + String.fromCharCode(x);
// })
var b = new Buffer(a, encoding);
return b;
}

function xorArrays(a, b) {
var result = [];
for (var i = 0; i < a.length; i++) {
result[i] = a[i] ^ b[i];
}
return result;
}

var valueChars = charArray(value);
var repeatedPassChars = charArray(repeatString(this.key, value));
var repeatedIVChars = charArray(repeatString(this.iv, value));

var pre = xorArrays(valueChars, repeatedIVChars);
var post = xorArrays(pre, repeatedPassChars);

return joinCharCodes(post);
};


module.exports = XorEncoder;
116 changes: 116 additions & 0 deletions nsca.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
var net = require("net");
var crc32 = require("buffer-crc32");
var Crypter = require("./lib/crypto");


function Notifier(host, port, secret, encryption) {
this.host = host;
this.port = port;
this.secret = secret;
this.encryption = encryption;
}


Notifier.prototype.send = function(hostName, serviceDesc, statusCode, pluginOutput, callback) {
var PACKET_VERSION = 3;
var MSG_LENGTH = 720;


var client = new net.Socket();

client.connect(this.port, this.host, function() {
// console.log("Connected to: " + this.host + ":" + this.port);
}.bind(this));

client.on("data", function(data) {
// console.log("data received: " + data);
var encoding = "binary";
var inBuffer = new Buffer(data);
var iv = inBuffer.slice(0, 8);
// console.log("received IV: " + iv);
var timestamp = inBuffer.readInt32BE(128);
// console.log("received timestamp: " + timestamp);

var outBuffer = new Buffer(MSG_LENGTH);
// empty Buffer
outBuffer.fill(0);
// NSCA version
outBuffer.writeInt16BE(PACKET_VERSION, 0);
// padding
outBuffer.fill("h", 2, 3);
// CRC32 null
outBuffer.writeUInt32BE(0, 4);
// timestamp
outBuffer.writeUInt32BE(timestamp, 8);
// status code
outBuffer.writeInt16BE(statusCode, 12);
// host name
outBuffer.write(hostName, 14, 77, encoding);
// service
outBuffer.write(serviceDesc, 78, 206, encoding);
// our message
outBuffer.write(pluginOutput, 206, 720, encoding);
// CEC32
outBuffer.writeUInt32BE(crc32.unsigned(outBuffer), 4);

if (this.encryption) {
var encrypter = new Crypter(this.encryption, this.secret, iv);
outBuffer = encrypter.encode(outBuffer);
}

client.write(outBuffer, function(a) {
client.destroy();
// console.log("data sent: " + outBuffer);
});
}.bind(this));

client.on("close", function() {
// no errors, lets go!
callback(null);
}.bind(this));

client.on("error", function(e) {
var err = new Error("NSCA server connection failed!");
callback(err);
}.bind(this));
};


module.exports = {
Notifier: Notifier,

// NSCA status
OK: 0,
WARN: 1,
FAIL: 2,
UNKNOWN: 3,

// encryption types
ENCRYPT_NONE : 0, // no encryption
ENCRYPT_XOR : 1, // not really encrypted, just obfuscated
ENCRYPT_DES : 2, // DES
ENCRYPT_3DES : 3, // 3DES or Triple DES
ENCRYPT_CAST128 : 4, // CAST-128
ENCRYPT_CAST256 : 5, // CAST-256
ENCRYPT_XTEA : 6, // xTEA
ENCRYPT_3WAY : 7, // 3-WAY
ENCRYPT_BLOWFISH : 8, // SKIPJACK
ENCRYPT_TWOFISH : 9, // TWOFISH
ENCRYPT_LOKI97 : 10, // LOKI97
ENCRYPT_RC2 : 11, // RC2
ENCRYPT_ARCFOUR : 12, // RC4
ENCRYPT_RC6 : 13, // RC6 (UNUSED)
ENCRYPT_RIJNDAEL128: 14, // RIJNDAEL-128
ENCRYPT_RIJNDAEL192: 15, // RIJNDAEL-192
ENCRYPT_RIJNDAEL256: 16, // RIJNDAEL-256
ENCRYPT_MARS : 17, // MARS (UNUSED)
ENCRYPT_PANAMA : 18, // PANAMA (UNUSED)
ENCRYPT_WAKE : 19, // WAKE
ENCRYPT_SERPENT : 20, // SERPENT
ENCRYPT_IDEA : 21, // IDEA (UNUSED)
ENCRYPT_ENIGMA : 22, // ENIGMA (Unix crypt)
ENCRYPT_GOST : 23, // GOST
ENCRYPT_SAFER64 : 24, // SAFER-sk64
ENCRYPT_SAFER128 : 25, // SAFER-sk128
ENCRYPT_SAFERPLUS : 26, // SAFER+
};
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "nsca",
"version": "0.0.1",
"description": "A node module for sending nagios nsca checks",
"main": "nsca.js",
"scripts": {
"start": "node nsca.js"
},
"repository": {
"type": "git",
"url": "https://github.com/nedeco/node-nsca.git"
},
"author": "AlexRRR",
"contributors": [{"name": "jomo"}],
"license": "MIT",
"bugs": {
"url": "https://github.com/nedeco/node-nsca/issues"
},
"homepage": "https://github.com/nedeco/node-nsca",
"dependencies": {
"buffer-crc32": "0.2.5",
"mcrypt": "0.1.11"
}
}
69 changes: 0 additions & 69 deletions xor.js

This file was deleted.