Ad Widget

Collapse

Regular Expression to extract value from a String for a trigger?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarcoUK
    Junior Member
    • Oct 2021
    • 26

    #1

    Regular Expression to extract value from a String for a trigger?

    Hi,
    is it possible to extract a value (number) from a string in a trigger?

    I have this item:
    Code:
    Name: test_bgp_prefix
    Type: SNMP agent
    Key: test_bgp_prefix
    SNMP OID: NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."bgpprefix"
    Type of information: Text
    This is my status:
    Code:
    snmpwalk -v 2c -c public 192.168.2.5 . | grep bgp
    HOST-RESOURCES-MIB::hrSWRunName.596 = STRING: "bgp_collectd"
    HOST-RESOURCES-MIB::hrSWRunName.21105 = STRING: "bgpd"
    HOST-RESOURCES-MIB::hrSWRunPath.21105 = STRING: "/usr/lib/quagga/bgpd"
    HOST-RESOURCES-MIB::hrSWRunParameters.596 = STRING: "/sbin/bgp_collectd"
    HOST-RESOURCES-MIB::hrSWRunParameters.21115 = STRING: "--daemon zebra bgpd"
    NET-SNMP-EXTEND-MIB::nsExtendCommand."bgpprefix" = STRING: /bin/check_bgp_prefix
    NET-SNMP-EXTEND-MIB::nsExtendCommand."bgpstatus" = STRING: /bin/check_bgp
    NET-SNMP-EXTEND-MIB::nsExtendArgs."bgpprefix" = STRING:
    NET-SNMP-EXTEND-MIB::nsExtendArgs."bgpstatus" = STRING:
    NET-SNMP-EXTEND-MIB::nsExtendInput."bgpprefix" = STRING:
    NET-SNMP-EXTEND-MIB::nsExtendInput."bgpstatus" = STRING:
    NET-SNMP-EXTEND-MIB::nsExtendCacheTime."bgpprefix" = INTEGER: 5
    NET-SNMP-EXTEND-MIB::nsExtendCacheTime."bgpstatus" = INTEGER: 5
    NET-SNMP-EXTEND-MIB::nsExtendExecType."bgpprefix" = INTEGER: exec(1)
    NET-SNMP-EXTEND-MIB::nsExtendExecType."bgpstatus" = INTEGER: exec(1)
    NET-SNMP-EXTEND-MIB::nsExtendRunType."bgpprefix" = INTEGER: run-on-read(1)
    NET-SNMP-EXTEND-MIB::nsExtendRunType."bgpstatus" = INTEGER: run-on-read(1)
    NET-SNMP-EXTEND-MIB::nsExtendStorage."bgpprefix" = INTEGER: permanent(4)
    NET-SNMP-EXTEND-MIB::nsExtendStorage."bgpstatus" = INTEGER: permanent(4)
    NET-SNMP-EXTEND-MIB::nsExtendStatus."bgpprefix" = INTEGER: active(1)
    NET-SNMP-EXTEND-MIB::nsExtendStatus."bgpstatus" = INTEGER: active(1)
    NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."bgpprefix" = STRING: 0 OK: 2180 BGP prefixes defined
    NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."bgpstatus" = STRING: 0 OK: BGP Session Established
    NET-SNMP-EXTEND-MIB::nsExtendOutputFull."bgpprefix" = STRING: 0 OK: 2180 BGP prefixes defined
    NET-SNMP-EXTEND-MIB::nsExtendOutputFull."bgpstatus" = STRING: 0 OK: BGP Session Established
    NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."bgpprefix" = INTEGER: 1
    NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."bgpstatus" = INTEGER: 1
    NET-SNMP-EXTEND-MIB::nsExtendResult."bgpprefix" = INTEGER: 0
    NET-SNMP-EXTEND-MIB::nsExtendResult."bgpstatus" = INTEGER: 0
    NET-SNMP-EXTEND-MIB::nsExtendOutLine."bgpprefix".1 = STRING: 0 OK: 2180 BGP prefixes defined
    NET-SNMP-EXTEND-MIB::nsExtendOutLine."bgpstatus".1 = STRING: 0 OK: BGP Session Established
    if I test my item I receive the string: 0 OK: 2180 BGP prefixes defined

    IS it possible (and how can I do it) create a trigger to process this string (0 OK: 2180 BGP prefixes defined) and extract only the value 2180?
  • MarcoUK
    Junior Member
    • Oct 2021
    • 26

    #2
    Originally posted by cyber
    You could add some preprocessing with regex to item, so it only saves that number, not the text.
    Match: (\d+) OK: (\d+) BGP prefixes defined set output to \2 and change data type to integer. it will save just that number.
    Thanks for your reply.
    Could I have an example please?
    I don't understand if can I set regex directly on the item (this item is an SNMP agent) or only in the trigger.

    Comment

    Working...