RandomReaper / weewx-zabbix

weewx plugin to push weather data to zabbix
Apache License 2.0
4 stars 3 forks source link

memoryview: a bytes-like object is required, not 'str' #6

Closed HoracioDos closed 3 years ago

HoracioDos commented 3 years ago

Hello. Zabbix extension fails to run.

Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: loop data:
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_usUnits 16
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_dateTime 1608039616
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_inHumidity 46.0
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_inTemp 26.200000000000003
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_outHumidity 71.0
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_outTemp 20.200000000000003
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_pressure 1010.8000000000001
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_windSpeed 7.2
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_windGust 9.72
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_windDir 225.0
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_rain None
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_radiation 228.18595
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_UV 2.0
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_status 0
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_ptr 42176
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_delay 18
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_rxCheckPercent 100
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_outTempBatteryStatus 0
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_rainTotal 7.739999999999999
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_altimeter 1010.8909740144559
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_appTemp 20.332427851579602
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_barometer 1010.8000000000001
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_beaufort 1
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_cloudbase 662.3046501766602
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_dewpoint 14.767697700714633
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_heatindex 20.129444444444452
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_humidex 24.02561521575064
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_inDewpoint 13.652460445809679
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_maxSolarRad 942.3936622272251
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_rainRate 0.0
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_windchill 20.200000000000006
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: pi2weewx weewx_windGustDir None
Dec 15 10:40:16 pi2weewx /weewxd[16646]: zabbix: command line : ['/usr/bin/zabbix_sender', '-z', 'XXX.XXX.XXX.XXX', '-i', '-']
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] INFO weewx.engine: Main loop exiting. Shutting engine down.
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] DEBUG weewx.restx: Shut down WeatherCloud thread.
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] DEBUG weewx.restx: Shut down Windy thread.
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] DEBUG weewx.restx: Shut down PWSWeather thread.
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] DEBUG weewx.restx: Shut down Wunderground-RF thread.
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__: Caught unrecoverable exception:
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****  memoryview: a bytes-like object is required, not 'str'
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****  Traceback (most recent call last):
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****    File "/usr/share/weewx/weewxd", line 154, in main
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****      engine.run()
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 206, in run
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****      self.dispatchEvent(weewx.Event(weewx.NEW_LOOP_PACKET, packet=packet))
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 241, in dispatchEvent
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****      callback(event)
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****    File "/usr/share/weewx/user/zabbix.py", line 90, in loop
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****      sender_stdout = p.communicate(input=s)[0]
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****    File "/usr/lib/python3.7/subprocess.py", line 939, in communicate
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****      stdout, stderr = self._communicate(input, endtime, timeout)
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****    File "/usr/lib/python3.7/subprocess.py", line 1666, in _communicate
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****      input_view = memoryview(self._input)
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****  TypeError: memoryview: a bytes-like object is required, not 'str'
Dec 15 10:40:16 pi2weewx python3[16646]: weewx[16646] CRITICAL __main__:     ****  Exiting.

Thanks

RandomReaper commented 3 years ago

Thank you for the report,

I currently quite overbooked, but if you could try to replace the line 90 from: sender_stdout = p.communicate(input=s)[0] to sender_stdout = p.communicate(input=s.encode())[0]

HoracioDos commented 3 years ago

Hello. I changed lines 89 and 91. It seems to work with: universal_newlines=True and text = True

        p = Popen(c, universal_newlines=True ,stdout=PIPE, stdin=PIPE, stderr=STDOUT)
        ...
        loginf(self.zabbix_sender + " result: " +sender_stdout)

I get this out output but it seems to be other problem. I test zabbix-sender manually

Dec 15 11:59:56 pi2weewx /weewxd[26457]: zabbix: /usr/bin/zabbix_sender result: Response from "XXX.XXX.XXX.XXX:10051": "processed: 0; failed: 32; total: 32; seconds spent: 0.000570"
                                         sent: 32; skipped: 0; total: 32
RandomReaper commented 3 years ago

If I remember correctly, processed 0 is because the item does not exists in zabbix.

You just masked the line I was asking you to change? I don't even know what you tested...

HoracioDos commented 3 years ago

Hello: I tested what I answered before. I inserted universal_newlines=True in popen() in line 89, It also works with text= True and I removed decode() in line 91. I will test your change later.

        p = Popen(c, universal_newlines=True ,stdout=PIPE, stdin=PIPE, stderr=STDOUT)
        ...
        loginf(self.zabbix_sender + " result: " +sender_stdout)

Zabbix items were already created. I'll build a template if I have the time. I know why zabbix_sender is not working. I use PSK to cypher agent to server communication. I will add the config file that it is needed -c /etc/zabbix/zabbix_agentd.conf

HoracioDos commented 3 years ago

Thank you for the report,

I currently quite overbooked, but if you could try to replace the line 90 from: sender_stdout = p.communicate(input=s)[0] to sender_stdout = p.communicate(input=s.encode())[0]

Your solution works fine. I added the config file parameter. It's working now with PSK. I'm trying to figure out why zabbix_sender runs 3 times each time. What's the units for send_internal? Thanks!

RandomReaper commented 3 years ago

Fixed for python3 in 7ca4c9f6dbf11daf6617a94e8df3c67cc1e972a5.

RandomReaper commented 3 years ago

I think, but you should verify, the units are the same as the internal zabbix units (see http://weewx.com/docs/customizing.htm#Changing_the_unit_system).

HoracioDos commented 3 years ago

Hello! I think Send_interval parameter is in seconds. As far as I understand, time difference result in your code (line 77) is in seconds. Is that correct? Thanks!

HoracioDos commented 3 years ago

Send_Interval = 290 seconds works fine if I want to send values just once in the packet loop. This way matches with the archive interval.

Dec 17 14:56:02 pi2weewx python3[24347]: weewx[24347] INFO weewx.manager: Added record 2020-12-17 14:55:00 -03 (1608227700) to database 'weewx.sdb'
Dec 17 14:56:02 pi2weewx python3[24347]: weewx[24347] INFO weewx.manager: Added record 2020-12-17 14:55:00 -03 (1608227700) to daily summary in 'weewx.sdb'
Dec 17 15:01:04 pi2weewx python3[24347]: weewx[24347] INFO user.zabbix: Response from "xxx.xxx.xxx.xxx:10051": "processed: 32; failed: 0; total: 32; seconds spent: 0.001104" sent: 32; skipped: 0; total: 32
Dec 17 15:01:04 pi2weewx python3[24347]: weewx[24347] INFO weewx.manager: Added record 2020-12-17 15:00:00 -03 (1608228000) to database 'weewx.sdb'
Dec 17 15:01:04 pi2weewx python3[24347]: weewx[24347] INFO weewx.manager: Added record 2020-12-17 15:00:00 -03 (1608228000) to daily summary in 'weewx.sdb'
Dec 17 15:06:06 pi2weewx python3[24347]: weewx[24347] INFO user.zabbix: Response from "xxx.xxx.xxx.xxx:10051": "processed: 32; failed: 0; total: 32; seconds spent: 0.001014" sent: 32; skipped: 0; total: 32
Dec 17 15:06:06 pi2weewx python3[24347]: weewx[24347] INFO weewx.manager: Added record 2020-12-17 15:05:00 -03 (1608228300) to database 'weewx.sdb'
Dec 17 15:06:06 pi2weewx python3[24347]: weewx[24347] INFO weewx.manager: Added record 2020-12-17 15:05:00 -03 (1608228300) to daily summary in 'weewx.sdb'
Dec 17 15:11:14 pi2weewx python3[24347]: weewx[24347] INFO user.zabbix: Response from "xxx.xxx.xxxx.xxx:10051": "processed: 32; failed: 0; total: 32; seconds spent: 0.000860" sent: 32; skipped: 0; total: 32