Skip to content

Instantly share code, notes, and snippets.

@matzoe
Last active August 29, 2015 14:00
Show Gist options
  • Save matzoe/11397138 to your computer and use it in GitHub Desktop.
Save matzoe/11397138 to your computer and use it in GitHub Desktop.
keepAlive: heartbeat
(function(){
var http = require('http');
var hostUri = "http://XXX/gw/1.0/heartbeat";
var interval = 5000;
var postData = {
"gw_key": "192.168.2.2",
"heart-beat": {
"type": "xxx",
"totalclients": "12",
"version":"4,1,1,0"
}
};
var opt = {
host: 'XXX',
port: '80',
path: '/gw/1.0/heartbeat',
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
var heartbeat_fail_counter = 0;
function post(data) {
opt.headers['Content-Length'] = data.length;
var req = http.request(opt, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
req.setTimeout(1000, function () {
heartbeat_fail_counter++;
console.log('WARNING: heartbeat timeout #', heartbeat_fail_counter);
});
req.end(data);
}
exports = module.exports = function () {
return setInterval(function () {
post(JSON.stringify(postData));
}, interval);
};
}());
// configure - http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_augeas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment