Ad Widget

Collapse

Python script error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcombar
    Junior Member
    • Nov 2021
    • 5

    #1

    Python script error

    Hi all, I have a problem with running a python script. The script from the shell works correctly, while from Zabbix it gives me the error:

    Value of type "string" is not suitable for value type "Numeric (unsigned)". Value "Traceback (most recent call last):
    File "/usr/lib/zabbix/externalscripts/PLC_UPS_modbus.py", line 4, in <module>
    from pymodbus.client.sync import ModbusTcpClient
    ImportError: No module named pymodbus.client.sync

    The script is as follows:
    __________________________________________________ ____________________
    #! / Usr / bin / env python
    import sys
    from pymodbus.client.sync import ModbusTcpClient
    from pprint import pprint

    # area of ​​the plc straight without crowding

    bit_place = []
    bit_place = [15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0]

    def readArea (ipaddress, area, bit):
    client = ModbusTcpClient (ipaddress)
    client.connect ()
    request = client.read_holding_registers (int (area), 2, unit = 1)
    value = '% s'% format (request.registers [0], '016b')
    if bit == 'all':
    pprint (value)
    else:
    print (value [bit_place [int (bit)]])

    if __name__ == '__main__':

    if len (sys.argv) == 4:
    ipaddress = sys.argv [1]
    area = sys.argv [2]
    bit = sys.argv [3]
    readArea (ipaddress, area, bit)
    else:
    #print u "" "requires 3 parameters (ipaddress, area, bit) \ t $" ""
    print ("error")
    __________________________________________________ ____________________

    If you run it from the terminal:

    root @ stf-isonoe-01: / usr / lib / zabbix / externalscripts # ./PLC_UPS_modbus.py 172.22.1.130 10003 04
    result: 0 (OK)

    The item is configured in several ways, but all of them give an error (see attached photo).

    Where is the mistake?
    Thank you very much all.




Working...