Icinga2:获取服务或主机变量中其他服务的状态

问题描述

google 不再是我的朋友了。 我尝试了很多东西,但没有任何效果..

我已经构建了这个全局函数: 首先,我正在寻找带有主机变量“vars.adminhost”的所有主机,并获取这些主机的 IP 地址:

globals.get_host_status = function(host_group) {
  var addresses = []
  var hostid = []
  var stati = 0
  var res = ""
  var check_name = "check-host-Login"
  for(h in get_objects(Host)){
        if(h.vars.adminhost){
         addresses.add(h.address)
        }
  }

然后我正在寻找主机 ID(在 icinga2 中如何调用它们):

  for(o in addresses){
        for(h in get_objects(Host)){
                if(h.address == o){
                        hostid.add(h.name)
                }
        }
  }

这两部分工作完美 现在的问题: 我想在不同服务的服务变量中写入主机上的“检查主机登录”服务的状态: 所以我试过这个:

for(name in hostid){
        stati = get_service(name,check_name).state
        res.add(stati)
        }
  return res
}

在 Icinga2 控制台中,我得到了正确的输出The states will be correctly displayed 在 icingaweb2 中,变量为空: Empty Variable in icingaweb2 在控制台中,服务的变量是一个双空列表: double null in console

我在对象服务中定义变量:

vars.test = get_host_status("ADMIN-HOST")

我不知道为什么 icingaweb2/icinga2 中的变量为空。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)