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

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:

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

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:

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

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 -h output

 

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.