I’m trying to build a command that checks multiple ports on multiple hosts. The command I’m trying to use is the ‘check_tcp’ command and trying to run it on custom variables (both the ports and hosts) that are setup as an array. Here is an example of how the command is currently running:
./check_tcp -H host1 host2 -p port1 port2
How I ideally want it to run is for it to cycle through each host in the array and each port, like so:
./check_tcp -H host1 -p port1
./check_tcp -H host1 -p port2
./check_tcp -H host2 -p port1
./check_tcp -H host2 -p port2
Has anyone encounter this issue had found a way to setup a service and command to do this?
I would use a thin wrapper around the check_tcp that takes your array and launches the various needed check_tcp commands and reports back the collected results. A check_tcp_multiple so to say.
You will need a bit play with script … like storing nagios exit code in list and try go trough this list and so but this should be nice template and direction where to start.
you import your check_tcp and add $config$ as a port like in the description of the “apply for” field
Evaluates the apply for rule for all objects with the custom attribute specified. E.g selecting “host.vars.custom_attr” will generate “for (config in host.vars.array_var)” where “config” will be accessible through “$config$”. NOTE: only custom variables of type “Array” are eligible.