opEvents releases after 1.1.0 include a facility to define your own templates for email notifications (ie. emails as part of an event action or because of an escalation).
The setup is very simple and requires basically just two steps:
The configuration file install/EventEmails.nmis
contains the definitions of all email templates. As shipped it includes one special template named default
, which is chosen for all email contacts without a template association, and one example for a very concise report. You can of course modify these existing templates or define your own. Here are these two example templates:
'default' => { 'subject'=> [ "event.date", ' ',"node.name", ' ', "event.event" ], 'body' => [ "Event Context:\n", "link.eventcontext", "\n\n", "Node Properties:\n","node.*","\n\n", "Event Properties:\n","event.*","\n","\n", ], }, 'veryshort' => { 'subject' => [ "node.name", ' ', "event.event" ], 'body' => [ "The event \"","event.event", "\" for host \"", "node.name", "\" occurred at ", "event.date", ".\nAll event details can be found here: ", "link.eventcontext", "\n", "All node details can be found here: ", "link.nodecontext", "\n\n", ], }, |
The syntactic rules for templates are simple but flexible:
node.XYZ
, event.ABC
and link.EFG
are treated specially, but only if they are isolated separate items.node.group
is part of a longer bit of text.node.XYZ
or event.XYZ
are replaced by the node or event property XYZ
.event.script
), then these are shown on separate lines and indented with a tab character.link.eventcontext
is replaced by a hyperlink to the event context page.link.nodecontext
creates a hyperlink to the node context page.opevents_url_base
in opCommon.nmis
to set an appropriate schema and hostname for the hyperlink. if this setting is missing you'll see http://localhost/
in the created hyperlinks.node.*
are translated into a list of all "standard summary" node properties, which are defined in opCommon.nmis
, key opevents_gui_event_node_summary_list
.event.*
works similarly, but for event properties and is not restricted to a default set. It also creates a trailing newline.node.*
and event.*
are disabled in the subject template, because that must contain just a single line of text. You also must not create multiple lines of text in the subject template (using "\n").The configuration file Contacts.nmis
contains the list of (email) contacts, and needs to be adjusted if you want templates other than default
to be used. The example file as shipped shows where the email template is set:
'contact1' => { 'Contact' => 'Contact1', ... 'Email' => 'nobody@localhost', 'EmailTemplate' => 'default', |
Simply change the value after EmailTemplate
to the name of your desired template. If opEvents cannot find the named template, or if no EmailTemplate
setting is present, then the default
template will be used. If that template doesn't exist or work, then you will receive your emails formatted with a hardcoded fallback template that includes a warning notice at the top.