Skip to content

Commit

Permalink
fix(logdb): Don't set up log db data structures if that feature is di…
Browse files Browse the repository at this point in the history
…sabled in config file
  • Loading branch information
Göran Sander committed May 19, 2024
1 parent 1d6989e commit 153ad9d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/config/production_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Butler-SOS:
enable: false
# Items below are mandatory if logdb.enable=true
pollingInterval: 60000 # How often (milliseconds) should Postgres log db be queried for warnings and errors?
queryPeriod: 5 minutes # How far back should Butler SOS query for log entries? Default is 5 min
queryPeriod: 5 minutes # How far back should Butler SOS query for log entries?
host: <IP or FQDN of Qlik Sense logging db> # E.g. 10.5.23.7 or sense.mycompany.com
port: 4432 # 4432 if using default Sense setup
qlogsReaderUser: qlogs_reader
Expand Down
37 changes: 20 additions & 17 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ if (
) {
config['Butler-SOS'].thirdPartyToolsCredentials.newRelic = [];

//
for (let index = 0; index < options.newRelicApiKey.length; index++) {
for (let index = 0; index < options.newRelicApiKey.length; index += 1) {
const accountName = options.newRelicAccountName[index];
const accountId = options.newRelicAccountId[index];
const insertApiKey = options.newRelicApiKey[index];
Expand Down Expand Up @@ -252,22 +251,26 @@ try {
// Get info on what servers to monitor
const serverList = config.get('Butler-SOS.serversToMonitor.servers');

// Set up connection pool for accessing Qlik Sense log db
const pgPool = new Pool({
host: config.get('Butler-SOS.logdb.host'),
database: 'QLogs',
user: config.get('Butler-SOS.logdb.qlogsReaderUser'),
password: config.get('Butler-SOS.logdb.qlogsReaderPwd'),
port: config.get('Butler-SOS.logdb.port'),
});
// Only set up connection pool for accessing Qlik Sense log db if that feature is enabled
let pgPool;
if (config.get('Butler-SOS.logdb.enable') === true) {
// Set up connection pool for accessing Qlik Sense log db
pgPool = new Pool({
host: config.get('Butler-SOS.logdb.host'),
database: 'QLogs',
user: config.get('Butler-SOS.logdb.qlogsReaderUser'),
password: config.get('Butler-SOS.logdb.qlogsReaderPwd'),
port: config.get('Butler-SOS.logdb.port'),
});

// the pool will emit an error on behalf of any idle clients
// it contains if a backend error or network partition happens
// eslint-disable-next-line no-unused-vars
pgPool.on('error', (err, client) => {
logger.error(`CONFIG: Unexpected error on idle client: ${err}`);
// process.exit(-1);
});
// the pool will emit an error on behalf of any idle clients
// it contains if a backend error or network partition happens
// eslint-disable-next-line no-unused-vars
pgPool.on('error', (err, client) => {
logger.error(`CONFIG: Unexpected error on idle client: ${err}`);
// process.exit(-1);
});
}

// Get list of standard and user configurable tags
// ..begin with standard tags
Expand Down
7 changes: 2 additions & 5 deletions src/lib/logdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ const globals = require('../globals');
const postToMQTT = require('./post-to-mqtt');

function setupLogDbTimer() {
// Get query period from config file. If not specified there, use default value.
let queryPeriod = '5 minutes';
if (globals.config.has('Butler-SOS.logdb.queryPeriod')) {
queryPeriod = globals.config.get('Butler-SOS.logdb.queryPeriod');
}
// Get query period from config file.
const queryPeriod = globals.config.get('Butler-SOS.logdb.queryPeriod');

// Configure timer for getting log data from Postgres
setInterval(() => {
Expand Down

0 comments on commit 153ad9d

Please sign in to comment.