Page 1 of 1

List of host templates

Posted: Wed Oct 07, 2015 9:31 am
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?

Re: List of host templates

Posted: Wed Oct 07, 2015 9:36 am
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.

Re: List of host templates

Posted: Wed Oct 07, 2015 9:45 am
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

Re: List of host templates

Posted: Wed Oct 07, 2015 9:48 am
by jomann
Awesome :)