Example: ExtractIfString.stch stitcher

Use this topic to understand how data extraction stitchers work.

The ExtractIfString.stch stitcher attempts to extract a textual interface identifier from an input argument of the form ifEntry.string_identifier, where string_identifier is the textual interface identifier . This method is usually used to extract the ifIndex value from an event field such as LocalPriObj or LocalRootObj.
Table 1. Line-by-line description of the ExtractIfString.stch stitcher
Line numbers Description
3-11 This stitcher is invoked by another stitcher, usually a topology lookup stitcher.
15 Initialize the ifString variable to null. The ifString variable will hold the results of the textual interface identifier extraction operation.
17 Read the input argument from the invoking stitcher and load this into ifInputStr variable.
19 Specify a regular expression to use as part of the pattern matching and data extraction operation.
21-27 Perform the pattern matching and data extraction operation.
29 Pass the extracted string back to the invoking stitcher.
UserDefinedStitcher
{
    StitcherTrigger
    {
        //
        // Called from another stitcher using the syntax:
        //
        // text ifString = "";
        // ifString = ExecuteStitcher( 'ExtractIfString', myStringField );
        //
    }

    StitcherRules
    {
        text ifString = "";

        text ifInputStr = eval(text, '$ARG_1');

        text stringMatch = "^ifEntry\.(\S+)";

        int stringMatchCount = MatchPattern( ifInputStr, stringMatch );

        // We only recognise a match if we matched once on the entire field
        if (stringMatchCount == 1 AND REGEX0 == ifInputStr )
        {
            ifString = eval(text, '$REGEX1');
        }

        SetReturnValue( ifString );
    }
}