通过查看zabbix数据库得到结果,推荐,当然也可以通过zabbix api获取数据,然后通过程序处理。

首先查到所有模板,以及模板ID。

select hostid,name from hosts where status=3;

然后可以查看所有的主机条目,有主机IP地址。

select distinct ip from `interface`;

然后根据模板ID查看此模板关联的主机。

select distinct * from `hosts_templates` as h join `interface` as i  on i.hostid=h.hostid  where h.templateid=10465;

最后根据模板ID查出的主机IP跟所有的主机IP做一个join查询,得到没有添加此模板的主机IP。

select a.ip,b.ip from `interface` a left join (select distinct ip from `hosts_templates` as h join `interface` as i  on i.hostid=h.hostid  where h.templateid=10465) as b on a.ip=b.ip order by b.ip desc;

根据同样的方法,可以灵活拿到自己需要的数据。

原文来自:http://www.ywnds.com/?p=8488

本文地址:https://www.linuxprobe.com/zabbix-linux.html编辑:向金平,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/