Reporting on custom inventory

Custom data from the hosts can be collected and reported on in the CFEngine Enterprise hub. For example, you can easily create custom inventory reports on the status or configuration of hardware. The inventory reporting interface in CFEngine Enterprise is easy to use and does not require any technical knowledge. System administrators can ensure CFEngine collects any relevant custom inventory, while non-technical users can easily consume this information in a self-service manner using the CFEngine Enterprise Inventory reporting interface.

 

1. Create the policy to collect the Inventory

An inventory attribute is either a string, list or class in the CFEngine language. Simply create one of these language constructs; we will use a string in this example.

vars:
     "system_uuid"
       string => execresult("/usr/sbin/dmidecode -s system-uuid", "useshell"),
       meta => { "inventory", "attribute_name=System UUID" };

Save this policy snippet somewhere in the policy. We recommend that you use the common def bundle in masterfiles/def.cf.

The only difference from this variable versus any other variable in the CFEngine policy is the meta attribute. In meta, we simply tell CFEngine that this is an inventor attribute to be collected to the hub and give it a friendly name for the reporting interface. However, please note that if you make inventory from classes, you need to make sure that they are in the namespace scope.

 

2. Report on the new Inventory in the CFEngine Enterprise UI

After about 15 minutes, you will see the new inventory attribute in the CFEngine Enterprise Mission Portal UI, under Reports -> Inventory and you can easily report on it as any other inventory attribute.

 

inventory-adding-system-uuid

 

inventory-report-system-uuid

3. Conclusion

Now that your new custom inventory attribute is defined in your policy, it is collected from all hosts and available to all your users to report on! You can save reports, filter, export and email — just like any other inventory attribute!

As a next step, you might want to look at creating an alert of type inventory to visualize and get notified if your new inventory ends up in an undesired state, such as a hardware failure.
You can learn more in the tutorial on how to create an alert – use the Inventory type of alert.