-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some code for checks we want to run on SG
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |