How to test pattern matching expressions in HP BSM Connector policies

This post is one in a series of articles that are aimed for HP BSM guys (and rarely girls) that are new to the, let’s call it “legacy”, Operations Manager and its agents. One of the new doctrines is the pattern matching syntax that is used in OA policies and which now have become part of BSM Connector policies.

Not sure about the reason’s, may be some OM veterans can shred some light on it, but the syntax of regular expressions (or patterns as they are known in the OM world) is very different to Perl style regexes that most of us were used to.
I won’t get into the depth of explanation about the syntax of pattern matching since there are many places you can find that information (offical  documentation and community articles) but rather present to you a command line utility (that comes as part of OA installation) that allows you to test the patterns that you’ve crafted (with sweat and blood I assume) against a test text.

opcpat – pattern matching expressions utility

The utility is located at the %ovinstalldir%\bin\win64\OpC\utils folder on a machine that has OA agent installed, for example BSM Connector.

Note: At the end of this article you will find the full help output of that utility (which you can get by running opcpat with -h option).

There 2 ways of using the pattern matching utility – opcpat:

  • Interactive; You will provide the pattens and the search text using command line prompts.
  • Non-interactive: You specify the location of pattern and search text files.



Interactive use of opcpat

The interactive way of using opcpat could be useful if you want quickly to test your pattern matching expression and don’t want to bother yourself with creating  pattern and values files.

Here is the flow of the pattern test:

  1. Specify the pattern you want to test
  2. Specify the separators
  3. Specify the text to you want to test your pattern against
  4. Verify the results
  5. Either repeat step 3 or hit RETURN to test a new pattern
opcpat
using singlebyte mode

Enter a pattern and the separator characters used for <@>, <S>
pattern (<RETURN> to exit): foo <@.txt> foo
separators:

******** next pattern ********
Pattern: "foo <@.txt> foo" using seps ""
value (<RETURN> for new pattern): foo bar foo
"" txt:"bar" ""

Pattern: "foo <@.txt> foo" using seps ""
value (<RETURN> for new pattern): fff bar fff
Pattern didn't match

Pattern: "foo <@.txt> foo" using seps ""
value (<RETURN> for new pattern):

Enter a pattern and the separator characters used for <@>, <S>
pattern (<RETURN> to exit):

Non-Interactive use of opcpat

I personally find the non-interactive way to be more convenient.

Let’s prepare the input files.

The patterns input file consists of pattern-separator pairs and has the following format:

# commentline (only allowed at the first lines of the file)
# comment ...
pattern1
separators1
pattern2
separators2 ...

In this example I will use a C:\temp\patternfile.txt with the following content:

JOB,NOTOK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>,<*.errorCode>

JOB,LATE,<*.jobId>,<@.runDate>,<@.runTime>

JOB,OK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>

Note the empty lines. I am using them to tell the utility to make use of the default separators (a blank and the tab character).




The values files will consists of lines of values we want to test our patterns against and it has the following format:

# commentline(s)
value_a
value_b
value_c

In this example I will use a C:\temp\valuefile.txt with the following content:

JOB,OK,JOB1,140521,080059,30883,D0
JOB,NOTOK,JOB1,140514,182035,01818,,JNRUN
JOB,LATE,JOB1,140520,030002

Now let’s run the utility and examine the output (which can  be seen in the CLI or redirected to a file using the -o option). You will notice that each pattern is matched against each of the lines in the values file. Each pattern – value matching attempt produces 4 lines of output:

  • pattern: the pattern that is currently been tried
  • using seps: which separators are been used in the current attempt ( displayed only if separators were specified for that pattern)
  • value: the value that the match attempt s been run against
  • result: result of the match attempt. Could have either “pattern didn’t match” sentence or the results of the matched pattern and it’s variables (if the pattern had any)
opcpat -fp c:\temp\patternfile.txt -fv c:\temp\valuefile.txt
using singlebyte mode
******** next pattern ********
Pattern: "JOB,NOTOK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>,<*.errorCode>" using seps ""
Value: "JOB,OK,JOB1,140521,080059,30883,D0"
Pattern didn't match

Pattern: "JOB,NOTOK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>,<*.errorCode>" using seps ""
Value: "JOB,NOTOK,JOB1,140514,182035,01818,,JNRUN"
"" jobId:"JOB1" runDate:"140514" runTime:"182035" runId:"01818" runNode:"" errorCode:"JNRUN"
Pattern: "JOB,NOTOK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>,<*.errorCode>" using seps ""
Value: "JOB,LATE,JOB1,140520,030002"
Pattern didn't match

******** next pattern ********
Pattern: "JOB,LATE,<*.jobId>,<@.runDate>,<@.runTime>" using seps ""
Value: "JOB,OK,JOB1,140521,080059,30883,D0"
Pattern didn't match

Pattern: "JOB,LATE,<*.jobId>,<@.runDate>,<@.runTime>" using seps ""
Value: "JOB,NOTOK,JOB1,140514,182035,01818,,JNRUN"
Pattern didn't match

Pattern: "JOB,LATE,<*.jobId>,<@.runDate>,<@.runTime>" using seps ""
Value: "JOB,LATE,JOB1,140520,030002"
"" jobId:"JOB1" runDate:"140520" runTime:"030002" ""

******** next pattern ********
Pattern: "JOB,OK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>" using seps ""
Value: "JOB,OK,JOB1,140521,080059,30883,D0"
"" jobId:"JOB1" runDate:"140521" runTime:"080059" runId:"30883" runNode:"D0"

Pattern: "JOB,OK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>" using seps ""
Value: "JOB,NOTOK,JOB1,140514,182035,01818,,JNRUN"
Pattern didn't match

Pattern: "JOB,OK,<*.jobId>,<@.runDate>,<@.runTime>,<@.runId>,<*.runNode>" using seps ""
Value: "JOB,LATE,JOB1,140520,030002"
Pattern didn't match



opcpat -h output

C:\Program Files\HP\HP BTO Software\bin\win64\OpC\utils>opcpat -h
Usage:
opcpat [-h] [-i] [-q] [-fp patternfile] [-fv valuefile] [-o outfile][-l length
-h: display this text
-q: quiet mode
-i: use case insensitive pattern matching
-fp patternfile: input file for patterns and separators (see below)
-fv valuefile: input file for value lines matched against each pattern
-o outfile: use 'outfile' for output
-l length: use 'length' for specifying max line length of input file

'patternfile' consists of pattern-separator pairs. It has the format:
# commentline (only allowed at the first lines of the file)
# comment ...
pattern1
separators1
pattern2
separators2 ...

'valuefile' has the format:
# commentline(s)
value_a
value_b
value_c
value_d

 

4 thoughts on “How to test pattern matching expressions in HP BSM Connector policies”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.