defines.cfg
In this sample defines.cfg, we specify a set of logical "defines"--preprocessor conditional switches for including or excluding sections of the configuration files.
You use these defines together with the '#ifdef <define>' preprocessor directive to customize your PIKT configurations according to certain conditions--those you specify directly, or conditions based on the current system or network state.
/////////////////////////////////////////////////////////////////////////////// // // PIKT defines.cfg -- preprocessor logical switches // /////////////////////////////////////////////////////////////////////////////// // // in this file, you must declare all preprocessor defines // // setting a define entails listing an identifier in the left-most column // of this file, then, on the same line or on any indented followup line, // specifying either 1 or TRUE or YES or ON // // unsetting a define entails listing an identifier in the left-most column // followed by either 0 or FALSE or NO or OFF // // so, for example, // // debug TRUE // or 1 or YES or ON // // declares and sets the "debug" define (logical flag or switch) and // // debug FALSE // or 0 or NO or OFF // // declares and unsets the "debug" define // // then, in any subsequent configuration file (macros.cfg, alerts.cfg, // alarms.cfg, programs.cfg, objects.cfg), you can wrap any of the new // define preprocessor directives (#ifdef, #ifndef, #elifdef, #elifndef, // #endifdef, ...) around config file lines, and include/exclude them at will // // for example, you might have // // #ifdef debug // output mail "<blah blah blah>" // debug message // #endifdef // // listing a define in this defines.cfg file sets or unsets that define; // you can override a define setting in two ways: either (a) by using // the #def(ine) or #undef(ine) preprocessor directives later on in the // config files, or (b) by adding -/+D <def> to your piktc command line // // so, if you have the following in this defines.cfg file // // debug FALSE // // you have set debug to FALSE (i.e., undefined it); you can override this // at the command line by, e.g., // // piktc -iv +D debug +A all +P all +F all +O all ... // // or by adding the following line anywhere following in the config files: // // #define debug // // you can turn this example define on and off at will throughout the // config files by a succession of suitable preprocessor statements: // // ... // #define debug // sets debug to TRUE // ... // #undefine debug // unsets debug, i.e., sets debug to FALSE // ... // #def debug // alternate form of "#define" // ... // #undef debug // alternate form of "#undefine" // ... // // #def(ine) and #undef(ine) statements have global effect; that is, if // you set (or unset) a define in one file, it remains set (or unset) // through the remainder of that file and on into the next (unless or until // you change its setting by a new #def(ine) or #undef(ine) directive) // // #def(ine) and #undef(ine) statements in the config files have the // highest priority, and command-line defines/undefines override any // settings in the defines.cfg file // // if you #def(ine) or #undef(ine) an identifier in a config file, else // use -/+D <identifier> at the command line, without first declaring that // identifier in defines.cfg, that will generate an error // // per-machine #if directives take precedence over define directives; // so, for example, // // #if linux // [ aaa ... ] // #ifdef paranoid // [ bbb ... ] // #endifdef // [ ccc ... ] // #endif // // would have the aaa, bbb & ccc stuff appear only on linux machines, and // the bbb stuff only if paranoid is set (defined); on the other hand, // with // // #ifdef paranoid // [ aaa ... ] // #if linux // [ bbb ... ] // #endif // [ ccc ... ] // #endifdef // // the aaa & ccc stuff would appear on all machines, if paranoid is set, // while the bbb stuff would appear only on linux machines with paranoid // defined // // this, however, would lead to error on non-linux systems: // // #ifdef paranoid // [ aaa ... ] // #if linux // [ bbb ... ] // #endifdef // [ ccc ... ] // #endif // // because there would be no concluding #endifdef on those machines // // observe that you can set/unset defines on a per-machine basis in the // defines.cfg file, for example // // #if mailserver // secure TRUE // #else // secure FALSE // #endif // // or, alternatively and equivalently, // // secure // #if mailserver // TRUE // #else // FALSE // #endif // // finally, remember that use of defines is entirely optional; it is not // even necessary to have any defines.cfg file at all (although if you // use -/+D or #def or ... elsewhere without a defines.cfg, this too will // generate an error) // /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// test FALSE // set to TRUE when we want to run PIKT in test // mode (e.g., after a major program revision), // or when we are testing a new alarm/script /////////////////////////////////////////////////////////////////////////////// private #if new TRUE // set to TRUE if we want to keep all PIKT messaging // private, sending only to the piktadmin #else FALSE #endif /////////////////////////////////////////////////////////////////////////////// silence FALSE // set to TRUE if we want to mute all PIKT messaging, // send all pikt messages to /dev/null /////////////////////////////////////////////////////////////////////////////// debug #if test TRUE #else FALSE // by default, don't run any debug code #endif /////////////////////////////////////////////////////////////////////////////// doexec #if new FALSE // if FALSE, don't exec any commands or take any // actions that might change anything; output // messages (logs, etc.) or take other innocuous // actions only; you might unset doexec if you are // checking out PIKT for the first time and want // to proceed cautiously, or if you have just // set up PIKT on a new machine and want to check // out the config for that machine first #else TRUE #endif //#setdef doexec = FALSE // general override; no exec for now /////////////////////////////////////////////////////////////////////////////// verbose #if new TRUE // if TRUE, output mail about routine execs, such as // "deleting <this>" or "truncating <that>"; usually // set this to FALSE; but occasionally set this to // TRUE to get a fuller report of all that PIKT is // doing silently, behind-the-scenes #else FALSE #endif /////////////////////////////////////////////////////////////////////////////// stifle #if missioncritical | systems | new FALSE // by default, limit how often certain relatively // unimportant warnings get sent; from time to time, // undefine stifle so that we may get a complete set // of warnings; note that, in the sample alarms.cfg, // one technique for stifling messages is by // comparing a current value with a history value // (e.g., #cap > %cap); we have not wrapped // '#ifdef stifle' around all such constructs; doing // so is left as an exercise for the reader #else TRUE #endif /////////////////////////////////////////////////////////////////////////////// quiet FALSE /////////////////////////////////////////////////////////////////////////////// setup FALSE // if we are doing initial setup /////////////////////////////////////////////////////////////////////////////// scripts FALSE /////////////////////////////////////////////////////////////////////////////// holiday FALSE // are we in a holiday period (e.g., xmas)? // set this to TRUE when entering a holiday period, // then re-enable all alerts to set up special // restricted holiday schedule; after the holiday, // set back to FALSE, then re-enable (hence reschedule) // all alerts /////////////////////////////////////////////////////////////////////////////// deftmp FALSE // for saving global define value temporarily deftmp1 FALSE deftmp2 FALSE deftmp3 FALSE deftmp4 FALSE deftmp5 FALSE deftmp6 FALSE deftmp7 FALSE deftmp8 FALSE deftmp9 FALSE deftmp10 FALSE /////////////////////////////////////////////////////////////////////////////// dst // TRUE if Daylight Savings Time now applies, // FALSE otherwise // at our site, `date +%Z` returns "CDT" if DST is in // effect, "CST" otherwise; substitute your own time // zone string as needed #verbatim <defines/dst_defines.cfg> [if [ `date +%Z` = "CDT" ]; then echo TRUE; else echo FALSE; fi] /////////////////////////////////////////////////////////////////////////////// #include <defines/security_defines.cfg> /////////////////////////////////////////////////////////////////////////////// page #if new FALSE // keep silent #else TRUE // issue pages #endif //#pexec "/dev/null" [if =wednesday =mailmsg1(review the defines.cfg:page setting, REMINDER, =piktadmin) fi] #ifdef pikttest # setdef page = FALSE //#elsifdef test //# setdef page = FALSE #endifdef #ifdef paranoid # setdef page = TRUE #endifdef #setdef page = FALSE // general override; no paging for now ///////////////////////////////////////////////////////////////////////////////
(A note about page layout: In the interest of readability, we have added artificial line wraps in many examples. Even though displayed here broken up across several screen lines, in general quoted strings, preprocessor directives, macro definitions, .log & .conf entries, and so on should all be unbroken on a single line.)
For more examples, see Samples.