Permalink
Browse files

Fixing IP bug

  • Loading branch information...
1 parent 24ad14c commit 8e712d93f41a638c8820185f64a9f945aa546c7a @MainframeEnzo MainframeEnzo committed Jan 3, 2012
Showing with 67 additions and 37 deletions.
  1. +8 −5 modules/dao.js
  2. +5 −8 run/client.js
  3. +54 −24 submodules/utilities.js
View
@@ -3,7 +3,6 @@ var fs = require('fs'),
Module = {},
location = 'dao.js';
-/* Path to dependencies from file */
var modules = {
cloudwatch: 'node-cloudwatch'
};
@@ -15,7 +14,12 @@ DaoManagerModule = function (constants, utilities, logger, dao) {
Module.logger = logger;
Module.dao = dao;
- /* Setup dependencies */
+ Module.utilities.getInternalIP(function (ip) {
+ Module.logger.write(Module.constants.levels.INFO, 'IP: ' + ip);
+ process.env[Module.constants.strings.IP] = ip;
+ });
+
+ /* Setup dependencies */
for (var name in modules) {
eval('var ' + name + ' = require(\'' + modules[name] + '\')');
}
@@ -37,8 +41,7 @@ DaoManagerModule.prototype.write = function (pluginName, jsonString) {
return false;
};
-DaoManagerModule.prototype.postCloudwatch = function (metricName, unit, value) {
- /* If we're in debug mode, don't post */
+DaoManagerModule.prototype.postCloudwatch = function (metricName, unit, value) { /* If we're in debug mode, don't post */
if (this.debugMode()) return;
/* If we're not on EC2, don't post */
@@ -64,7 +67,7 @@ DaoManagerModule.prototype.postCloudwatch = function (metricName, unit, value) {
if (Module.constants.globals[Module.constants.strings.CLOUDWATCH_ENABLED] == Module.constants.strings.TRUE) {
try {
Module.cloudwatchApi.request('PutMetricData', params, function (response) {
- Module.logger.write(Module.constants.levels.INFO, 'CloudWatch response: ' + response.toString());
+ Module.logger.write(Module.constants.levels.INFO, 'CloudWatch response: ' + response.toString());
});
} catch (Exception) {
Module.logger.write(Module.constants.levels.SEVERE, 'Error POSTing data to CloudWatch: ' + Exception);
View
@@ -37,11 +37,15 @@ function NodeMonitor() {
var utilities = new utilitiesModule.UtilitiesManagerModule(constants);
var logger = new loggerModule.LoggingManagerModule(constants, utilities);
var credentials = new credentialsModule.CredentialManagerModule(constants, utilities, logger);
-
+ var dao = new daoModule.DaoManagerModule(constants, utilities, logger);
+ var plugins = new pluginsModule.PluginsManagerModule(constants, utilities, logger, dao);
+
this.constants = constants;
this.utilities = utilities;
this.logger = logger;
this.credentials = credentials;
+ this.dao = dao;
+ this.plugins = plugins;
/* Use object to store config options */
constants.globals = {};
@@ -53,11 +57,6 @@ function NodeMonitor() {
utilities.parseCommandLineOptions(function () {
/* Auto-populate object based on EC2, if true, use EC2-metadata script */
utilities.autoPopulate(function () {
- /* Set default IP */
- constants.globals[constants.strings.IP] = constants.globals[constants.strings.LOCAL_IPV4];
- process.env[constants.strings.IP] = constants.globals[constants.strings.LOCAL_IPV4];
- logger.write(constants.levels.INFO, 'IP: ' + process.env[constants.strings.IP]);
-
/* Validate credentials */
credentials.check();
});
@@ -76,7 +75,5 @@ nodeMonitor.init(function () {
}
console.log('Running on platform: ' + process.platform.toString());
*/
- var dao = new daoModule.DaoManagerModule(constants, utilities, logger);
- var plugins = new pluginsModule.PluginsManagerModule(nodeMonitor.constants, nodeMonitor.utilities, nodeMonitor.logger, nodeMonitor.dao);
nodeMonitor.plugins.start();
});
@@ -11,8 +11,7 @@ UtilitiesManagerModule.prototype.parseCommandLineOptions = function (callback) {
var count = 0;
process.argv.forEach(function (value, index, array) {
if (count != 0 && count != 1) {
- Module.constants.globals[value.split('=')[0]] = value.split('=')[1];
- /* Debug */
+ Module.constants.globals[value.split('=')[0]] = value.split('=')[1]; /* Debug */
/* console.log('Read cmd parameter: ' + value.split('=')[0] + ', with value: ' + value.split('=')[1]); */
}
count++;
@@ -31,38 +30,69 @@ UtilitiesManagerModule.prototype.parseConfig = function (configFile, callback) {
for (var i = 0; i < splitBuffer.length; i++) {
var params = splitBuffer[i].split('=');
if (params[0] != undefined && params[0] != '') {
- Module.constants.globals[params[0]] = params[1];
- /* Debug */
+ Module.constants.globals[params[0]] = params[1]; /* Debug */
/* console.log('Read config parameter: ' + params[0] + ', with value: ' + params[1]); */
}
}
callback(Module.constants.globals);
});
};
-UtilitiesManagerModule.prototype.autoPopulate = function (callback) {
- if (Module.constants.globals[Module.constants.strings.EC2] != Module.constants.strings.TRUE) { /* Default to localhost */
- Module.constants.globals[Module.constants.strings.INSTANCE_ID] = 'none';
- Module.constants.globals[Module.constants.strings.LOCAL_IPV4] = '127.0.0.1';
- Module.constants.globals[Module.constants.strings.PUBLIC_HOSTNAME] = '127.0.0.1';
- return;
+UtilitiesManagerModule.prototype.getInstanceId = function (callback) {
+ if (Module.constants.globals[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
+ [Module.constants.strings.INSTANCE_ID].forEach(function (
+ parameter) {
+ require('child_process').exec(
+ Module.constants.strings.EC2_METADATA_SCRIPT + ' --' + parameter + ' | awk \'{print$2}\'', function (error, stdout, stderr) {
+ if (error) {
+ console.log('Error auto-configuring: ' + error + ', exiting application');
+ process.exit(1);
+ } else { /* Debug */
+ /* console.log('Read ec2 parameter: ' + parameter + ', with value: ' + stdout); */
+ callback(stdout);
+ }
+ });
+ });
}
+ callback('none');
+};
- [Module.constants.strings.INSTANCE_ID, Module.constants.strings.LOCAL_IPV4, Module.constants.strings.PUBLIC_HOSTNAME].forEach(function (
- parameter) {
- require('child_process').exec(
- Module.constants.strings.EC2_METADATA_SCRIPT + ' --' + parameter + ' | awk \'{print$2}\'', function (error, stdout, stderr) {
- if (error) {
- console.log('Error auto-configuring: ' + error + ', exiting application');
- process.exit(1);
- } else {
- /* Debug */
- /* console.log('Read ec2 parameter: ' + parameter + ', with value: ' + stdout); */
- Module.constants.globals[parameter] = stdout;
- }
+UtilitiesManagerModule.prototype.getPublicHostname = function (callback) {
+ if (Module.constants.globals[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
+ [Module.constants.strings.PUBLIC_HOSTNAME].forEach(function (
+ parameter) {
+ require('child_process').exec(
+ Module.constants.strings.EC2_METADATA_SCRIPT + ' --' + parameter + ' | awk \'{print$2}\'', function (error, stdout, stderr) {
+ if (error) {
+ console.log('Error auto-configuring: ' + error + ', exiting application');
+ process.exit(1);
+ } else { /* Debug */
+ /* console.log('Read ec2 parameter: ' + parameter + ', with value: ' + stdout); */
+ callback(stdout);
+ }
+ });
});
- callback(Module.constants.globals);
- });
+ }
+ callback('127.0.0.1');
+};
+
+UtilitiesManagerModule.prototype.getInternalIP = function (callback) {
+ if (Module.constants.globals[Module.constants.strings.EC2] == Module.constants.strings.TRUE) {
+ [Module.constants.strings.LOCAL_IPV4].forEach(function (
+ parameter) {
+ require('child_process').exec(
+ Module.constants.strings.EC2_METADATA_SCRIPT + ' --' + parameter + ' | awk \'{print$2}\'', function (error, stdout, stderr) {
+ if (error) {
+ console.log('Error auto-configuring: ' + error + ', exiting application');
+ process.exit(1);
+ } else { /* Debug */
+ /* console.log('Read ec2 parameter: ' + parameter + ', with value: ' + stdout); */
+ callback(stdout);
+ }
+ });
+ });
+ }
+ callback('127.0.0.1');
};
UtilitiesManagerModule.prototype.isEven = function (number) {

0 comments on commit 8e712d9

Please sign in to comment.