Skip to content

Commit

Permalink
Made querying Sense log db optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mountaindude committed Dec 18, 2018
1 parent c71ca16 commit 6121e7c
Showing 1 changed file with 75 additions and 71 deletions.
146 changes: 75 additions & 71 deletions butler-sos.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,18 @@ function getStatsFromSense(host, serverName) {
);
}

// Configure timer for getting log data from Postgres
setInterval(function () {
globals.logger.verbose("Event started: Query log db");

// checkout a Postgres client from connection pool
globals.pgPool.connect()
.then(pgClient => {
return pgClient
.query(
`select
if (globals.config.get("Butler-SOS.logdb.enableLogDb") == true) {

// Configure timer for getting log data from Postgres
setInterval(function () {
globals.logger.verbose("Event started: Query log db");

// checkout a Postgres client from connection pool
globals.pgPool.connect()
.then(pgClient => {
return pgClient
.query(
`select
id,
entry_timestamp as timestamp,
entry_level,
Expand All @@ -337,68 +339,70 @@ setInterval(function () {
order by
entry_timestamp desc
`
)
.then(res => {
pgClient.release();
globals.logger.debug("Log db query got a response.");

var rows = res.rows;
rows.forEach(function (row) {
globals.logger.silly("Log db row: " + JSON.stringify(row));

// Post to Influxdb (if enabled)
if (globals.config.get("Butler-SOS.influxdbConfig.enableInfluxdb")) {
globals.logger.debug("Posting log db data to Influxdb...");

// Write the whole reading to Influxdb
globals.influx
.writePoints([{
measurement: "log_entry",
tags: {
host: row.process_host,
source_process: row.process_name,
log_level: row.entry_level
},
fields: {
message: row.payload.Message
},
timestamp: row.timestamp
}])
.then(err => {
globals.logger.silly("Sent log db event to Influxdb. ");
})
.catch(err => {
console.error(
`Error saving log event to InfluxDB! ${err.stack}`
);
});
}

// Post to MQTT (if enabled)
if (globals.config.get("Butler-SOS.mqttConfig.enableMQTT")) {
globals.logger.debug("Posting log db data to MQTT...");
postLogDbToMQTT(
row.process_host,
row.process_name,
row.entry_level,
row.payload.Message,
row.timestamp
);
}
)
.then(res => {
pgClient.release();
globals.logger.debug("Log db query got a response.");

var rows = res.rows;
rows.forEach(function (row) {
globals.logger.silly("Log db row: " + JSON.stringify(row));

// Post to Influxdb (if enabled)
if (globals.config.get("Butler-SOS.influxdbConfig.enableInfluxdb")) {
globals.logger.debug("Posting log db data to Influxdb...");

// Write the whole reading to Influxdb
globals.influx
.writePoints([{
measurement: "log_entry",
tags: {
host: row.process_host,
source_process: row.process_name,
log_level: row.entry_level
},
fields: {
message: row.payload.Message
},
timestamp: row.timestamp
}])
.then(err => {
globals.logger.silly("Sent log db event to Influxdb. ");
})
.catch(err => {
console.error(
`Error saving log event to InfluxDB! ${err.stack}`
);
});
}

// Post to MQTT (if enabled)
if (globals.config.get("Butler-SOS.mqttConfig.enableMQTT")) {
globals.logger.debug("Posting log db data to MQTT...");
postLogDbToMQTT(
row.process_host,
row.process_name,
row.entry_level,
row.payload.Message,
row.timestamp
);
}
});
})
.then(res => {
globals.logger.verbose("Sent log event to Influxdb. ");
})
.catch(err => {
pgClient.release();
globals.logger.error("Log db query error: " + err.stack);
});
})
.then(res => {
globals.logger.verbose("Sent log event to Influxdb. ");
})
.catch(err => {
pgClient.release();
globals.logger.error("Log db query error: " + err.stack);
});
})
.catch(err => {
globals.logger.error("ERROR: Could not connect to Postgre log db: " + err.stack);
});
}, globals.config.get("Butler-SOS.logdb.pollingInterval"));
})
.catch(err => {
globals.logger.error("ERROR: Could not connect to Postgres log db: " + err.stack);
});
}, globals.config.get("Butler-SOS.logdb.pollingInterval"));
}


// Configure timer for getting healthcheck data
setInterval(function () {
Expand Down

0 comments on commit 6121e7c

Please sign in to comment.