Ad Widget

Collapse

process pgbackrest info --output json for lld and data fetching

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ik_zelf
    Member
    • Feb 2015
    • 60

    #1

    process pgbackrest info --output json for lld and data fetching

    For postgres backup monitoring I wrote a little script that gets the info for the last backup of all defined backups:
    Code:
    #!/usr/bin/env bash
    
    pgbackrest info --output json |
    jq 'map([.backup[] + {name}]
    | max_by(.timestamp.stop))'
    '
    this gives output similar to:
    Code:
    [{
    "timestamp": {
    "start": 1642144388,
    "stop": 1642144392
    },
    "type": "full",
    "name": "db1"
    },
    {
    "timestamp": {
    "start": 1642144392,
    "stop": 1642144394
    },
    "type": "incr",
    "name": "db2"
    }]
    (I removed most items trying to make this a bit shorter)
    How can I use this data in a discovery rule to generate items like {#NAME}.type ?
    How can I use this same data to fetch the value for "type" for all listed databases?
    Should I change the output of the script to make it [easier] usable?

    My idea is to collect this raw data in a text item and have the discovery rule and the generated items dependents of the raw data text item.

    I am currently on v-5LTS.
    I hope for some nice hints on this, thanks in advance.
    Last edited by ik_zelf; 14-01-2022, 15:57. Reason: I fixed the jq string so it now forms a correct array
  • Answer selected by ik_zelf at 17-01-2022, 09:57.
    ik_zelf
    Member
    • Feb 2015
    • 60

    Reading https://www.zabbix.com/documentation...items/jsonpath gives me the idea I should be able to fetch the data from the array using a filter like:

    $.[?(@.name=="{#NAME}" && @.type=="full")].timestamp.start

    The idea is to search for a name and the current type of the backup to fetch the start time
    This seems to be working OK for me now with the array as specified in the top post of this thread.
    Thanks for thinking with me.
    Last edited by ik_zelf; 17-01-2022, 09:50.

    Comment


    • ik_zelf
      ik_zelf commented
      Editing a comment
      Just in case someone needs pgbackrest monitoring: check https://github.com/ikzelf/my-zabbix-templates I put a script and a template in there. Might be useful and maybe one sees improvements and shares them. Feel free to clone and use.
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    for LLD you need something like this


    [
    { "timestamp": { "start": 1642144388, "stop": 1642144392 }, "type": "full", "name": "db1" }
    ,
    { "timestamp": { "start": 1642144392, "stop": 1642144394 }, "type": "incr", "name": "db2" }
    ]

    LLD macro: {#NAME}==$.name {#TYPE}==$.type$.type
    key prototype: key[{#NAME}_{#TYPE}]
    Last edited by Hamardaban; 14-01-2022, 13:47.

    Comment


    • ik_zelf
      ik_zelf commented
      Editing a comment
      I fixed the jq command string so it now forms a correct array. I was expecting {#NAME} = $.[*].name and {#TYPE} = $.[*].type
      In https://jsonpath.com that gives [
      "db1",
      "db2"
      ] and [
      "full",
      "incr"
      ]
      Is that OK?
      With that I can indeed have prototypes like ey prototype: key[{#NAME}_{#TYPE}] although I prefer in this case key[{#NAME}_type because the array will only list the last backup of a database (weekly full, daily incr).
      question that remains is: how can I select the correct array element for getting the value? Can I use {#NAME} in the pre-processing of the item? It would be a pity if I receive "full" for db2 ...... (with given inputs)

    • ik_zelf
      ik_zelf commented
      Editing a comment
      comment on wrong msg. Sorry for that.
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #3
    Pls read: https://www.zabbix.com/documentation...evel_discovery

    Comment

    • ik_zelf
      Member
      • Feb 2015
      • 60

      #4
      Reading https://www.zabbix.com/documentation...items/jsonpath gives me the idea I should be able to fetch the data from the array using a filter like:

      $.[?(@.name=="{#NAME}" && @.type=="full")].timestamp.start

      The idea is to search for a name and the current type of the backup to fetch the start time
      This seems to be working OK for me now with the array as specified in the top post of this thread.
      Thanks for thinking with me.
      Last edited by ik_zelf; 17-01-2022, 09:50.

      Comment


      • ik_zelf
        ik_zelf commented
        Editing a comment
        Just in case someone needs pgbackrest monitoring: check https://github.com/ikzelf/my-zabbix-templates I put a script and a template in there. Might be useful and maybe one sees improvements and shares them. Feel free to clone and use.
    Working...