List of host templates

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

List of host templates

Post by BanditBBS »

I promise, this is my last coding question for at least the next 2 weeks :)

I'm working on a custom component and I need to list all hosttemplates into a select box. I've done it before with hostgroups using get_xml_hostgroup_objects() but there is no backend call for listing host templates. Anyone know of a way for me to grab all the hosttemplate names?
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: List of host templates

Post by jomann »

I'm not aware of a function in XI that currently just grabs the host templates available. However, it should be easy enough to pull from the nagiosql DB in mysql - table is table_hosttemplate - you should get more than enough info for what you need with just a basic SELECT * FROM nagiosql.tbl_hosttemplate;

I should point out there's a function to run SQL queries

Code: Select all

$rs = exec_sql_query(DB_NAGIOSQL, $sql);
inside of XI since it's already actually connected to each of the DBs. This returns an ADO object which you can use $rs->RecordCount(); to get the amount of records or something like $rs->GetArray(); to get a full array of the data.
You do not have the required permissions to view the files attached to this post.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: List of host templates

Post by BanditBBS »

jomann wrote:I'm not aware of a function in XI that currently just grabs the host templates available. However, it should be easy enough to pull from the nagiosql DB in mysql - table is table_hosttemplate - you should get more than enough info for what you need with just a basic SELECT * FROM nagiosql.tbl_hosttemplate;

I should point out there's a function to run SQL queries

Code: Select all

$rs = exec_sql_query(DB_NAGIOSQL, $sql);
inside of XI since it's already actually connected to each of the DBs. This returns an ADO object which you can use $rs->RecordCount(); to get the amount of records or something like $rs->GetArray(); to get a full array of the data.
Yeah, thanks again man! I did digging in nagios code and stole some of yours :) for anyone else in future, this worked great:

Code: Select all

$hosttemplates = exec_sql_query(DB_NAGIOSQL, "SELECT `template_name` FROM nagiosql.tbl_hosttemplate ORDER BY `template_name`;", true);
You can close this up and I'll not ask coding questions again for 10 days, lol
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: List of host templates

Post by jomann »

Awesome :)
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked