louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
55.89k stars 5.03k forks source link

Add Oracle as a new monitor #2493

Open simone80an opened 1 year ago

simone80an commented 1 year ago

⚠️ Please verify that this feature request has NOT been suggested before.

🏷️ Feature Request Type

New Monitor

🔖 Feature description

Having Oracle as a new Specific Monitor Type so i can monitor also Oracle db servers.

✔️ Solution

Testing connection of Oracle database servers.

❓ Alternatives

No response

📝 Additional Context

No response

bitsky6 commented 1 year ago

Any Update regarding this?

simone80an commented 1 year ago

I did a test using uptime-kuma version 19.4 and the following steps:

<template v-if="monitor.type === 'oracledb'">
    <input id="sqlConnectionString" v-model="monitor.databaseConnectionString" type="text" class="form-control" placeholder='"user":"<USER>","password":"<PASSWORD>","connectionString":"(DESCRIPTION =(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=<HOSTADDRESS>)(PORT=<PORT>)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=<SERVICENAME>)))"'>
</template>

added new const

const oracledb = require("oracledb");

added this code at line 321:

/**
 * Run a query on Oracle DB
 * @param {string} connectionString The database connection string
 * @param {string} query The query to validate the database with
 * @returns {Promise<(string[]|Object[]|Object)>}
 */
exports.oracledbQuery = async function (connectionString, query) {

    try {

        let connectionStringJson=JSON.parse('{' + connectionString + '}');
        let connection = await oracledb.getConnection(connectionStringJson);

        await connection.execute(query);
        await connection.close();

    } 
    catch (err) {
        throw err;
    } 

};

modified line 6 as following:

const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, oracledbQuery, mqttAsync, setSetting, httpNtlm, radius, grpcQuery } = require("../util-server");

added this code at line 584:

else if (this.type === "oracledb") {
    let startTime = dayjs().valueOf();

    await oracledbQuery(this.databaseConnectionString, this.databaseQuery);

    bean.msg = "";
    bean.status = UP;
    bean.ping = dayjs().valueOf() - startTime;
}

cd to project dir and run npm rebuild, then start again uptime-kuma. I tested for a couple of weeks and seems working.

bitsky6 commented 1 year ago

Cool maybe ask to build into the next version, make a request. Thanks will try to see if I manage like this.

bitsky6 commented 1 year ago

Hey thanks for that,

I have pushed a pull request for it.