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
Al2Klimov
(Grandmaster)
May 4, 2022, 8:54am
2
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
Al2Klimov
(Grandmaster)
May 5, 2022, 8:33am
4
How are apps and ports related? First => first and second => second? Or by cartesian product?
They goes by cartesian product.
Al2Klimov
(Grandmaster)
May 5, 2022, 2:55pm
6
Does this apply to all such hosts?
Yes all those hosts who have the vars.app starting with “docker”
Al2Klimov
(Grandmaster)
May 5, 2022, 4:24pm
8
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)) { ...