Paging
[posted 2001/01/30]
Referring again to that NIS passwd crisis from last week, PIKT paged us at 4 AM Monday morning, letting us know that the NIS passwd file was trashed. That emergency was dire enough to warrant the page, also at that early hour, but it got me to thinking about selectively turning paging on and off at different times of the day.
Here is another PIKT macro I cooked up:
/////////////////////////////////////////////////////////////////////////////// page(M, R, H) // send a page message (M) to recipients (pager phone alias) // (R) but only during hours (H) if (H) =execwait "echo '(M)' | =mailx -s '(M)' (R)" fi ///////////////////////////////////////////////////////////////////////////////
Before, we were paging using the statement, for example,
=execwait "echo '$host is sick/down' | =mailx -s '$host is sick/down' =pagesysadmins"
but this would execute regardless of the hour.
Now, instead, we can invoke
=page($host is sick/down, =pagesysadmins, =allhours)
or
=page($hostname() /ckp is full, pagedba\, ! =offhours)
and the page will go off or not depending on the =page() macro's third argument. (Note that the =page macro's first argument, the page message, should not be enclosed in quotes.)
=allhours is a new macro, akin to =offhours
offhours ( #hour() >= 22 || #hour() < 6 ) // 10 PM to 6 AM allhours #true() // any time of the day // or night
I went through our alarms.cfg, editing in this new =page() macro. To reassure myself that the only effective change in the final preprocessed scripts was the addition of the 'if <hours> ... fi' wrapper, I did this for one sample system:
vienna# piktc -f +A all +H moscow diff -r /pikt/lib/configs/staging/EMERGENCY.alt /pikt/lib/configs/diffing/EMERGENCY.alt 77d76 < if #true ( ) 79d77 < fi 134d131 < if ! ( #hour ( ) >= 22 || #hour ( ) < 6 ) 136d132 < fi
Reassured that the paging statement itself was unchanged from before, I then ran a 'piktc -fv +A all -H downsys' to verify that these were the only changes introduced on all systems. I followed up with the usual 'piktc -iv +A all -H downsys' to actually install the changed versions.
With the =page() macro, too, I can think of all sorts of embellishments. Some other day...
Not only does the =page() macro introduce new functionality, it also is more concise and readable than the '=execwait ...' statement it replaces. I am constantly thinking of new macros like this that enhance PIKT's functionality, flexibility, readability, and ease of use.
For more examples, see Developer's Notes.