Forum Discussion

JaredM's avatar
9 months ago
Solved

how to construct Regex datapoint statements

I am not finding much documentation on how to construct regex statements for a datapoint other than this:

https://www.logicmonitor.com/support/logicmodules/datasources/datapoints/normal-datapoints

My goal is to convert a string from an SNMP walk. I currently can return the OID and receive the raw value.

My attempts so far have resulted in NaN:

datapointName:\[^\\d]", "”

datapointName:\"-.*", ""

OID is .1.3.6.1.4.1.9.9.156.1.1.2.1.4.1 
Raw value is 12.5.1.16900-48

Thanks for any assistance.

  • Hey @JaredM 

    So, I don’t have that exact OID to test against, but I tested against this one in my own environment:

    1.3.6.1.2.1.1.2.0 which returns a value of 1.3.6.1.4.1.8072.3.2.10

    I was able to parse the 1.3 out of that returned value and show it in raw data using this regex:

    ^(\d+\.\d+)

6 Replies

  • Hey @JaredM 

    So, I don’t have that exact OID to test against, but I tested against this one in my own environment:

    1.3.6.1.2.1.1.2.0 which returns a value of 1.3.6.1.4.1.8072.3.2.10

    I was able to parse the 1.3 out of that returned value and show it in raw data using this regex:

    ^(\d+\.\d+)

  • Perfect!  

    That is great to hear that it resolved it.  

    Yea, so to give a bit more context, since the SNMP collection method essentially just returns the value directly you can just use straight regex to capture the value you want to from that returned value without needing to try to parse anything out before it. 

  • The LM specific part is that the value you want to return needs to be in a capture group.

    Even having years of experience with RegEx and even getting it to work with online testers doesn’t always mean it works in LM. There are LM specific tricks that a handful of good examples would clarify.

    The same thing goes for regex in configsources.

  • Hey @JaredM 

    You are correct in that we do not provide much documentation on how to craft regex statements.  This is because it’s not something that is specific to LogicMonitor, we utilize Javas regex for most of the portal and would refer back to the Java regex docs:

    https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html 

    However, looking at the raw value “12.5.1.16900-48” I just want to make sure, are you trying to capture this whole value in your datapoint?  If so that would not be possible since it does include characters that are non-numerical.  DataSources are only able to capture numerical data.  

    So out of that statement you could potentially parse something like this, “12511690048” but I don’t know how useful that would be.  This may be better suited for a PropertySource if a single value ties to a resource, or as an instance level property if there are multiple values tied to multiple instances on a single resource. 

    Although the LMSupport team cannot craft a custom LogicModule for you, if you were to open a support ticket we can take a deeper look into this in your specific environment.  If you do enter a support case, please do DM me the ticket ID and I can take a look for you. 

  • @LMjosephBrett , thanks and I realize you caught the fact that this needs to be parsed more than just the hyphenated suffix.

    I’m okay with a result of “12.5”. But I can’t get a result if I try:
    datapointName:/^[0-9]+(\.[0-9]+)?/

    even:
    datapointName:\d.

    Therefore, it still feels like something that is a specific requirement to the platform is missing in the statement. I have gathered “datapointName:” is required.. anything else? That’s what I’m asking for help with at this point, rather than the actual regex statement construction.

  • Yes, this solved it for me. The caret character added at the beginning seemed to clear up issues when added. 

    The documentation which shows the datapoint name included in the regex field always fails for me.