DX NetOps

Expand all | Collapse all

Vendor Certification: Is it possible to convert from string to number?

Jump to Best Answer
  • 1.  Vendor Certification: Is it possible to convert from string to number?

    Posted 06-29-2018 02:21 PM

    I'm trying to create a new vendor certification for a custom metric family. The problem is that the vendor MIB returns the relevant OIDs as DisplayString instead of one of the number formats. Unfortunately, the Data Aggregator does not automatically convert the values to numbers. I could find any function in the documentation to do that. Is there an expression that I can use to do the conversion?

     

    Here is a fragment from the polling debug:

     

    Jun 29 18:08:36.862: AbstractPollResponseListener Received Snmp4j response to an SNMP GET request: , responseEvent=ResponseEvent [
    Jun 29 18:08:36.862: source=Snmp
    Jun 29 18:08:36.862: address=172.17.44.113/161
    Jun 29 18:08:36.862: request=GET[requestID=735175083, errorStatus=Success(0), errorIndex=50, VBS[
    Jun 29 18:08:36.862: 1.3.6.1.4.1.2684.1.1.21.0 = Null
    Jun 29 18:08:36.862: 1.3.6.1.4.1.2684.1.1.23.0 = Null
    Jun 29 18:08:36.862: 1.3.6.1.4.1.2684.1.1.22.0 = Null
    Jun 29 18:08:36.862: ]]
    Jun 29 18:08:36.862: response=RESPONSE[requestID=735175083, errorStatus=Success(0), errorIndex=0, VBS[
    Jun 29 18:08:36.862: 1.3.6.1.4.1.2684.1.1.21.0 = 0.00
    Jun 29 18:08:36.862: 1.3.6.1.4.1.2684.1.1.23.0 = 30
    Jun 29 18:08:36.862: 1.3.6.1.4.1.2684.1.1.22.0 = 2.0
    Jun 29 18:08:36.862: ]]
    Jun 29 18:08:36.862: userObject=ItemBasedRequestState[responseReceivedTimestamp=1530295716862, nextIndex=1, itemList=[207824]]

    Jun 29 18:08:36.862: error=null
    Jun 29 18:08:36.862: ]
    Jun 29 18:08:36.862: Sending response:SnmpPollResponse [itemID=207824, deviceItemId=207824, internetAddress=172.17.44.113, pollGroupId=207788, cycleTimestamp=1530295500000
    Jun 29 18:08:36.862: readTimestamp=1530295716862, duration=300000, pollRate=-1, error=SUCCESS, errorIndex=-1, rowData=[
    Jun 29 18:08:36.862: SnmpResponseVariable [oid=1.3.6.1.4.1.2684.1.1.21.0, type=OCTET_STRING, value={48,46,48,48}, isDelta=false, isList=false, error=SUCCESS, isDynamicIndex=false, indexList=null]
    Jun 29 18:08:36.862: SnmpResponseVariable [oid=1.3.6.1.4.1.2684.1.1.23.0, type=OCTET_STRING, value={51,48}, isDelta=false, isList=false, error=SUCCESS, isDynamicIndex=false, indexList=null]
    Jun 29 18:08:36.862: SnmpResponseVariable [oid=1.3.6.1.4.1.2684.1.1.22.0, type=OCTET_STRING, value={50,46,48}, isDelta=false, isList=false, error=SUCCESS, isDynamicIndex=false, indexList=null]
    Jun 29 18:08:36.862: ]]

     

     

    Looks like DA converts the string to a list with one integer for each character.



  • 2.  Re: Vendor Certification: Is it possible to convert from string to number?
    Best Answer

    Broadcom Employee
    Posted 06-29-2018 02:30 PM

    Hi Renato,

     

    The following are the Functions & Global Variables related to MVEL use to convert values.

     

    Functions and Global Variables - CA Performance Management - 3.5 - CA Technologies Documentation 

     

    Not sure I see one that is capable of performing the conversion you're seeking.

     

    Anyone else converted a DisplayString to provide metrics in a custom cert that could share the method with the Community?

     

    If not this might come down to it being an Enhancement Request.

     

    Thanks,
    Mike



  • 3.  Re: Vendor Certification: Is it possible to convert from string to number?

    Broadcom Employee
    Posted 06-29-2018 03:32 PM

    Yes, there is a way to do this.  I've had to do this for another vendor certification a few months back.  Unfortunately, I can't get to a system to check what it was at the moment.  I don't recall using MVEL but rather ().toInteger or similar.  Maybe that will jog someone else's memory.  Otherwise, I'll post an update when I get access.



  • 4.  Re: Vendor Certification: Is it possible to convert from string to number?

    Posted 06-29-2018 03:33 PM

    Can't believe I went missed that. There is a snmpOctetStringFloat function. 



  • 5.  Re: Vendor Certification: Is it possible to convert from string to number?

    Posted 07-02-2018 08:58 AM

    As other before me said, the VC in PM is fully MVEL capable. You can use the Double.parseDouble(YourStringValue.toString()) function to extract parts from a string that you might need. If the value itself does not contain any other characters,then Double.parseDouble(YourStringValue) would suffice. 

     

    This is a section from a VC that I have that reads the String value and extracts, based on space separator only the first section from the string. That section is then converted to a Double.

     

    <Expression destAttr="VoltageValue">(esPointValueInt &lt; 0) ? (Double.parseDouble(esPointValueStr.toString().split("\\s+")[0])/-1) : (Double.parseDouble(esPointValueStr.toString().split("\\s+")[0]))</Expression>

     

    I use this intensively in devices that are not SNMP friendly. 



  • 6.  Re: Vendor Certification: Is it possible to convert from string to number?

    Posted 07-02-2018 09:05 AM

    I'm using snmpOctetStringFloat function. It is simpler. I just don't know from which version it is available. I'm using it with version 3.2

     

    Thank you for the code though. It will be useful.



  • 7.  Re: Vendor Certification: Is it possible to convert from string to number?

    Posted 07-02-2018 09:31 AM

    I think that will only work for an octetstring that presents only figures. If you have a string that has to be parsed, that's the way to go. I initially encountered several strings like that had to be parsed and I ended up using this method for all strings.