dmitriy-myz / zabbix-templates

MIT License
9 stars 5 forks source link

How to connect Zabbix to script? #7

Closed TheLordDrake closed 4 years ago

TheLordDrake commented 4 years ago

Hi, I'm pretty new to Zabbix and Consul and I'm having some problems trying to figure out how to connect the two.

I have Consul and Zabbix running in docker containers on a Linux host. Based on your reply to another issue here I placed the python script in the /opts/scripts/ directory on my consul container. I've also installed the consul template and created a host using that template in zabbix with the IP of the Linux host machine (Consul container is using the host network)

I'm having a hard time figuring out how Zabbix is supposed to collect information from Consul. I did add the line from the .conf file to a zabbix agent's configuration. That agent is reporting other data, like Ping and CPU load. I'm unsure how to check if it's actually getting anything from consul though.

dmitriy-myz commented 4 years ago

Hi! As I understand you need to place script consul2zabbix.py to /opt/scripts/ directory of container there zabbix agent installed. In you case it can be easy to place in container with zabbix it it have zabbix agent. Also you need to change this line to match address of your consul agent http interface. https://github.com/dmitriy-myz/zabbix-templates/blob/master/consul2zabbix/consul2zabbix.py#L19

TheLordDrake commented 4 years ago

Hi, thanks for getting back to me so quickly. I have added the /opt/scripts/consul2zabbix.py script to my zabbix agent container, and updated that line to use the Linux host machine's IP address. (Consul's container is using the host network) I still don't seem to be getting anything back.

Let me break down my current setup for you a little more clearly, hopefully that will make this easier. I am running Zabbix Server, a Zabbix Agent, and Consul as docker containers on Ubuntu.

dmitriy-myz commented 4 years ago

Hm... Look like valid configuration. I guess I found reason why it not working. It assume that zabbix agent runned on same host as consul so it use current node hostname to pull info from consul. In you current configuration you can replace in line 19 consul url to match hostname of consul docker image url = 'http://consul_ip:8500/v1/health/node/node_name' node_name can be retrieved from consul api like this (in qoutes) curl -s consul_ip:8500/v1/catalog/nodes | grep Node

dmitriy-myz commented 4 years ago

I thought about full cluster monitoring using one consul endpoint, but didn't implement it. In my case it more clear to have consul and zabbix agent on same host.

TheLordDrake commented 4 years ago

I gave that a shot. I'm still not receiving anything on the Server's end. I ran the script manually and it does work, it's returning the correct values. So the script either isn't being run or its response isn't being picked up by the server. Also when I check the "Latest Data" section of Zabbix the field for Consul Status is grayed out. At this point I'm unsure if perhaps this is a configuration problem with Zabbix itself.

I figured out the issue. When the script was copied it wasn't given executable permission so the zabbix user couldn't run it. I ran added that permission to the python script and now data is coming through just fine. Thank you for the assistance! Would you mind if I opened a PR to update the installation instructions to include some of this new information?

dmitriy-myz commented 4 years ago

~I gave that a shot. I'm still not receiving anything on the Server's end. I ran the script manually and it does work, it's returning the correct values. So the script either isn't being run or its response isn't being picked up by the server. Also when I check the "Latest Data" section of Zabbix the field for Consul Status is grayed out. At this point I'm unsure if perhaps this is a configuration problem with Zabbix itself.~

I figured out the issue. When the script was copied it wasn't given executable permission so the zabbix user couldn't run it. I ran added that permission to the python script and now data is coming through just fine. Thank you for the assistance! Would you mind if I opened a PR to update the installation instructions to include some of this new information?

Yes, this would be great!

TheLordDrake commented 4 years ago

I have created a PR with the updates.