#if-#endif
You can customize config files by means of the #if, #elif, #else & #endif preprocessing directives.
For example, in alerts.cfg, for the EMERGENCY alert, you might set different timings, nice levels, and alarm lists for the piktmaster, missioncritical, and dbserver systems:
EMERGENCY #if missioncritical | piktmaster timing */5 * * * * 1 #else timing */10 * * * 1-5 1 timing 0 * * * 0,6 1 #endif #if ! piktmaster nicecmd "=nice -n 19" #endif mailcmd "=mailx -a 'From: piktadmin' -s 'PIKT Alert on =pikthostname: EMERGENCY' =pikt-emergency" lpcmd "=lp =piktprinter" status active level emergency alarms #if piktmaster SysDown #endif #if missioncritical LoadAverage ProcessCounts ZombieCounts CPUUsage #else // any of these issues on non mission-critical // systems is never considered an emergency #endif #if dbserver & ! ( dbtest1 | dbtest2 ) DatabaseDown #endifAs another example, in alarms.cfg, for the CPUUsage alarm script, you might adjust the 'input proc' for different behaviors of the top command on different flavors of Linux, also 'output mail' more frequently on missioncritical systems than others:
CPUUsage init status =piktstatus level =piktlevel task "Report unusually high CPU usage" #if gentoo | suse input proc "=cat =hstdir/log/top.CPUUsage 2>/dev/null | =head -n 3 | =tail -n 1" dat $ky 1 // invariant key, "Cpu(s):" dat #cpuid 8 #elsif redhat input proc "=cat =hstdir/log/top.CPUUsage 2>/dev/null | =head -n 5 | =tail -n 1" dat $ky 1 // invariant key, "CPU0" dat #cpuid $-1 #endif keys $ky begin doexec wait "=top -b -n1 -d1 2>/dev/null > =hstdir/log/top.CPUUsage" ... rule // report unusually high cpu usage if #cpuid <= #cpuidlim #if missioncritical =hourly(output mail $inlin set #dotopps = #true(), ) #else =periodically(output mail $inlin set #dotopps = #true(), , 240) #endif endif ...As a final example, in objects.cfg, you might enclose entire #include files within #if ... #endif:
Checksums #include <objects/adm/checksums_piktbin_objects.cfg> #if redhat # include <objects/adm/checksums_redhat_linux_objects.cfg> #elif suse # include <objects/adm/checksums_suse_linux_objects.cfg> #endifIn any of the config files (except systems.cfg, where #if, #endif, etc. are now allowed), the format is
#if <machine class> <lines> [optional] #elif <machine class> [optional] [or: #elsif, #elseif] <lines> [optional] #else [optional] <lines> [optional] #endif [or: #fi]where <machine class> can be a series of host names, host aliases, or host groups, separated by either the |, &, or ! set operators. | indicates set union, & set conjunction, and ! set complement. You can also use parentheses, ( and ), in the class specifications.
#elsif and #elseif are alternate forms of #elif, and #fi is interchangeable with #endif.
Rather than #if, #elif, #else, and #endif, you may instead use their synonyms #ifsys, #elifsys, #elsesys, and #endifsys if you prefer. You may freely intermix these alternate forms, but for clarity's sake, it's probably best not to (for example, don't use #if-#endifsys, or #ifsys-#else-#endif).
You can nest #if-#endif's up to sixty four levels deep.
Refer to the Samples section for many more examples.
prev page | 1st page | next page |