Ad Widget

Collapse

How To Display All Rows From A SQL Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mursel.BAKAY
    Junior Member
    • Jun 2022
    • 12

    #1

    How To Display All Rows From A SQL Query

    Hi,

    I have created an item for showing sql query result. But it shows only the first row as result. I want to display all rows and show it on dashboard. Is it possible?

    How can I do it?
    Thanks a lot.
  • vladimir_lv
    Senior Member
    • May 2022
    • 240

    #2
    How looks your item?

    Comment

    • Mursel.BAKAY
      Junior Member
      • Jun 2022
      • 12

      #3
      Hi,

      I attached screens about my issue.
      My item looks like item.png. When I test it, that looks as test.png. And my sql result have 280 rows but zabbix shows only 1 row. Also my query and its result showed at result.png.

      Thanks for your help.
      Attached Files

      Comment

      • vladimir_lv
        Senior Member
        • May 2022
        • 240

        #4
        You can try to get an answer for your request as JSON and then parse it.
        For example:
        Code:
         SELECT CONCAT('[', my_result, ']') AS zabbix_hosts FROM ( SELECT GROUP_CONCAT('{', my_json, '}' SEPARATOR ',') AS my_result FROM (   SELECT      CONCAT     (       '"hostid":'   , '"', hostid   , '"', ','        '"host":', '"', host, '"', ','       '"uuid":'  , uuid     ) AS my_json   FROM hosts ) AS more_json ) AS yet_more_json;

        Comment

        • dimir
          Zabbix developer
          • Apr 2011
          • 1080

          #5
          In order to catch multiple lines use item key
          Code:
          db.odbc.get
          instead of
          Code:
          db.odbc.select
          More info here.
          Last edited by dimir; 27-07-2022, 14:28.

          Comment


          • dimir
            dimir commented
            Editing a comment
            I'm afraid there's no such way currently. Would it be possible to filter out just what you need using item value preprocessing? Or, you could use dependent items, but in this case the number of values to save should be probably static.

            Alternatively you can create your own module for Frontend.

          • dimir
            dimir commented
            Editing a comment
            Why are you using JSON? If you leave it just as multiline output isn't it shown correctly in the item widget?

          • Mursel.BAKAY
            Mursel.BAKAY commented
            Editing a comment
            I'm not using JSON anyway. When I add item to dashboard, my result is like "value.png" as I attached. I don't know what to do.
        • Mursel.BAKAY
          Junior Member
          • Jun 2022
          • 12

          #6
          value.png has been attached.
          Attached Files

          Comment

          Working...