mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-04 13:46:13 +08:00 
			
		
		
		
	Merge pull request #2328 from rmarops/mongodb-ping
added MongoDB ping monitor
This commit is contained in:
		
							
								
								
									
										2181
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2181
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -96,6 +96,7 @@
 | 
				
			|||||||
        "jsonwebtoken": "~9.0.0",
 | 
					        "jsonwebtoken": "~9.0.0",
 | 
				
			||||||
        "jwt-decode": "~3.1.2",
 | 
					        "jwt-decode": "~3.1.2",
 | 
				
			||||||
        "limiter": "~2.1.0",
 | 
					        "limiter": "~2.1.0",
 | 
				
			||||||
 | 
					        "mongodb": "~4.13.0",
 | 
				
			||||||
        "mqtt": "~4.3.7",
 | 
					        "mqtt": "~4.3.7",
 | 
				
			||||||
        "mssql": "~8.1.4",
 | 
					        "mssql": "~8.1.4",
 | 
				
			||||||
        "mysql2": "~2.3.3",
 | 
					        "mysql2": "~2.3.3",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ const axios = require("axios");
 | 
				
			|||||||
const { Prometheus } = require("../prometheus");
 | 
					const { Prometheus } = require("../prometheus");
 | 
				
			||||||
const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, TimeLogger, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND } = require("../../src/util");
 | 
					const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, TimeLogger, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND } = require("../../src/util");
 | 
				
			||||||
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, mqttAsync, setSetting, httpNtlm, radius, grpcQuery,
 | 
					const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, mqttAsync, setSetting, httpNtlm, radius, grpcQuery,
 | 
				
			||||||
    redisPingAsync
 | 
					    redisPingAsync, mongodbPing,
 | 
				
			||||||
} = require("../util-server");
 | 
					} = require("../util-server");
 | 
				
			||||||
const { R } = require("redbean-node");
 | 
					const { R } = require("redbean-node");
 | 
				
			||||||
const { BeanModel } = require("redbean-node/dist/bean-model");
 | 
					const { BeanModel } = require("redbean-node/dist/bean-model");
 | 
				
			||||||
@@ -583,6 +583,15 @@ class Monitor extends BeanModel {
 | 
				
			|||||||
                    bean.msg = "";
 | 
					                    bean.msg = "";
 | 
				
			||||||
                    bean.status = UP;
 | 
					                    bean.status = UP;
 | 
				
			||||||
                    bean.ping = dayjs().valueOf() - startTime;
 | 
					                    bean.ping = dayjs().valueOf() - startTime;
 | 
				
			||||||
 | 
					                } else if (this.type === "mongodb") {
 | 
				
			||||||
 | 
					                    let startTime = dayjs().valueOf();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await mongodbPing(this.databaseConnectionString);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    bean.msg = "";
 | 
				
			||||||
 | 
					                    bean.status = UP;
 | 
				
			||||||
 | 
					                    bean.ping = dayjs().valueOf() - startTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                } else if (this.type === "radius") {
 | 
					                } else if (this.type === "radius") {
 | 
				
			||||||
                    let startTime = dayjs().valueOf();
 | 
					                    let startTime = dayjs().valueOf();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ const mssql = require("mssql");
 | 
				
			|||||||
const { Client } = require("pg");
 | 
					const { Client } = require("pg");
 | 
				
			||||||
const postgresConParse = require("pg-connection-string").parse;
 | 
					const postgresConParse = require("pg-connection-string").parse;
 | 
				
			||||||
const mysql = require("mysql2");
 | 
					const mysql = require("mysql2");
 | 
				
			||||||
 | 
					const { MongoClient } = require("mongodb");
 | 
				
			||||||
const { NtlmClient } = require("axios-ntlm");
 | 
					const { NtlmClient } = require("axios-ntlm");
 | 
				
			||||||
const { Settings } = require("./settings");
 | 
					const { Settings } = require("./settings");
 | 
				
			||||||
const grpc = require("@grpc/grpc-js");
 | 
					const grpc = require("@grpc/grpc-js");
 | 
				
			||||||
@@ -318,6 +319,23 @@ exports.mysqlQuery = 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 = await MongoClient.connect(connectionString);
 | 
				
			||||||
 | 
					    let dbPing = await client.db().command({ ping: 1 });
 | 
				
			||||||
 | 
					    await client.close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (dbPing["ok"] === 1) {
 | 
				
			||||||
 | 
					        return "UP";
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        throw Error("failed");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Query radius server
 | 
					 * Query radius server
 | 
				
			||||||
 * @param {string} hostname Hostname of radius server
 | 
					 * @param {string} hostname Hostname of radius server
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,6 +57,9 @@
 | 
				
			|||||||
                                        <option value="mysql">
 | 
					                                        <option value="mysql">
 | 
				
			||||||
                                            MySQL/MariaDB
 | 
					                                            MySQL/MariaDB
 | 
				
			||||||
                                        </option>
 | 
					                                        </option>
 | 
				
			||||||
 | 
					                                        <option value="mongodb">
 | 
				
			||||||
 | 
					                                            MongoDB
 | 
				
			||||||
 | 
					                                        </option>
 | 
				
			||||||
                                        <option value="radius">
 | 
					                                        <option value="radius">
 | 
				
			||||||
                                            Radius
 | 
					                                            Radius
 | 
				
			||||||
                                        </option>
 | 
					                                        </option>
 | 
				
			||||||
@@ -277,6 +280,18 @@
 | 
				
			|||||||
                                    <input id="redisConnectionString" v-model="monitor.databaseConnectionString" type="text" class="form-control" placeholder="redis://user:password@host:port">
 | 
					                                    <input id="redisConnectionString" v-model="monitor.databaseConnectionString" type="text" class="form-control" placeholder="redis://user:password@host:port">
 | 
				
			||||||
                                </div>
 | 
					                                </div>
 | 
				
			||||||
                            </template>
 | 
					                            </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            <!-- MongoDB -->
 | 
				
			||||||
 | 
					                            <template v-if="monitor.type === 'mongodb'">
 | 
				
			||||||
 | 
					                                <div class="my-3">
 | 
				
			||||||
 | 
					                                    <label for="sqlConnectionString" class="form-label">{{ $t("Connection String") }}</label>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                    <template v-if="monitor.type === 'mongodb'">
 | 
				
			||||||
 | 
					                                        <input id="sqlConnectionString" v-model="monitor.databaseConnectionString" type="text" class="form-control" placeholder="mongodb://username:password@host:port/database">
 | 
				
			||||||
 | 
					                                    </template>
 | 
				
			||||||
 | 
					                                </div>
 | 
				
			||||||
 | 
					                            </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            <!-- Interval -->
 | 
					                            <!-- Interval -->
 | 
				
			||||||
                            <div class="my-3">
 | 
					                            <div class="my-3">
 | 
				
			||||||
                                <label for="interval" class="form-label">{{ $t("Heartbeat Interval") }} ({{ $t("checkEverySecond", [ monitor.interval ]) }})</label>
 | 
					                                <label for="interval" class="form-label">{{ $t("Heartbeat Interval") }} ({{ $t("checkEverySecond", [ monitor.interval ]) }})</label>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user