It is a way to define some proper subjet? The documentation about that is not very clear to me:
body executor control { mailsubject => "CFEngine report ($(sys.fqhost))"; }
Where should i write this code?
Hi Jerome,
TL;DR
Create a def.json at the root of your policy set and define default:def.control_executor_mailsubject.
{ "variables": { "default:def.control_executor_mailsubject": { "value": "CFEngine output from $(sys.fqhost)" } } }
The rest of the story:
When a cfengine agent runs, it is going to do some system discovery to understand the environment (basically sys vars and hard classes). Then it's going to process Augments (https://docs.cfengine.com/docs/3.24/reference-language-concepts-augments.html). First, $(sys.workdir)/data/host_specific.json if it exists, then $(sys.policy_entry_dirname)/def_preferred.json or $(sys.policy_entry_dirname)/def.json if they exist and then other supplemental augments as specified by the augments key.
Then it's going to start parsing policy starting with the first policy file read $(sys.policy_entry_filename) which defaults to promises.cf and other policy files are parsed as they are discovered based on the presence of the inputs defined (which may have been extended by Augments via the inputs key).
The setting you are talking about, for mailsubject lives in body executor control, you will find it within the policy framework in controls/cf_execd.cf
Looking at this file you will find it looks like this:
cfengine_internal_agent_email.!cfengine_internal_disable_agent_email:: mailto => "$(def.mailto)"; mailfrom => "$(def.mailfrom)"; smtpserver => "$(def.smtpserver)"; mailmaxlines => "$(default:def.control_executor_mailmaxlines)"; control_executor_mailsubject_configured.cfengine_internal_agent_email.!cfengine_internal_disable_agent_email:: mailsubject => "$(default:def.control_executor_mailsubject)"; control_executor_mailfilter_exclude_configured.cfengine_internal_agent_email.!cfengine_internal_disable_agent_email:: mailfilter_exclude => { "@(default:def.control_executor_mailfilter_exclude)" }; control_executor_mailfilter_include_configured.cfengine_internal_agent_email.!cfengine_internal_disable_agent_email:: mailfilter_include => { "@(default:def.control_executor_mailfilter_include)" };
Notice that mailsubject here has a value of $(default:def.control_executor_mailsubject). This tells us that the value is defined in the default namespace (see more about namespaces here https://docs.cfengine.com/docs/3.24/reference-language-concepts-namespaces.html), in the def bundle scope, in the variable control_executor_mailsubject.
We can leverage Augments to define that variable, as mentioned in the docs for configuring the subject for emails sent by cf-execd (https://docs.cfengine.com/docs/3.24/reference-masterfiles-policy-framework.html#configure-subject-for-emails-sent-by-cf-execd).
{ "variables": { "default:def.control_executor_mailsubject": { "value": "CFEngine output from $(sys.fqhost)" } } }