Query sql Database

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
rambertnala
Posts: 60
Joined: Fri Feb 26, 2016 7:15 am

Query sql Database

Post by rambertnala »

Hi everybody.

I need help to do this.

I need to do a query to sql table and get value at las row and third column. That value is not integer. It's a nvchar value

So i need to get that value stored at that position, using plugin nagios from nrpe.

I have installed Nsclient 0.4.3 at conmputer where i wanna get value.

I don't know if i have explained very well which i need.

Thanks and regards.
rambertnala
Posts: 60
Joined: Fri Feb 26, 2016 7:15 am

Re: Query sql Database

Post by rambertnala »

Ok

I need to execute a query like this

select top 1 from ... order by... DESC

using check_nrpe from my nagios server.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Query sql Database

Post by mcapra »

Here's a basic table:

Code: Select all

MariaDB [test]> SELECT * FROM mytable;
+------+----------------+
| pkey | value          |
+------+----------------+
|    1 | welcome        |
|    2 | hello          |
|    3 | something else |
+------+----------------+
3 rows in set (0.00 sec)
If I wanted to get the pkey that is largest, I could execute the following query:

Code: Select all

MariaDB [test]> SELECT * FROM mytable ORDER BY pkey DESC LIMIT 1;
+------+----------------+
| pkey | value          |
+------+----------------+
|    3 | something else |
+------+----------------+
1 row in set (0.00 sec)
On your machine that is using NSClient++, your first step would be acquiring a plugin that allows you to execute MySQL queries. I don't see any on the exchange currently that work with the windows command line, so you'd either have to write one yourself or get perl on the NSClient++ machine and leverage a plugin like this: https://exchange.nagios.org/directory/P ... n)/details

If the MySQL database has a user with remote access, you could check the query from your Nagios Core machine using the above plugin.
Former Nagios employee
https://www.mcapra.com/
rambertnala
Posts: 60
Joined: Fri Feb 26, 2016 7:15 am

Re: Query sql Database

Post by rambertnala »

Hi thanks for your answer

Is a MSSQL Database, not MySQL
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Query sql Database

Post by rkennedy »

See if any of the plugins will work for you on our Exchange as @mcapra mentioned. This is regardless of MySQL or MSSQL. Here's a quick link -
https://exchange.nagios.org/index.php?o ... word=mssql
Former Nagios Employee
Locked