CFEngine: easy classification of mail reports
  2014-07-03

Once you have started to manage tens of servers with CFEngine (great!), if you stick to mail reports you will quickly become overwhelmed. To classify them more easily, here is a trick with CFEngine-3.6.

By default the subject is [fqdn/ip], for example (mail headers)

Subject: [debian70.boring/192.168.1.110]

Not very easy to filter them through your email client (in case you don’t/can’t use a powerful MDA like procmail) without clashing with others similar subjects.

Here comes the mailsubject option of cf-execd, which allows you to set your own mail subject through body executor control. The cf-execd configuration lies in the /var/cfengine/inputs/controls/cf_execd.cf file.

Example from the documentation:

 body executor control
    {
        mailsubject => "CFEngine report ($(sys.fqhost))";
    }

Which gives (mail headers):

Subject: CFEngine report (debian70.boring)

Easier to filter, easy to customize with all the CFEngine variables available, and a little undocumented bonus, an extra X-CFEngine: mail header is added when this option is set:

X-CFEngine: vfqhost="debian71.boring";ip-addresses="127.0.0.1 192.168.1.111 fe80::a00:24fe:9eab:77ba";policyhub="192.168.1.110";..."

But this time, no way to customize it.

There is a pull request to add this header even if mailsubject option is not set, if you are interested in, please add a comment to the GitHub entry!

Latest extra, the corresponding procmail rule:

:0:
* ^X-CFEngine:
Servers/

Reporting through mail becomes more inefficient with the increase of managed servers. Consider logging through Syslog for better scalability, here is a great post about it.