Ad Widget

Collapse

CSV to JSON adding brackets and backslashes

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #1

    CSV to JSON adding brackets and backslashes

    I've created a discovery rule that collects a list of files.
    The list goes something like this:
    Code:
    $ zabbix_get -s PXW1CEADG016 -k system.run["powershell.exe -File C:\zabbix\scripts\mailing_file_stats.ps1"]
    name
    C:\FTP\import\bkp
    C:\FTP\import\20220709013444_cacs10_v83.txt
    C:\FTP\import\20220709013444_cacs10_v83.txt.log
    C:\FTP\import\20220709013444_cacs11_v83.txt
    C:\FTP\import\20220709013444_cacs11_v83.txt.log
    C:\FTP\import\20220709013445_cakauto4.txt
    C:\FTP\import\20220709013445_cakauto4.txt.log
    C:\FTP\import\20220709_Cacs3_v83_PXW1CEADG018.txt
    C:\FTP\import\20220709_Cacs9_v83_PXW1CEADG021.txt
    Then, I added the preprocessing "CSV to JSON".
    For that discovery, there's a macro, {#MAILING.NAME} -> $..name

    For testing, I've created an item prototype to get the file size.
    Code:
    vfs.file.size[{#MAILING.NAME}]
    After that, Zabbix created an item for each file with the wrong file path.
    It added literal brackets and backslashes to the file path, therefore, making the item unsupported.

    vfs.file.size["["C:\\FTP\\import\\20220709_Cacs3_v83_Processad o_no _servidor_PXW1CEADG018.txt"]"]

    Any idea of how to correct that?
    Last edited by markfree; 10-07-2022, 00:44.
  • Answer selected by markfree at 10-07-2022, 01:09.
    Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    For me it looks like your jsonpath ($..name) is somehow incorrect as it returns the value as list (array), not as plain string. How about $..name.first() or $.name?

    Markku

    Comment

    • Markku
      Senior Member
      Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
      • Sep 2018
      • 1781

      #2
      For me it looks like your jsonpath ($..name) is somehow incorrect as it returns the value as list (array), not as plain string. How about $..name.first() or $.name?

      Markku

      Comment

      • markfree
        Senior Member
        • Apr 2019
        • 868

        #3
        That's it!
        If I change JSONPath to $.name, the discovery rule finds all files correctly.

        I was testing JSONPath with an online evaluator and its result had no matches when using 1 dots.
        I guess that was misleading.
        Last edited by markfree; 10-07-2022, 01:09.

        Comment

        • Markku
          Senior Member
          Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
          • Sep 2018
          • 1781

          #4
          Originally posted by markfree

          I was testing JSONPath with an online evaluator and its result had no matches when using 1 dots.
          I guess that was misleading.
          My feeling exactly: I haven't found a practical way to test the Zabbix JSONPath expressions outside of Zabbix as those that I've tried haven't quite worked like Zabbix.

          Markku

          Comment

          Working...