mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-08 07:35:44 +08:00
added MongoDB ping monitor
This commit is contained in:
@@ -13,6 +13,7 @@ const { badgeConstants } = require("./config");
|
||||
const mssql = require("mssql");
|
||||
const { Client } = require("pg");
|
||||
const postgresConParse = require("pg-connection-string").parse;
|
||||
const { MongoClient } = require("mongodb");
|
||||
const { NtlmClient } = require("axios-ntlm");
|
||||
const { Settings } = require("./settings");
|
||||
const grpc = require("@grpc/grpc-js");
|
||||
@@ -294,6 +295,27 @@ exports.postgresQuery = function (connectionString, query) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Connect to and Ping a MongoDB database
|
||||
* @param {string} connectionString The database connection string
|
||||
* @returns {Promise<(string[]|Object[]|Object)>}
|
||||
*/
|
||||
exports.mongodbPing = async function (connectionString) {
|
||||
let client, db;
|
||||
try {
|
||||
client = await MongoClient.connect(connectionString, {useNewUrlParser: true})
|
||||
db = client.db();
|
||||
dbping = await db.command({ ping: 1 });
|
||||
if (dbping["ok"] === 1) {
|
||||
return 'UP'
|
||||
}
|
||||
throw Error("failed");
|
||||
}
|
||||
catch(err){ console.error(err); }
|
||||
finally{ client.close(); }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query radius server
|
||||
* @param {string} hostname Hostname of radius server
|
||||
|
Reference in New Issue
Block a user