Page 1 of 1
hosttemplates overview from database
Posted: Wed Apr 25, 2018 4:13 am
by sltn_support
Hi,
Is there a to create a list from the Nagios database where the hosts show the used templates.
In CCM I can view the host with templates used but I would like to know how this is done in sql.
Regards, Patrick.
Re: hosttemplates overview from database
Posted: Wed Apr 25, 2018 3:18 pm
by cdienger
echo "select * from tbl_lnkHosttemplateToHost;" | mysql -uroot -pnagiosxi -Dnagiosql
echo "select * from tbl_lnkHostToHosttemplate;" | mysql -uroot -pnagiosxi -Dnagios
The above will show you links between hosts and hosttemplate ids. The ids can then be linked to ids found in tbl_host and tbl_hosttemplate.
Re: hosttemplates overview from database
Posted: Thu Apr 26, 2018 4:42 am
by sltn_support
cdienger wrote:echo "select * from tbl_lnkHosttemplateToHost;" | mysql -uroot -pnagiosxi -Dnagiosql
echo "select * from tbl_lnkHostToHosttemplate;" | mysql -uroot -pnagiosxi -Dnagios
The above will show you links between hosts and hosttemplate ids. The ids can then be linked to ids found in tbl_host and tbl_hosttemplate.
Hi,
with the first line I get 0 results and with the second one I get 2878 rows.
In the ccm I can see the assigned templates; this has to be a sql statement, right?
Re: hosttemplates overview from database
Posted: Thu Apr 26, 2018 7:06 am
by mcapra
As mentioned by
@cdienger, you'll need to join the results of those queries to their respective object tables.
There is indeed logic within the Nagios XI code that resolves this, but I don't believe it's a simple static SQL command that you could copy+paste and have it work. It's a generic set of functions that joins objects with linking tables; Having hard-coded queries do this wouldn't be very efficient.
If you're interested in exactly how that works, the
NagiosQL source code is publicly available.
Re: hosttemplates overview from database
Posted: Thu Apr 26, 2018 10:18 am
by cdienger
Thanks for the clarification and link,
@mcapra!