we have a bunch of mounts on a bunch of servers. Mounts are numbered (/mnt/mount01 … /mnt/mount80).
I need to monitor them, but don’t want to define all the mounts by hand. I was hoping for a bash-like function like "for MOUNT in {00 … 80}; do “create service”; done. Or similar…
I do not use the director, plain config files. Meanwhile, I tried to solve this by using ansible. And while it is fun to learn ansible and stuff, your idea to just have one check script that just checks everything is maybe easier.
for (mount in range(10)) {
object Service "mount-" + mount use (mount) {
vars.mount = "/mnt/mount" + mount
[...]
}
}
Or alternatively:
apply Service "mount-" for (mount in range(10)) {
vars.mount = "/mnt/mount" + mount
assign where [...]
}
The latter makes for sense if you use the same apply rule for many hosts (you can also access host vars instead of hard-coding a number like 10 in the example.
This looks like the ansible approach I’m working on. My issue here:
every server has an unknown number of NFS Servers
every server has an unknown number of mounts from each of that servers
every mountpoint has a format of 4 digits (0001 - 0020) - that means i need someting like format %4d
unknown means they are not equal everywhere and could change over time. But they are known of course and I could put some “vars.nfsserver=server1”
apply Service "NFS Server Stale " for (nfs-server in host.vars.nfs-servers) {
/* another for loop for mountpoints per server
for (mount in range(host.vars.nfs-mount-min,host.vars.nfs-mount.max)) {
check_command = "nfs-stale"
vars.nfs_path = "/mnt/"+nfs-server+mount
}
assign where vars.nfs-servers
}
So, the big question: how to put a loop into a loop?
apply Service "NFS-SERVER1 NFS Stale " for (MOUNT in range(format("%04d",host.vars.nfs-server1_min),format("%04d",host.vars.nfs-server1_max))) {
import "generic-service"
command_endpoint = host.vars.agent_endpoint
vars.grafana_graph_disable = true
check_command = "nfs-stale"
vars.nfs_path="/mnt/NFS-SERVER1/" + MOUNT
assign where host.vars.nfs-servers
}
It worked - kind of. Issue is the leading zeros. Whatever I put in vars.nfs-server1_min, leading zeros get stripped off. But I need it in a format of 4 digits. Thats why I’m testing the format.