0

select alias from icinga_hosts;打印每个主机组中的所有主机名。

select alias from icinga_hostgroups;打印所有主机组。

我看不到如何“从 icinga_hosts 中选择别名,其中 icinga_hostgroups 是“customer0”;

换句话说,“打印主机组 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  |     |         |                |
4

2 回答 2

0

你需要这样的icinga_hostgroup_members表:

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';
于 2018-02-18T22:10:42.390 回答
0
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';
于 2018-02-19T20:03:04.480 回答