Assign service if file exists

Hi all,

I’ve a pacemaker cluster where various haproxy daemons are running, each of them has ists own admin.sock file. The admin.sock file exists sometimes on server A and sometimes on server B.

I try to combine the “assigne where” rule with the check of the existense of the admin.sock file but havn’t find any example.

apply Service "Haproxy: stats" {
  import "generic-service"
  check_command = "haproxy_status"

  vars.haproxy_status_socket = "/run/haproxy/msx/admin.sock"
  vars.haproxy_status_default = "d,1,2,,"

  command_endpoint = host.name
  assign where match ("deblb*", host.name) and ??? haproxy_status_socket exists???
}

Do you have an idea?

Regards
Stephan

I’d create services that checks whether this file is existing or not. And add the check result to the assign rule.

Ok, I’ve created an new service:

apply Service "file_age: " for (file_age => config in host.vars.file_age) {
  import "generic-service"
  check_command = "file_age"
  command_endpoint = host.name

  vars += config

  assign where match ("deblb1*", host.name)
  assign where match ("deblb2*", host.name)
}

and have in the hosts file the following variables:

  vars.file_age["msx/admin.sock"] = {
    file_age_file = "/run/haproxy/msx/admin.sock"
    file_age_warning_time = "0"
    file_age_critical_time = "0"
  }

  vars.file_age["ncl/admin.sock"] = {
    file_age_file = "/run/haproxy/ncl/admin.sock"
    file_age_warning_time = "0"
    file_age_critical_time = "0"
  }

This works but how can I add the results in the assign rule?

I’m sorry, this was not a good idea since you would need a reload when the cluster changes.

A better idea is to keep the new checks and use their results in the existing check. If the new check reports admin.sock does not exist (you can get the result with get_objects), it overwrites its check result with e.g. “OK - haproxy inactive”.

I’m sorry I’ve no idea how to use the results of the file_age check in the haproxy_status check. I havn’t found any “assign where” rule examples which are using check results in the docs.

To handle the absence of one paticular socket file is a second step - I want to understand how the system works if the sockets are there.

As I mentioned using assign rules would need a reload to make the changes active.

Here is an example to rely on check results.