One apply service having 2 Host config vars

As a part of docker app monitoring effort, I want to implement it for the docker app status “docker ps” and monitor the ports using “nc”

The hosts running the docker apps have ‘vars’ for app names (array) and app ports (array ).

Is it possible to have one “apply Service” and run 2 check commands to for each app and each using 2 different ‘for’ loops?

Please advise,
Thanks

Hello @monigacom!

Please give an example config.

Best,
A/K

Here is an example host config

object Host “dockerhost” {
import “generic-linux-host”

display_name = “dockerhost”
address = “xx.xx.xx.xxx”
vars.app = [“docker-app1”, “docker-app2”]
vars.tcp_ports = [8000,8001]
vars.location = “DC”
}

I don’t know if one can have multiple “check_command” in one “apply Service” object to be able to run against different vars.app?

Thanks

How are apps and ports related? First => first and second => second? Or by cartesian product?

They goes by cartesian product.

Does this apply to all such hosts?

Yes all those hosts who have the vars.app starting with “docker”

With

cartesianDocker = function(host) {
  if (!(host.vars.app && host.vars.tcp_ports)) {
    return { }
  }
  var ret = { }
  for (a in host.vars.app) {
    for (tp in host.vars.tcp_ports) {
      ret[a+":"+tp] = { app = a; port = tp }
    }
  }
  return ret
}

you can do the following:

apply Service "" for (svc_name => opts in cartesianDocker(host)) { ...

Thank you @Al2Klimov