1#
2# Make list of hosts available to all clients, and use it on clients
3# in order to configure a sample monitoring application that checks
4# health of all clients.
5#
6# Sample application configuration file contents below, put this in
7# /var/cfengine/masterfiles/template_monitoring on the hub.
8#
9# ---
10#
11#monitor_hosts = $(orchestration_hostlist_use.host_string)
12#
13# ---
14#
15# Note that your copy_from statement in failsafe.cf or update.cf must
16# copy this file also (e.g. not only copy *.cf files in any file_select)
17
18
19
20body common control
21{
22      inputs => { "$(sys.libdir)/stdlib.cf" };
23      bundlesequence => { "orchestration_hostlist_update",  "orchestration_hostlist_use"};
24}
25
26
27bundle agent orchestration_hostlist_update
28{
29  vars:
30    am_policy_hub::
31      "host_list" slist => hostsseen("inf", "lastseen", "address");
32
33  files:
34
35    am_policy_hub::
36      "$(sys.workdir)/masterfiles/host_list"
37      comment       => "Write the addresses of all hosts to a file",
38      handle        => "orchestration_hostlit_update_files_host_list_write",
39      edit_line     => insert_lines( "@(orchestration_hostlist_update.host_list)" ),
40      create        => "true",
41      edit_defaults => empty;
42}
43
44
45bundle agent orchestration_hostlist_use
46{
47  vars:
48      "host_list"    slist => readstringlist("$(sys.workdir)/inputs/host_list", "#.*", "\n", 1000, 40000);
49      "host_string" string => join(", ", "host_list");
50
51  files:
52      "/tmp/monitoring"
53      comment       => "Update application configuration to reflect all hosts on this hub",
54      handle        => "orchestration_read_files_host_list_configuration",
55      edit_line     => expand_template("$(sys.workdir)/inputs/template_monitoring"),
56      create        => "true",
57      edit_defaults => empty;
58}
59