Ad Widget

Collapse

One call, two items.

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • StefTresMan
    Member
    • Feb 2022
    • 32

    #1

    One call, two items.

    Hi All,

    I currently am monitoring temperature and humidity loggers through a script. What I do there is solved thanks to the community in this post: https://www.zabbix.com/forum/zabbix-...telnet-session

    The script is called from userparameters in Zabbix agent. Works perfectly. The thing is, these logger give status of temperature and humidity in one call. The BASH-script opens a socket to the logger, sends a command, receives a reply. The reply contains both temperature AND humidity information, and when i run the script, i filter the information sent to zabbix by commandline parameters: -t returns temp, -h returns humidity.
    So i run the script twice to get temperature and humidity, script filters the data and returns HUM or TEMP.

    In the Zabbix template I have created 2 items: temperature and humidity, each an other userparameter defined in the zabbix_agentd.conf file

    Is it possible in Zabbix to let the script run only once and get the data into two different items? I can let the script return eg CSV for the two metrics. (item preprocessing???)
    So one userparameter that calls the script, and and two Items returned? Now i have to run it twice while the needed data is returned in one response, doubling the network overhead to derive this data since i have to open the socket twice. And in my measurements i sometimes have 'NaN' results because Zabbix calls the script twice, but can't derive the data because the socket is still open from the previous call..
  • Answer selected by StefTresMan at 06-07-2022, 14:28.
    Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    Helo again. :-)
    You write a script that returns json with temperature and humidity.
    Make one master item (without saving history) and 2 items dependent on it.
    In dependent item in preprocessing, use JSONPATH and get the desired values.

    all information is here

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #2
      Helo again. :-)
      You write a script that returns json with temperature and humidity.
      Make one master item (without saving history) and 2 items dependent on it.
      In dependent item in preprocessing, use JSONPATH and get the desired values.

      all information is here

      Comment

      • StefTresMan
        Member
        • Feb 2022
        • 32

        #3
        Hi Hamardaben,

        Thank you for helping me out again! I will look into it and see how it goes - will keep you posted.

        Comment

        • StefTresMan
          Member
          • Feb 2022
          • 32

          #4
          I managed to do it like this:

          Rewrote the script so it is called with only commandline parameter IP. Script returns both temerature and humidity seperated by a comma: 21.3,41.7. Created a maser item that calls the script, and the created 2 dependent items where i derive the values with javascript:

          Code:
          temp = value.split(",")[0];
          val = parseFloat(temp);
          return val;
          since the script returns text, and temperature is a float, i also used the parseFloat object.
          For humidity:
          Code:
          temp = value.split(",")[1];
          Works like a charm. Thanks again, Hamardaban​​​​​​​ ! You got me in the right direction again. Next thread is on it's way

          Comment

          Working...