DX Unified Infrastructure Management

 View Only
  • 1.  Logmon - Define two variables in the same line (same Watcher)

    Posted Jan 17, 2017 07:52 AM

    Hi,

     

    I'm trying to set up a Watcher Rule in logmon where I want to define to variables in a single line text file.

    Excerpt from the file:

    "<ID>1078</ID><Name>John</Name>"

     

    I want the values 1078 and John as two separate variables.

    I'm using the following expression:

    /((?<=<ID>).*(?=</ID>))|((?<=<Name>).*(?=</Name>))/

     

    In logmon the variables are set as Match Expression ($1 for ID and $2 for Name) in the same Watcher Rule.

    The first capture group for <ID> and the second capture group for <Name>

    Message To Send on Match: "Person ${Name} has ID ${ID}"

    (desired result: "Person John has ID 1078")

     

    When testing the profile I noticed that it won't match both <ID> and <Name>.

    I get the following message: "Person ${Name} has ID 1078"

    When changing the order of the elements in the file to "<Name>John</Name><ID>1078</ID>" I get "Person John has ID $ID".

    So it looks like it only matches the first possible one. I have "Alarm on First Match Only" unchecked.

     

    Is it possible to define two variables in the same Watcher Rule using a single line text file?

     

    Any help is appreciated!

     

    Thanks in advance,

    Erik



  • 2.  Re: Logmon - Define two variables in the same line (same Watcher)

    Broadcom Employee
    Posted Jan 17, 2017 03:14 PM

    can you post your logmon.cfg and the original source file to review.

    Might be able to provide a solution with that.



  • 3.  Re: Logmon - Define two variables in the same line (same Watcher)

    Posted Jan 17, 2017 05:17 PM

    Your REGEX has a '|' character in it - that's an OR statement.

     

    I think that what you want is

    /^<ID>(\d+)</ID><Name>(.*)</Name>$/

     

    then you'll have $1 and $2 properly captured. In your try, only $1 would be set and it would depend which pattern matched first.

     

    -Garin



  • 4.  Re: Logmon - Define two variables in the same line (same Watcher)

    Posted Jan 17, 2017 05:19 PM

    RegExp - JavaScript | MDN 

     

    Worth a look

     

    -Garin



  • 5.  Re: Logmon - Define two variables in the same line (same Watcher)

    Posted Jan 19, 2017 07:25 AM

    That did the trick!

    I see now that the lookaheads were completely unecessary in my regex.

    I previously set up a working expression in logmon using a pipe, but that was a textfile with line breaks and tidy comma separation. In that case it was a bit easier to work with column matching

     

    Many thanks for your help, very much appreciated!

     

    /Erik