Output Macros
The macros in the sample output_macros.cfg configuration file below are for special handling script output. You would use these to control verbosity, to route messages in unusual ways, to send mail and reminder messages, etc.
/////////////////////////////////////////////////////////////////////////////// // output macros - script output /////////////////////////////////////////////////////////////////////////////// // the verbose define controls whether certain routine messages get emailed // or thrown away; in earlier versions of PIKT, this conditionality was // handled in this way in alarms.cfg: // // #ifdef verbose // output mail "truncated $inlin" // #endifdef // // with the macros below, we can now achieve the same effect by replacing // the above three lines with just this one line: // // =outputmail "truncated $inlin" #ifdef verbose outputmail output mail #elsedef outputmail output log "/dev/null" #endifdef // if verbose is not defined (is set to FALSE), the message is logged to // /dev/null, that is, thrown away /////////////////////////////////////////////////////////////////////////////// // the stifle define controls how often certain routine messages ("nagmail") // are sent; in earlier versions of PIKT, this conditionality was handled // in this way in alarms.cfg: // // #ifdef stifle // if #fa % 7 == 0 // report only every 7 days // output mail "orphaned?: $inline" // fi // #elsedef // output mail "orphaned?: $inline" // #endifdef // // with the stifle macros below, we can now achieve the same effect by // replacing the above seven lines with just these three lines: // // if #fa % =stifle(7) == 0 // report only every 7 days // output mail "orphaned?: $inline" // fi #ifdef stifle stifle(N) (N) #elsedef stifle(N) 1 #endifdef /////////////////////////////////////////////////////////////////////////////// output_other_mail(P, S, R, L) // output conditional mail to addressee(s) // beyond those specified in the alert // mailcmd; we don't #pclose() the (P) // proc handle at the end, instead letting // pikt do it, enabling us to make this a // a one-liner macro // (P) is the proc handle name (e.g., MAIL) // (S) is the subject (e.g., 'check this out') // (R) is the recipient (e.g., brahms\) // (L) is the line (e.g., $inline) if ! #defined(#isopen(P)) set #isopen(P) = #false() fi if ! #isopen(P) if #popen((P), "=mailx -s (S) (R)", "w") != #err() set #isopen(P) = #true() else output mail "\#popen() failure for: =mailx -s (S) (R)" quit fi fi do #write((P), (L)) /////////////////////////////////////////////////////////////////////////////// close_other_mail(P) // close an open mail channel // (P) is the proc handle name (e.g., MAIL) if #defined(#isopen(P)) && #isopen(P) do #pclose((P)) fi /////////////////////////////////////////////////////////////////////////////// outputproc(C, P) // send all output from process (P) to communications // channel (C) // (C) is the comm channel (e.g., mail, syslog, print) // (P) is the process (e.g., "=ll /tmp") // sample use: =outputproc(mail, "=ll /tmp") if #popen(OUTPUTPROC, (P), "r") while #read(OUTPUTPROC) > 0 output (C) $rdlin endwhile do #pclose(OUTPUTPROC) fi /////////////////////////////////////////////////////////////////////////////// outputfile(C, F) // send all output from file (F) to communications // channel (C) // (C) is the comm channel (e.g., mail, syslog, print) // (F) is the file (e.g., "=crontabs/$name") // sample use: =outputfile(mail, "=crontabs/$name") if #fopen(OUTPUTFILE, (F), "r") while #read(OUTPUTFILE) > 0 output (C) $rdlin endwhile do #fclose(OUTPUTFILE) fi /////////////////////////////////////////////////////////////////////////////// outputlogfile(C, L) // send new entries in logfile (L) to communications // channel (C) // (C) is the comm channel (e.g., mail, syslog, print) // (L) is the logfile (e.g., "=sulog") // sample use: =outputlogfile(syslog, "=sulog") // note: this takes the place of 'input logfile "..."' init input logfile (L) rule output (C) $inlin /////////////////////////////////////////////////////////////////////////////// outputhdr(C, H) // out header (H) to communications channel (C), but // only if the header has not already been output // (C) is the comm channel (e.g., mail, syslog, print) // (H) is the header (e.g., // $command("=ps -eo user,pid,comm =head -1")) // sample use: // =outputhdr(mail, $command("=ps -eo user,pid,comm =head -1")) if ! #defined(#outputhdr) output (C) (H) set #outputhdr = #true() fi /////////////////////////////////////////////////////////////////////////////// mailmsg1(M, S, R) // e-mail a one-line message (M) with subject (S) // to recipient (R) // (S) must be a single word, e.g., REMINDER // use =mailmsg1() instead of =mailmsg2() in // 'pikt +C' and #piktexec commands // sample use: =mailmsg1(review the sudo group, REMINDER, =piktadmin) =execwait "echo (M) | =mailx -s (S) (R)" /////////////////////////////////////////////////////////////////////////////// mailmsg2(M, S, R) // e-mail a one-line message (M) with subject (S) // to recipient (R) // (S) may be multiple words // sample use: =mailmsg2($inlin, bad address, $list\-owner) =execwait "echo '(M)' | =mailx -s '(S)' (R)" /////////////////////////////////////////////////////////////////////////////// remind(Y, M, D, MSG) // send out a reminder message beginning at a certain date // (Y) is the year (e.g., 2000) // (M) is the month (e.g., 7) // (D) is the date (e.g., 15) // (MSG) is the message (e.g., "REVIEW DISK QUOTAS") if #now() > #datevalue((Y), (M), (D)) output mail (MSG) fi // note: you should be careful to make sure that this reminder // doesn't occur repeatedly starting at the trigger date, for // example, by limiting it to just once per day on just one // machine: //#if madrid // begin // set #dy = #day() // if #dy > %dy // repeat once daily // =remind(2001, 7, 15, "REVIEW DISK QUOTAS") // fi //#endif ///////////////////////////////////////////////////////////////////////////////
For more examples, see Samples.