Ad Widget

Collapse

Modbus Zabbix Proxy

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dade
    Member
    • Jan 2021
    • 34

    #1

    Modbus Zabbix Proxy

    Hello everyone!

    I have the following scenario:

    Zabbix Server on a ubuntu vm, Zabbix Proxy on a Raspberry PI, and a sensor device connected to the Raspberry PI via USB (USB convert RS485).

    I tested a python script on the Raspberry PI and I can collect the data correctly from the equipment via modbus, that is, the communication via modbus between the raspberry pi and the equipment is working.

    My goal: I want the Zabbix Proxy configured on the Raspberry to do this collection via modbus.

    I tried to create a host (monitored by Proxy) and configure the following item:
    Zabbix Agent (Active)
    keys:
    Modbus.get [“/ dev / ttyUSB0 9600 N", 01.04.0001.0001] or
    Modbus.get [“/ dev / ttyUSB0: 9600: 8N", 01.04.0001.0001]

    But it did not work. I don't know if the problem is in the item, host or proxy. I didn't find much information about Modbus.get on the internet.

    Thanks in Advanced!
    Attached Files
  • dade
    Member
    • Jan 2021
    • 34

    #2
    I got this error "Unknown metric Modbus.get" on item

    Comment

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

      #3
      According to the documentation, you are incorrectly specifying the connection parameters, in particular the endpoint



      First, specify the protocol - rtu or ascii



      Comment

      • dade
        Member
        • Jan 2021
        • 34

        #4
        Hello Hamardaban! Thanks for you reply!


        Note1: On dmesg i have: [ 1036.808907] usb 1-1.3: FTDI USB Serial Device converter now attached to ttyUSB0

        Note2: On python script i put: port='/dev/ttyUSB0' and it's working.

        I tried diferents ways like:

        Modbus.get["rtu://ttyUSB0",01,04,0001,0001]
        Modbus.get["rtu://ttyS0:9600",01,04,0001,0001]
        Modbus.get[rtu://ttyUSB0:9600:8n,01,04,0001,0001]
        Modbus.get[ascii://ttyUSB0,01,04,0001,0001]
        Modbus.get["rtu://dev/ttyUSB0:9600",01,04,0001,0001]
        Modbus.get[rtu://dev/ttyUSB0,01,04,0001,0001]
        Modbus.get["/dev/ttyUSB0 9600 N",01,04,0001,0001]
        Modbus.get["/dev/ttyUSB0:9600:8n",01,04,0001,0001]
        But it still didnt work.

        Comment

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

          #5
          Specify which version of zabbix you use on the agent and proxy?

          Does your device work as rtu or ascii?
          Note that ascii only supports agent version 2.
          Try using the agent's passive mode.

          Modbus.get["rtu://dev/ttyUSB0:9600:8n",1....
          + verify all next parameter

          Last edited by Hamardaban; 01-04-2021, 20:42.

          Comment

          • dade
            Member
            • Jan 2021
            • 34

            #6
            Ty again Hamardaban. I tried differents parameters but i got same error: Unknown metric Modbus.get

            I gave up on using modbus.get and I decided to create an item to run the python script. I created the following item wih Zabbix Agent:

            system.run [python home/pi/sht20_read_temp.py, wait]

            But when I test it this error occurs:

            Traceback (most recent call last):
            File "home/pi/sht20_read_temp.py", line 6, in <module>
            client.connect()
            File "/usr/lib/python2.7/dist-packages/pymodbus/client/sync.py", line 476, in connect
            self.socket.interCharTimeout = self.inter_char_timeout
            AttributeError: 'NoneType' object has no attribute 'interCharTimeout'



            Running the script directly in the raspberry shell works:

            pi @ raspberrypi: ~ $ python sht20_read_temp.py
            27.1


            Other linux commands with system.run also works like "ls home/" pi or "cat home/pi/sht20_read_temp.py" ...

            Can you help me with that too?

            Thanks for you attention.

            Phyton script below:


            #!/usr/bin/env python
            from pymodbus.client.sync import ModbusSerialClient as ModbusClient
            import time

            client = ModbusClient(method='rtu', port='/dev/ttyUSB0', timeout=1, stopbits = $
            client.connect()

            rr = client.read_input_registers(address=1, count=1, unit=1);
            print rr.registers[0] / 10.0;

            Comment

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

              #7
              Try to run the script on behalf of the user under which the zabbix server is running.

              Comment

              • dade
                Member
                • Jan 2021
                • 34

                #8
                Ty Hamardaban,

                .. so How can i do this?

                sorry about my noobises

                Comment

              • dade
                Member
                • Jan 2021
                • 34

                #9
                So, i did in raspberry shell:

                pi@raspberrypi:~ $ sudo -u pi python sht20_read_temp.py
                26.9


                it worked. But when i used zabbix user i got same item's error:

                pi@raspberrypi:~ $ sudo -u zabbix python sht20_read_temp.py
                Traceback (most recent call last):
                File "sht20_read_temp.py", line 6, in <module>
                client.connect()
                File "/usr/lib/python2.7/dist-packages/pymodbus/client/sync.py", line 476, in connect
                self.socket.interCharTimeout = self.inter_char_timeout
                AttributeError: 'NoneType' object has no attribute 'interCharTimeout'



                I created a item with: system.run[sudo -u pi python home/pi/sht20_read_temp.py,wait] .... and got this:


                We trust you have received the usual lecture from the local System
                Administrator. It usually boils down to these three things:

                #1) Respect the privacy of others.
                #2) Think before you type.
                #3) With great power comes great responsibility.

                sudo: no tty present and no askpass program specified


                Ty Hamardaban i appreciate your tips.

                Comment

                • dade
                  Member
                  • Jan 2021
                  • 34

                  #10
                  update, i tried again the modbus.get e now a got this:

                  2021/04/05 13:00:37.000729 check 'modbus.get["rtu://dev/ttyUSB0:9600:8n1",1,4,30001,1,int8,le,4]' is not supported: Unable to connect: permission denied

                  So it looks like I have to give zabbix some specific permission

                  Comment

                  • dade
                    Member
                    • Jan 2021
                    • 34

                    #11
                    UPDATE: SOLVED

                    I did: sudo usermod -a -G dialout zabbix

                    So modbus.get worked!!! Thanks Hamardaban

                    although i would like to understand why i cant execute my python script through zabbix item.

                    Comment

                    • Spectator
                      Member
                      • Sep 2021
                      • 71

                      #12
                      Originally posted by dade
                      UPDATE: SOLVED

                      I did: sudo usermod -a -G dialout zabbix

                      So modbus.get worked!!! Thanks Hamardaban

                      although i would like to understand why i cant execute my python script through zabbix item.
                      Dear dade,
                      This post was a great help to me!
                      I would write this one line in CAPITAL LETTERS in the Zabbix Modbus documentation!
                      Thanks again!

                      Comment

                      Working...