2

I am looking to send a few items to zabbix using Zabbix-Sender function of pyzabbix. As a test I am running the below code -

from pyzabbix import ZabbixMetric, ZabbixSender, ZabbixResponse
metrics = []
m= ZabbixMetric('mme01', 'TEST', 20)
metrics.append(m)
ZabbixSender('10.46.224.5').send(metrics)

I made this snippet after reading the document - https://py-zabbix.readthedocs.io/en/latest/sender.html

When I run the snippet I get the error -

AttributeError: 'ConnectionRefusedError' object has no attribute 'msg'

I have verified IP connectivity

Can Anyone help ?

rfguy
  • 149
  • 1
  • 3
  • 11
  • I decided to bypass the module - pyzabbix and decided to use the raw zabbix sender utility. Works great. – rfguy Dec 13 '18 at 19:42

3 Answers3

3

there is a mess in modules names.

it seems you call 'other' pyzabbix module who has not needed methods. first, remove all zabbix-related modules: pip list | grep zabbix; pip uninstall ...

and then install pyzabbix: pip install py-zabbix.

this should help.

UPDATED: I dug deeper and figured out that the AttributeError: 'ConnectionRefusedError' object has no attribute 'msg' exception caused by old module version bug, which has been fixed here. update it with pip or manually.

new bug I have faced is [Errno 8] nodename nor servname provided, or not known caused by socket lib and can be fixed pointing to zabbix server/proxy IP address instead of DNS name

2

I decided to bypass the module - pyzabbix and decided to use the raw zabbix sender utility. Works great.

For other folks my solution relies on a file with values that need to be sent to zabbix.

Sample file -

"mme01" TEST 1544729668 44

The use the utility -

/opt/zabbix-proxy/bin/zabbix_sender -vv -z 10.43.X.X -T  -i mme_file.txt

Replace with path of your zabbix_sender and the zabbix server IP.

rfguy
  • 149
  • 1
  • 3
  • 11
0

I had the same issue on some machines of mine. At that time I refactored my code to use zabbix_sender and it worked great.

After some time I found out the issue was related to pip repository corruption. I ended up reinstalling all the packages with this option:

pip install --ignore-installed <package>

apparently the issue was fixed, but I still have no idea why it occurred on some manchines and not in anothers.

Yennefer
  • 5,704
  • 7
  • 31
  • 44