SQL select 打印 Icinga2 主机组中的所有主机名
SQL select to print all host names in Icinga2 hostgroup
select alias from icinga_hosts;
打印每个主机组中的所有主机名。
select alias from icinga_hostgroups;
打印所有主机组。
我看不到如何 "select select alias from icinga_hosts where icinga_hostgroups is "customer0";
换句话说,'print all the hostnames in hostgroup customer0'.
我需要某种加入吗?这是 MariaDB 5.5。感谢您的任何建议。
MariaDB [icinga]> show fields in icinga_hostgroups;
+---------------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------------+------+-----+---------+----------------+
| hostgroup_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| instance_id | bigint(20) unsigned | YES | MUL | 0 | |
| config_type | smallint(6) | YES | | 0 | |
| hostgroup_object_id | bigint(20) unsigned | YES | | 0 | |
| alias | varchar(255) | YES | | | |
| notes | text | YES | | NULL | |
| notes_url | text | YES | | NULL | |
| action_url | text | YES | | NULL | |
| config_hash | varchar(64) | YES | | NULL | |
+---------------------+---------------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)
show fields in icinga_hosts;
+-----------------------------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------------------+---------------------+------+-----+---------+----------------+
| host_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| instance_id | bigint(20) unsigned | YES | MUL | 0 | |
| config_type | smallint(6) | YES | | 0 | |
| host_object_id | bigint(20) unsigned | YES | MUL | 0 | |
| alias | varchar(255) | YES | | | |
| display_name | varchar(255) | YES | | | |
| address | varchar(128) | YES | | | |
您需要 icinga_hostgroup_members
table 如:
SELECT groups.alias AS 'Group',
hosts.alias AS Host
FROM icinga_hosts AS hosts
JOIN icinga_hostgroup_members AS group_members
ON hosts.host_object_id = group_members.host_object_id
JOIN icinga_hostgroups AS groups
ON group_members.hostgroup_id = groups.hostgroup_id
WHERE groups.alias = 'customer0';
select oh.name1 as host_name, ohg.name1 as hostgroup_name
from icinga_hosts h
join icinga_objects oh on h.host_object_id=oh.object_id
join icinga_hostgroup_members hgm on hgm.host_object_id=h.host_object_id
join icinga_hostgroups hg on hg.hostgroup_id=hgm.hostgroup_id
join icinga_objects ohg on hg.hostgroup_object_id=ohg.object_id
where ohg.name1='linux-servers';
select alias from icinga_hosts;
打印每个主机组中的所有主机名。
select alias from icinga_hostgroups;
打印所有主机组。
我看不到如何 "select select alias from icinga_hosts where icinga_hostgroups is "customer0";
换句话说,'print all the hostnames in hostgroup customer0'.
我需要某种加入吗?这是 MariaDB 5.5。感谢您的任何建议。
MariaDB [icinga]> show fields in icinga_hostgroups;
+---------------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------------+------+-----+---------+----------------+
| hostgroup_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| instance_id | bigint(20) unsigned | YES | MUL | 0 | |
| config_type | smallint(6) | YES | | 0 | |
| hostgroup_object_id | bigint(20) unsigned | YES | | 0 | |
| alias | varchar(255) | YES | | | |
| notes | text | YES | | NULL | |
| notes_url | text | YES | | NULL | |
| action_url | text | YES | | NULL | |
| config_hash | varchar(64) | YES | | NULL | |
+---------------------+---------------------+------+-----+---------+----------------+
9 rows in set (0.00 sec)
show fields in icinga_hosts;
+-----------------------------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------------------+---------------------+------+-----+---------+----------------+
| host_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| instance_id | bigint(20) unsigned | YES | MUL | 0 | |
| config_type | smallint(6) | YES | | 0 | |
| host_object_id | bigint(20) unsigned | YES | MUL | 0 | |
| alias | varchar(255) | YES | | | |
| display_name | varchar(255) | YES | | | |
| address | varchar(128) | YES | | | |
您需要 icinga_hostgroup_members
table 如:
SELECT groups.alias AS 'Group',
hosts.alias AS Host
FROM icinga_hosts AS hosts
JOIN icinga_hostgroup_members AS group_members
ON hosts.host_object_id = group_members.host_object_id
JOIN icinga_hostgroups AS groups
ON group_members.hostgroup_id = groups.hostgroup_id
WHERE groups.alias = 'customer0';
select oh.name1 as host_name, ohg.name1 as hostgroup_name
from icinga_hosts h
join icinga_objects oh on h.host_object_id=oh.object_id
join icinga_hostgroup_members hgm on hgm.host_object_id=h.host_object_id
join icinga_hostgroups hg on hg.hostgroup_id=hgm.hostgroup_id
join icinga_objects ohg on hg.hostgroup_object_id=ohg.object_id
where ohg.name1='linux-servers';