Skip to content

Commit

Permalink
some code for checks we want to run on SG
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Apr 17, 2016
1 parent 99eb7fb commit bfaab16
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gateway/check-ip-address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

// Get IP address
function get_ip_addresses () {
var os = require('os');
var ifaces = os.networkInterfaces();

var out = [];

for (var ifname in ifaces) {
if (ifname != lo) {
out.push(ifaces[ifname].address);
}
}
return out.join('|');
}

var addresses = get_ip_addresses();

console.log(addresses);
process.exit(0);
1 change: 1 addition & 0 deletions gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/lab11/gateway-tools#readme",
"dependencies": {
"getmac": "^1.0.7",
"mqtt-discover": "^0.1.1"
}
}
37 changes: 37 additions & 0 deletions gateway/sensu-configure-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env node

var getmac = require('getmac');
var exec = require('child_process').exec;
var fs = require('fs');

var CONFIG_FILENAME = '/etc/sensu/conf.d/client.json';

var output = JSON.parse(fs.readFileSync(CONFIG_FILENAME));

// Get IP address
function get_first_ip_address () {
var os = require('os');
var ifaces = os.networkInterfaces();

for (var ifname in ifaces) {
if (ifname != lo) {
return ifaces[ifname].address;
}
}
return '';
}

if ('client' in output) {
getmac.getMac(function (err, addr) {
var name = 'swarm-gateway-' + addr;

output['client']['name'] = name;
output['client']['address'] = get_first_ip_address();

fs.writeFileSync(CONFIG_FILENAME, JSON.stringify(output));

exec(RESTART_SENSU_CMD, function (err, stdout, stderr) {
process.exit(0);
});
});
}
11 changes: 11 additions & 0 deletions sensu-server-config/swarm-gateway-ip-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"checks": {
"gateway-check-ipaddress": {
"command": "/home/debian/gateway-tools/gateway/check-ip-address.js",
"subscribers": [
"swarm-gateway"
],
"interval": 300
}
}
}

0 comments on commit bfaab16

Please sign in to comment.