Mail Macros
[posted 2001/06/07]
Recently, we had an episode where, due to some NIS failures, also a downage of our GNU Mailman list server, some crucial PIKT alert e-mail was not delivered in a timely fashion.
We had configured our mail macros, in macros.cfg, this way (which should be familiar to you if you've ever looked closely at the configs_samples):
// pikt-emergency, for example, is an NIS alias set to various sysadmins; // we could make such addresses PIKT macros, i suppose brahms brahms\ bach bach\ bruch bruch\ liszt liszt\ schubert franz.schubert\ // for emergency alerts (and similarly, for all following), if we have // #define'd test (we are running in test mode), send alerts to brahms, else // if the current host is a newsys or a testsys, send alerts to brahms, else // if the current host is a db (phd) machine, send alerts to the // pikt-emergency addressees (the unix sysadmins) and also the pikt-db // (pikt-phd) addressees (the dbadmins (the phdadmins)), else for all other // machines just send to the pikt-emergency addressees (the unix sysadmins) # ifdef test piktemergency =brahms # elsedef piktemergency # if newsys | testsys =brahms # else # if phd pikt-emergency // pikt-phd # elif db pikt-emergency pikt-db # else pikt-emergency # endif # endif # endifdef # ifdef test pikturgent =brahms # elsedef pikturgent ... [much more of the same]
Then, as the first comment above indicates, we set the various pikt NIS aliases in a separate /etc/NIS/aliases file on our NIS server:
# these are pikt aliases pikt-admin: pikt-test: pikt-debug: pikt-emergency: , pikt-urgent: pikt-critical: #pikt-emergency: #pikt-urgent: #pikt-critical: pikt-warning: pikt-notice: , pikt-info: , pikt-security: , pikt-db: , , , #pikt-db:
If we had this mailcmd statement in alerts.cfg
mailcmd "=mailx -s 'PIKT Alert on =pikthostname: EMERGENCY' =piktemergency"
=piktemergency might resolve to pikt-emergency in piktd.conf like this
10,25,40,55 * * * * 5 /usr/bin/nice --5 /pikt/bin/pikt +M "/usr/bin/mailx -s 'PIKT Alert on vienna: EMERGENCY' pikt-emergency" +L "/bin/lp -d w309ps" +A EMERGENCY
where pikt-emergency is an NIS alias resolving to
,
where systems was a GNU Mailman mailing list.
Confusing, no? Moreover, there are at least two points of failure there: NIS, and GNU Mailman. Furthermore, I found myself constantly fiddling with the NIS aliases file (which is not yet under PIKT management), commenting and uncommenting and changing entries, then remaking the NIS alias map.
There had to be a better way, and of course there is. This is how we now do it:
// try to use actual addresses, not NIS aliases or references to GNU Mailman // lists, just in case of NIS or GNU Mailman breakdown // systems brahms brahms\ // johannes.brahms\ bach bach\ // johann.bach\egbdf bruch bruch\ // max.bruch\ liszt liszt\ // franz.liszt\ purcell purcell\ // henry.purcell\ systems =brahms =bach =bruch =liszt =purcell piktadmin =brahms // pikt head honcho // dbas leoncavallo leoncavallo\ // ruggero.leoncavallo\ smetana smetana\ // bedrich.smetana\ borodin borodin\ // alexander.borodin\ // dba emeritus schubert schubert\ // franz.schubert\ dbas =leoncavallo =smetana =borodin dbadmin =leoncavallo // dba head honcho // the various pikt- macros, the addresses that the alerts.cfg mailcmd sends to pikt-admin =piktadmin pikt-debug =piktadmin pikt-test =piktadmin #ifndef test # if ! ( newsys | testsys ) pikt-emergency =systems # if db =dbas # endif pikt-urgent =systems # if db =dbadmin # if milan =borodin # endif # endif pikt-critical =systems # if athens2 | athens4 =dbadmin # endif pikt-warning =systems # if athens2 | athens4 =dbadmin # endif pikt-notice =brahms =bach =bruch pikt-info =brahms =bach =bruch pikt-security =systems pikt-db =dbas # else // ! ( newsys | testsys ) pikt-emergency =piktadmin pikt-urgent =piktadmin pikt-critical =piktadmin pikt-warning =piktadmin pikt-notice =piktadmin pikt-info =piktadmin pikt-security =piktadmin pikt-db =piktadmin # endif // ! ( newsys | testsys ) #elsedef // test pikt-emergency =piktadmin pikt-urgent =piktadmin pikt-critical =piktadmin pikt-warning =piktadmin pikt-notice =piktadmin pikt-info =piktadmin pikt-security =piktadmin pikt-db =piktadmin #endifdef // test
The mailcmd statement in alerts.cfg is now
mailcmd "=mailx -s 'PIKT Alert on =pikthostname: EMERGENCY' =pikt-emergency"
(See the slight difference? =piktemergency was changed to (hyphenated) =pikt-emergency.)
=pikt-emergency might resolve, on vienna, in piktd.conf like this
10,25,40,55 * * * * 5 /usr/bin/nice --5 /pikt/bin/pikt +M "/usr/bin/mailx -s 'PIKT Alert on vienna: EMERGENCY' brahms\ bach\ bruch\ liszt\ purcell\" +L "/bin/lp -d w309ps" +A EMERGENCY
On the athens2 machine, =pikt-emergency would add the appropriate addresses:
10,25,40,55 * * * * 5 /usr/bin/nice --5 /pikt/bin/pikt +M "/usr/bin/mailx -s 'PIKT Alert on athens2: EMERGENCY' brahms\ bach\ bruch\ liszt\ purcell\ leoncavallo\ smetana\ borodin\" +L "/bin/lp -d w309ps" +A EMERGENCY
The new advantages:
- piktd.conf now routes alert e-mail directly to the appropriate mailboxes, not indirectly through NIS and GNU Mailman, thereby removing two potential points of failure.
- We no longer have to worry about maintaining pikt aliases in the NIS aliases file (they have all been removed).
- For PIKT purposes, we no longer have to worry about maintaining the correct GNU Mailman list memberships.
- The mail macros setup in the new macros.cfg is, I think, easier to understand and maintain than the old.
- I can easily slip into test mode everywhere (with all alert e-mail going to =piktadmin, i.e., =brahms, i.e., me) simply with
# piktc -erv +D test +H all
Before, I would have to edit and remake the NIS aliases maps. Now, I can manage everything in the PIKT config and with the appropriate piktc commands.
In short, we now have a much more reliable and maintainable setup than previously.
In your setup, maybe this sort of sophistication and complexity is overkill. Okay, but at least you have the choice to Have It Your Way. I have demonstrated two radically different ways of organizing the alert e-mail addresses. Maybe Your Way is radically simpler, or radically different in some other complex way. As always, PIKT gives you choice.
For more examples, see Developer's Notes.