#rule() Debug Function

[posted 2002/02/27]

We have added the new #rule() debug function (aka #rulenumber()). #rule() returns 0 when invoked from within a Pikt script begin section, 1 within the first rule, 2 within the second rule, and so on. If there are six rules within a Pikt script and #rule() is invoked from within an end section, 7 is returned.

One use of the #rule() debug function is to identify more easily which rule triggers certain actions.  For example, you might have a script with many rules applying many different pattern matches to a logfile message.  It's sometimes hard to determine which rule yields a match, hence which rule is responsible for sending alert e-mail, triggering a page, or logging to a log file.

Here is a suggested macro using #rule() (for inclusion in macros.cfg):

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

// debug macros

tracerule(S)
#ifdef debug
                "rule $text(#rule()): " . (S)
#elsedef
                (S)
#endifdef

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

You might use it in a script thusly:

        ...

        rule
                if $inlin =~ "<regexp 1>"
                        output mail =tracerule($il)
                        ...
                endif

        rule
                if $inlin =~ "<regexp 2>"
                        output mail =tracerule($il)
                        ...
                endif

        rule
                if $inlin =~ "<regexp 3>"
                        output mail =tracerule($il)
                        ...
                endif

        ...

If you have debug set to TRUE in defines.cfg (or using '+D debug' at the piktc command line), you would then see output like

        rule 5: Jan 30 10:33:03 milan sshd[11548]: [ID 800047 auth.info]
          Did not receive identification string from 100.200.111.222

instead of simply (without the rule identifier)

        Jan 30 10:33:03 milan sshd[11548]: [ID 800047 auth.info]
          Did not receive identification string from 100.200.111.222

(The latter is the normal output you would see if not in debug mode.)

Open Hand For more examples, see Developer's Notes.

 
Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software
Developer's Notes | Licensing | Authors | Pikt-Users | Pikt-Workers | Related Projects | Site Index | Privacy Policy | Contact Us
Page best viewed at 1024x768 or greater.   Page last updated 2008-02-27.   This site is PIKT® powered.
PIKT® is a registered trademark of the University of Chicago.   Copyright © 1998-2008 Robert Osterlund. All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title
View sample
grpck
problems
Pikt script