mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-03 20:14:21 -04:00
Added postgres monitor
This commit is contained in:
parent
a3b94aa532
commit
945288f0c0
5 changed files with 268 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue