Commit 761d0a3a authored by Félix Hamel's avatar Félix Hamel

1.7.25-beta6

+ Add support for config file for logstash server endpoint
parent 0cc445db
......@@ -294,84 +294,6 @@ CMBF.prototype.launch = P.method(function(pluginOpts) {
_this.log.trace("Server configuration will be", opts);
var server = new Hapi.Server(opts);
server.on("request", function(request) {
if (request.method !== "options") {
// Filter
if(request.headers["user-agent"].indexOf("ELB-HealthChecker") >= 0) {
return;
}
else if(request.headers["user-agent"].indexOf("uptimerobot") >= 0) {
return;
}
let LOG = {
headers: request.headers,
method: request.method,
url: request.url.path,
payload: request.payload
};
if (request.auth.credentials && request.auth.credentials.profile) {
LOG["user"] = {
username: request.auth.credentials.profile.username,
email: request.auth.credentials.profile.email,
token: request.headers.authorization
};
}
server.log(["request"], LOG);
}
});
server.on("response", function(request) {
if (request.method !== "options") {
// Filter
if(request.headers["user-agent"].indexOf("ELB-HealthChecker") >= 0) {
return;
}
else if(request.headers["user-agent"].indexOf("uptimerobot") >= 0) {
return;
}
// Check if output is less than 2000 chars, otherwise only return a message to preserve ELK disk space.
// (Anyway we can retry the query if needed)
if (request.response.source.data) {
var DATA = JSON.stringify(request.response.source.data);
if (DATA.length > 2000) {
DATA = {
"message": "Stripped by logger, please execute again to view the complete response"
};
}
else {
DATA = request.response.source.data;
}
}
let LOG = {
headers: request.headers,
method: request.method,
url: request.url.path,
payload: request.payload,
response: {
data: DATA,
error: request.response.source.error,
message: request.response.source.message,
statusCode: request.response.source.statusCode
}
};
if (request.auth.credentials && request.auth.credentials.profile) {
LOG["user"] = {
username: request.auth.credentials.profile.username,
email: request.auth.credentials.profile.email,
token: request.headers.authorization
};
}
server.log(["response"], LOG);
}
});
_this.server = server;
server.decorate("server", "cmbf", _this);
server.method(
......@@ -390,34 +312,11 @@ CMBF.prototype.launch = P.method(function(pluginOpts) {
function() {
_this.log.debug("Register Early Plugin: hapi-config");
var registerPlugin = P.promisify(server.register, server);
return P.join(
registerPlugin({
register: require("hapi-config"),
options: pluginOpts || {}
}),
registerPlugin({
register: require("good"),
options: {
includes: {
request: ["headers", "payload"]
},
reporters: {
// Send only 'log' events to Logstash
logstash: [
{
module: "good-squeeze",
name: "Squeeze",
args: [{ log: "*", request: "*", response: "*" }]
}, {
module: "good-logstash",
args: [
"udp://logs.cellars.io:5000",
{ tags: ["cellars"] }
]
}
]
}
}
})
);
}
......@@ -607,7 +506,9 @@ CMBF.prototype.launch = P.method(function(pluginOpts) {
config: config,
pluginOptions: pluginOpts
},
function() {
async function() {
// Retrieve the computed configuration
var config = server.plugins["hapi-config"].CurrentConfiguration;
var registerPlugin = P.promisify(server.register, server);
var availablePlugins = config.get("server:framework", [
"covistra-system"
......@@ -616,6 +517,32 @@ CMBF.prototype.launch = P.method(function(pluginOpts) {
"Loading default foundation plugins: hapi-bunyan",
availablePlugins
);
// Check if in the config we have the logstash string
if (config.get("server:log:logstash:enabled") === true) {
await registerPlugin({
register: require("good"),
options: {
includes: {
request: ["headers", "payload"]
},
reporters: {
logstash: [{
module: "good-squeeze",
name: "Squeeze",
args: [{ log: "*", request: "*", response: "*" }]
}, {
module: "good-logstash",
args: [
config.get("server:log:logstash:server"),
{ tags: ["cellars"] }
]
}]
}
}
});
}
return registerPlugin({
register: require("hapi-bunyan"),
options: {
......
{
"name": "cmbf-core",
"version": "1.7.25-beta5",
"version": "1.7.25-beta6",
"description": "Covistra Mobile-Backend Framework Core Module",
"main": "index.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment