简体   繁体   English

在icinga2中将依赖项应用于服务

[英]Applying a dependency to a service in icinga2

We are using icinga2 for monitoring. 我们正在使用icinga2进行监控。 We have a lot service checks which are applied dynamically through apply rules. 我们有很多服务检查,这些检查通过应用规则动态地应用。 Additionally, these are services applied to a hashmap of database instances which are on various hosts. 此外,这些服务适用于各种主机上的数据库实例的哈希图。 The long and the short of it is that our service names are determined dynamically so one might be, for example HOST!DBNAME-svcvheck . 总而言之,我们的服务名称是动态确定的,因此可以这样确定,例如HOST!DBNAME-svcvheck

So the scenario is that most of these services depend on a database is up, eg, `HOST!DBNAME-tnsping". Unfortunately, the documentation examples are fairly simple and don't include dynamically creating a parent service reference. What I think I want to do is something like this: 所以情况是,这些服务大多依赖于数据库中了,比如:`HOST!DBNAME-TNSPING。”不幸的是, 文件的例子是相当简单的,不会动态包括创建父服务的参考。我觉得我是什么想做的是这样的:

apply Dependency "db-connectivity" to Service {
  parent_service_name = "$host.name$!$service.vars.envname$-tnsping"
  # also tried variants of this, e.g.
  # parent_service_name = host.name + "!" + service.vars.envname + "-tnsping"
  child_service_name = service.name
  child_host_name = host.name
  disable_checks = true
  assign where "oracle-db-svc" in service.templates
}

The host doesn't really matter in my case because the dependencies are only the services but the child_host_name is a required field. 在我的情况下,主机并不重要,因为依赖项仅是服务,而child_host_name是必填字段。

No matter what I do I can't seem to get it to recognize the parent service. 不管我做什么,我似乎都无法识别父服务。 For example: 例如:

Error: Dependency 'scan-szepdb041x.myhost.org!UAT2-beqfilelast!db-connectivity' references a parent host/service which doesn't exist.

The rules for referencing other object variables while applying a Dependency seem a bit different from applying a Service. 在应用Dependency时引用其他对象变量的规则似乎与应用服务有些不同。

Does anyone have any ideas or examples of dynamically apply service dependencies to services which were generated dynamically? 是否有人对将服务依赖项动态应用于动态生成的服务有任何想法或示例?

you probably have to loop over existing hosts and see if they match. 您可能必须遍历现有主机,然后查看它们是否匹配。 Then you define dependency inside of a loop. 然后,您可以在循环内定义依赖项。

I had a similar example for dynamically generating disk checks. 我有一个类似的示例,用于动态生成磁盘检查。 If i find it, i'll post it here in a few days. 如果找到它,我会在几天后将其发布在这里。

Not sure if that is possible with dependencies, but I'll see. 不确定依赖项是否可行,但是我会看到的。

edit: see if somethig like that will be enough to get you started: 编辑:看看这样的东西是否足以让您入门:

for (server in get_objects(Host)) {
        if (match("somename*", server.name)) {
                apply Dependency "db-connectivity" + server.name to Service use (server) {
                        parent_service_name = server.name + service.vars.envvname + "-tnsping"
                        child_service_name = service.name
                        child_host_name = host.name
                        disable_checks = true
                        assign where "oracle-db-svc" in service.templates
                }
        }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM