Ad Widget

Collapse

Item Preprocessing Regex Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erasedhammer
    Member
    • Aug 2020
    • 58

    #1

    Item Preprocessing Regex Help

    I'm trying to parse through dpkg versions with the "system.sw.packages.get" key.
    Dpkg prepends and appends various data that I want to trim off so it can be consistent accross different package managers.
    For example I would like to get rid of the ":1" and the "+deb11u1" values in this example: "1:8.4p1-5+deb11u1

    But the problem is, these values are not always present in the return version value.
    And there is no way for Zabbix to fail safely and still return some value (the Custom On Fail: discard value doesn't work as it doesn't give a value back, it just fails outright).
    So I am trying to use regex to work on a lot of different strings and trim off the uneeded material.

    Here are my preprocessing steps so far:
    Code:
    JSONPath $.*.version
    Regex (?<=").*(?=") \0
    Regex .*(?=\+)? \0
    Regex (?<=:)?.* \0
    Despite adding the "?" after match group, it fails when the value is present. But if I remove it, it fails when the value is not present.

    Here is some examples for the various input data:
    Code:
    [{"name":"archivebox","manager":"dpkg","version":"0.6.2-1","size":1763328,"arch":"all","buildtime":{"times tamp":0,"value":""},"installtime":{"timestamp":0," value":""}}]
    [{"name":"chrony","manager":"dpkg","version":"4.0-8+deb11u2","size":644096,"arch":"amd64","buildtime ":{"timestamp":0,"value":""},"installtime":{"times tamp":0,"value":""}}]
    [{"name":"openssh-server","manager":"dpkg","version":"1:8.4p1-5+deb11u1","size":1604608,"arch":"amd64","buildtim e":{"timestamp":0,"value":""},"installtime":{"time stamp":0,"value":""}}]
    [{"name":"qemu-guest-agent","manager":"dpkg","version":"1:5.2+dfsg-11+deb11u2","size":765952,"arch":"amd64","buildtim e":{"timestamp":0,"value":""},"installtime":{"time stamp":0,"value":""}}]
    Can someone help me with this regex? I am not sure how to work with all these different input values and have the preprocessing steps not fail.
    Last edited by erasedhammer; 15-05-2023, 16:49.
  • markosa
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Aug 2022
    • 104

    #2
    I think you need to have one regex which handles different versions(syntax) since those steps are getting input from previous step. regex101.com is quite good place to test different patterns.

    Comment

    Working...