Added postgres monitor

This commit is contained in:
Christopher Pickering 2022-06-15 12:12:47 -05:00
parent a3b94aa532
commit 945288f0c0
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
5 changed files with 268 additions and 8 deletions

View file

@ -11,6 +11,7 @@ const mqtt = require("mqtt");
const chroma = require("chroma-js");
const { badgeConstants } = require("./config");
const mssql = require("mssql");
const { Client } = require("pg");
const { NtlmClient } = require("axios-ntlm");
// From ping-lite
@ -254,6 +255,33 @@ exports.mssqlQuery = function (connectionString, query) {
});
};
/**
* Run a query on Postgres
* @param {string} connectionString The database connection string
* @param {string} query The query to validate the database with
* @returns {Promise<(string[]|Object[]|Object)>}
*/
exports.postgresQuery = function (connectionString, query) {
return new Promise((resolve, reject) => {
const client = new Client({ connectionString });
client.connect();
client.query(query)
.then(res => {
resolve(res);
})
.catch(err => {
reject(err);
})
.finally(() => {
client.end();
});
});
};
/**
* Retrieve value of setting based on key
* @param {string} key Key of setting to retrieve