extract info from MySQL db

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.
Rhobar
Posts: 41
Joined: Sat Mar 16, 2013 9:23 am
Location: Rome, Italy

extract info from MySQL db

Post by Rhobar »

Hello World!

Now my nagios+NDOutils+MySQL is running up!

so, I have other questions for you :D
please, don't kill me :lol:

now I have to create an php application that reads from MySQL db and creates XML doc...
The XML doc is a probedata of checked service from nagios

if I want only the informations about check_local_load service, for example, which select MySQL command should I to use?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: extract info from MySQL db

Post by scottwilkerson »

this should help finding what you are looking for

http://nagios.sourceforge.net/docs/ndou ... _Model.pdf
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Rhobar
Posts: 41
Joined: Sat Mar 16, 2013 9:23 am
Location: Rome, Italy

Re: extract info from MySQL db

Post by Rhobar »

I read it, but it is a bit too complicated for me (my English is not very good :D ), so I asked for help here
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: extract info from MySQL db

Post by abrist »

It all depends what you called the service check. This is usually not support that we provide as it is a custom solution for a specific setup. You should spend a bit of time getting acquainted with mysql and the syntax of queries. Start with the following documentation:
http://dev.mysql.com/doc/
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Rhobar
Posts: 41
Joined: Sat Mar 16, 2013 9:23 am
Location: Rome, Italy

Re: extract info from MySQL db

Post by Rhobar »

I tried this:

Code: Select all

mysql> select output from nagios_servicestatus;
+--------------------------------------------------------------------+
| output                                                             |
+--------------------------------------------------------------------+
| PROCS OK: 106 processes with STATE = RSZDT                         |
| SSH OK - OpenSSH_5.3 (protocol 2.0)                                |
| SWAP OK - 100% free (4031 MB out of 4031 MB)                       |
| PING OK - Packet loss = 0%, RTA = 0.05 ms                          |
| DISK OK - free space: / 10828 MB (72% inode=88%):                  |
| USERS OK - 2 users currently logged in                             |
| HTTP OK: HTTP/1.1 200 OK - 265 bytes in 0.011 second response time |
| OK - load average: 0.24, 0.05, 0.02                                |
+--------------------------------------------------------------------+
8 rows in set (0.00 sec)
and it is ok, but which select command I hate to use if I want only the one of these lines?
For example, I need only check_load line (in this case is the last), is it possible to have a select command that has as result only one of these lines?
How becomes the select command in that case?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: extract info from MySQL db

Post by scottwilkerson »

First you will need to find the line to filter by
run

Code: Select all

select * from nagios_servicestatus;
Get the service_id for the one you want
Then

Code: Select all

select output from nagios_servicestatus where service_id=<ID_YOU_SELECTED>;
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Rhobar
Posts: 41
Joined: Sat Mar 16, 2013 9:23 am
Location: Rome, Italy

Re: extract info from MySQL db

Post by Rhobar »

thanks ;)

i've done this:

Code: Select all

mysql> select output from nagios_servicestatus where service_object_id=3;
+-------------------------------------+
| output                              |
+-------------------------------------+
| OK - load average: 0.25, 0.16, 0.06 |
+-------------------------------------+
1 row in set (0.00 sec)
but another question...
that object_id is always the same or changes sometimes?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: extract info from MySQL db

Post by scottwilkerson »

It should always remain the same. Your not going to get a ton of basic SQL support here but one thing you could do is something like this, replacing localhost and Ping with what you are looking for

Code: Select all

select s.output from nagios_servicestatus s, nagios_objects o where s.service_object_id=o.object_id AND o.name1='localhost' AND o.name2='Ping';
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Rhobar
Posts: 41
Joined: Sat Mar 16, 2013 9:23 am
Location: Rome, Italy

Re: extract info from MySQL db

Post by Rhobar »

hi!
scottwilkerson wrote:

Code: Select all

select s.output from nagios_servicestatus s, nagios_objects o where s.service_object_id=o.object_id AND o.name1='localhost' AND o.name2='Ping';
what does "s" stand for?
scottwilkerson wrote:Your not going to get a ton of basic SQL support here
you're right, sorry :oops:
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: extract info from MySQL db

Post by scottwilkerson »

Rhobar wrote:what does "s" stand for?
In the query I had this

Code: Select all

from nagios_servicestatus s
So s becomes shorthand for nagios_servicestatus table

and because I also had

Code: Select all

 nagios_objects o
o is short for nagios_objects

you could also use

Code: Select all

select nagios_servicestatus.output from nagios_servicestatus, nagios_objects where nagios_servicestatus.service_object_id=nagios_objects.object_id and nagios_objects.name1='localhost' and nagios_objects.name2='Ping';
But that's just messy compared to

Code: Select all

SELECT s.output FROM nagios_servicestatus s, nagios_objects o WHERE s.service_object_id=o.object_id AND o.name1='localhost' AND o.name2='Ping';
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked