loganalysis
Version:
Collects stdout and stderr messages from Node.js applications and sends them to the IBM SmartCloud Analytics - Log Analysis service.
79 lines (70 loc) • 2.52 kB
JavaScript
/*
* © Copyright IBM Corp. 2014
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var cloud_app = {};
module.exports = cloud_app;
var env = process.env;
cloud_app.isRunninginCloud = env.VCAP_APPLICATION ? true : false;
if (env.VCAP_APPLICATION) {
var vcap_application = JSON.parse(env.VCAP_APPLICATION);
cloud_app.vcap_application = vcap_application;
cloud_app.application_name = vcap_application.application_name;
cloud_app.application_version = vcap_application.application_version;
cloud_app.instance_index = vcap_application.instance_index;
cloud_app.instance_id = vcap_application.instance_id;
//cloud_app.app_guid = vcap_application.app_guid;
cloud_app.bm_source = 'node-js-console';
} else {
cloud_app.application_name = 'node-js-sample-app';
cloud_app.instance_id = 'node-js-sample-app-id';
cloud_app.instance_index = 0;
//cloud_app.app_guid = 'nodejs-1';
cloud_app.bm_source = 'node-js-console';
}
if (env.VCAP_SERVICES) {
cloud_app.vcap_services = JSON.parse(env.VCAP_SERVICES);
}else { //hard coded for local testing
cloud_app.vcap_services = {};
cloud_app.vcap_services["MonitoringAndAnalytics"] = [{
name : "Monitoring and Analytics-ux",
label: "MonitoringAndAnalytics",
tags: ["dev_ops"],
plan: "Plan for MonitoringAndAnalytics",
credentials : {
scala_url : 'https://localhost:9987',
scala_userid : "unityuser",
scala_password: "unityuser",
//WTF! app_guid is in service's VCAP variable? That too in 'credentials'??
app_guid : 'nodejs-1',
keyfile : ""
}
}];
}
cloud_app.findVCAPServicesByType = function (type) {
if (!cloud_app.vcap_services) {
return [];
}
var serviceObjects = [];
for (var name in cloud_app.vcap_services) {
if (name.indexOf(type) == -1) {
continue;
}
var services = cloud_app.vcap_services[name];
for (var i = 0, length = services.length; i < length; i++) {
serviceObjects.push(services[i]);
}
}
return serviceObjects;
};