1bundle agent host_info_report
2# @brief Generates a short high level summary of the executing host information
3#
4# **Example:**
5# `cf-agent -b host_info_report`
6{
7  vars:
8    "host_info_report_template"
9      handle  => "host_info_report_vars_host_info_report_template",
10      string  => "$(this.promise_dirname)/../../templates/$(this.bundle).mustache",
11      comment => "Where the report template is found";
12
13    "host_info_report_output"
14      handle  => "host_info_report_vars_host_info_report_output",
15      string  => "$(sys.workdir)/reports/$(this.bundle).txt",
16      comment => "Where the host info report should be generated";
17
18  methods:
19    show_software::
20      "Software"
21        handle    => "host_info_report_methods_software",
22        usebundle => host_info_report_software,
23        comment   => "Collect information about software installed";
24
25    any::
26      "CFEngine"
27        handle    => "host_info_report_methods_cfengine",
28        usebundle => host_info_report_cfengine,
29        comment   => "Collect information about CFEngine";
30
31      "Render"
32        usebundle => host_info_report_render_txt,
33        comment   => "Render the host info report in plain text";
34}
35
36bundle agent host_info_report_software
37# @brief Collect information about software installed
38{
39  vars:
40      "packages"
41        data => packagesmatching(".*", ".*", ".*", ".*"),
42        comment => "Get information about all packages currently on system";
43
44      "package_names"
45        slist => getindices("packages[name]");
46
47    DEBUG::
48      "printable"
49        string => format("%S", packages);
50
51  reports:
52    DEBUG::
53      "$(printable)";
54      "$(package_names)";
55}
56
57bundle agent host_info_report_cfengine
58# @brief Collect information about CFEngine
59{
60  classes:
61    "have_masterdir_cf_promises_validated"
62      expression => fileexists("$(sys.masterdir)/cf_promises_validated"),
63      handle => "host_info_report_cfengine_classes_have_masterdir_cf_promises_validated",
64      comment => "We need to know if we have the files, because if we try to
65                  read them when they don't exist we get error messages. Look
66                  in masterdir because we are interested in the last time when
67                  policy was changed and validated (indicating when a policy
68                  release was received). ";
69
70    "have_inputdir_cf_promises_release_id"
71      expression => fileexists("$(sys.inputdir)/cf_promises_release_id"),
72      handle => "host_info_report_cfengine_classes_have_masterdir_cf_promises_release_id",
73      comment => "We need to know if we have the files, because if we try to
74                  read them when they don't exist we get error messages. Look
75                  in inputdir because we are interested in the current policy
76                  release id as determined on the policyserver, not as
77                  calculated locally.";
78
79  vars:
80      # doesn't work :( # "interface_flags" slist => maparray("$(this.k): IP $(sys.ipv4[$(this.k)]), flags $(this.v)", "sys.interface_flags");
81      "interface_flags" slist => maparray("$(this.k): $(this.v)", "sys.interface_flags");
82      "interface_ips" slist => maparray("$(this.k): IPv4 $(this.v)", "sys.ipv4");
83      "interface_info_unsorted" slist => { @(interface_flags), @(interface_ips) };
84      "interface_info" slist => sort(interface_info_unsorted, "lex");
85
86    any::
87      "cfengine_info_files"
88        handle => "host_info_report_vars_cfengine_info_files",
89        slist => { "cf_promises_validated", "cf_promises_release_id" },
90        comment => "These files are required for CFEngine related information,
91                    and if we try to read them when they don't exist we get
92                    ugly error messages";
93
94    have_masterdir_cf_promises_validated::
95      "cf_promises_validated"
96        data => readjson("$(sys.masterdir)/cf_promises_validated", 1K),
97        comment => "This contains information about the last time policy was
98                    updated and subsequently validated, it indicates when
99                    policy was last updated from the policy server.";
100
101      "cf_promises_validated_timestamp_formatted"
102        string => strftime("localtime", "%F %T %Z", $(cf_promises_validated[timestamp])),
103        comment => "It's useful to display when policy was last updated and
104                    verified, in a human readable format.";
105
106    have_inputdir_cf_promises_release_id::
107      "cf_promises_release_id"
108        data => readjson("$(sys.inputdir)/cf_promises_release_id", 1K);
109
110    any::
111      "last_agent_run"
112        string => strftime("localtime", "%F %T %Z", filestat("$(sys.workdir)/outputs/previous", "mtime"));
113
114    DEBUG::
115      "printable"
116        string => format("%S", cf_promises_release_id);
117
118  reports:
119    DEBUG::
120      "$(printable)";
121
122  reports:
123    DEBUG.have_masterdir_cf_promises_validated::
124      "I have cf_promises_validated";
125
126    DEBUG.have_inputdir_cf_promises_release_id::
127      "I have a policy release ID";
128}
129
130bundle agent host_info_report_inventory
131# @brief Collect information about policy
132{
133
134  vars:
135
136@if minimum_version(3.10)
137      "inventory_vars" data => variablesmatching_as_data( ".*", "inventory" );
138@endif
139
140}
141
142bundle agent host_info_report_render_txt
143# @brief Generates a report with the collected information
144{
145  files:
146    "$(host_info_report.host_info_report_output)"
147      create => "true",
148      edit_template => "$(host_info_report.host_info_report_template)",
149      handle => "host_info_report_files_host_info_report_output",
150      classes => scoped_classes_generic("bundle", "host_info_report_output"),
151      template_method => "mustache";
152
153  reports:
154    host_info_report_output_repaired::
155      "Host info report generated and available at '$(host_info_report.host_info_report_output)'";
156
157    host_info_report_output_not_ok::
158      "There was a problem generating your host info report at '$(host_info_report.host_info_report_output)'";
159}
160