{"id":15331950,"url":"https://github.com/slachiewicz/zabbix-haproxy","last_synced_at":"2025-10-10T02:31:28.923Z","repository":{"id":85555932,"uuid":"49426299","full_name":"slachiewicz/zabbix-haproxy","owner":"slachiewicz","description":"HAProxy Zabbix Discovery and Template","archived":false,"fork":true,"pushed_at":"2024-07-28T22:30:26.000Z","size":99,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-27T18:42:27.519Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"anapsix/zabbix-haproxy","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slachiewicz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-11T12:53:50.000Z","updated_at":"2024-07-28T22:30:31.000Z","dependencies_parsed_at":"2023-03-17T15:45:34.832Z","dependency_job_id":null,"html_url":"https://github.com/slachiewicz/zabbix-haproxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/slachiewicz/zabbix-haproxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slachiewicz%2Fzabbix-haproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slachiewicz%2Fzabbix-haproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slachiewicz%2Fzabbix-haproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slachiewicz%2Fzabbix-haproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slachiewicz","download_url":"https://codeload.github.com/slachiewicz/zabbix-haproxy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slachiewicz%2Fzabbix-haproxy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002542,"owners_count":26083400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T09:57:18.396Z","updated_at":"2025-10-10T02:31:28.627Z","avatar_url":"https://github.com/slachiewicz.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"HAProxy Zabbix Discovery and Template\n=====================================\n\n[Zabbix](http://zabbix.com) is a powerful open-source monitoring platform, capable of monitoring anything and everything, with the right configuration.\nZabbix's powerful Discovery capability is awesome, making it possible to automatically register hosts as they come online or monitor database servers without having to add individual databases and tables one by one.\nThis repo contains everything you need to discover and monitor HAProxy frontends, backends and backend servers.\n\n[HAProxy](http://www.haproxy.org/) is an awesome multi-purpose load-balancer.\n\n\u003e HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications.\n\u003e It is particularly suited for very high traffic web sites and powers quite a number of the world's most visited ones. Over the years it has become the de-facto standard opensource load balancer, is now shipped with most mainstream Linux distributions, and is often deployed by default in cloud platforms.\n\n### Latest / Changelog\n\n* [01/20/2017]: replaced single XML template with two - one for Zabbix v2 and another for v3\n* [09/08/2015]: now all stats are retrieved via `haproxy_stats.sh` script, which caches the stats for 5 minutes (by default) to avoid hitting HAProxy stats socket too much.\n\n### Prerequisites\n\n* Zabbix Server \u003e= 2.x (tested on 2.2 and 2.4)\n* Zabbix Frontend \u003e= 2.x\n* HAProxy \u003e= 1.3\n* Socat (when using sockets) or nc (when accessing haproxy status via tcp connection)\n\n### Instructions\n\n* Place `userparameter_haproxy.conf` into `/etc/zabbix/zabbix_agentd.d/` directory, assuming you have Include set in `zabbix_agend.conf`, like so:\n```\n### Option: Include\n# You may include individual files or all files in a directory in the configuration file.\n# Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.\n#\n# Mandatory: no\n# Default:\nInclude=/etc/zabbix/zabbix_agentd.d/\n```\n* Place `haproxy_discovery.sh` into `/usr/local/bin/` directory and make sure it's executable (`sudo chmod +x /usr/local/bin/haproxy_discovery.sh`)\n* Import appropriate `haproxy_zbx_v2_template.xml` or `haproxy_zbx_v3_template.xml` template via Zabbix Web UI interface (provided by `zabbix-frontend-php` package)\n* Configure HAProxy control socket\n  - [Configure HAProxy](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#9.2) to listen on `/var/run/haproxy/info.sock`\n  - or set custom socket path in checks (set `{$HAPROXY_SOCK}` template macro to your custom socket path)\n  - or update `userparameter_haproxy.conf` and `haproxy_discovery.sh` with your socket path\n* Customize your HAProxy config file location via `{$HAPROXY_CONFIG}` template macro, if necessary\n```\n# haproxy.conf snippet\n# haproxy read-only non-admin socket\n## (user level permissions are required, admin level will work as well, though not necessary)\nglobal\n  # default usage, through socket\n  stats socket /var/run/haproxy/info.sock  mode 666 level user\n  ## alternative usage, using tcp connection (useful e.g. when haproxy runs inside a docker and zabbix-agent in another)\n  ## replace socket path by ip:port combination on both scripts when using this approach, e.g. 172.17.0.1:9000\n  #stats socket *:9000\n\n```\n\n\u003e**MAKE SURE TO HAVE APPROPRIATE PERMISSIONS ON HAPROXY SOCKET**\n\u003eYou can specify what permissions a stats socket file will be created with in `haproxy.cfg`. When using non-admin socket for stats, it's _mostly_ safe to allow very loose permissions (0666).\n\u003eYou can even use something more restrictive like 0660, as long as you add Zabbix Agent's running user (usually \"zabbix\") to the HAProxy group (usually \"haproxy\").\n\u003eThis way you don't have to prepend `socat` with `sudo` in `userparameter_haproxy.conf` to make sure Zabbix Agent can access the socket. And you don't have to create `/etc/sudoers` entry for Zabbix. And don't need to remember to make it restrictive, avoiding all implication of misconfiguring use of SUDO.\n\u003eThe symptom of permissions problem on the socket is the following error from Zabbix Agent:\n\u003e`Received value [] is not suitable for value type [Numeric (unsigned)] and data type [Decimal]`\n\n* Verify on server with HAProxy installed:\n```\nanapsix@lb1:~$ sudo zabbix_agentd -t haproxy.list.discovery[FRONTEND]\n  haproxy.list.discovery[FRONTEND]              [t|{\"data\":[{\"{#FRONTEND_NAME}\":\"http-frontend\"},{\"{#FRONTEND_NAME}\":\"https-frontend\"}]}]\n\nanapsix@lb1:~$ sudo zabbix_agentd -t haproxy.list.discovery[BACKEND]\n  haproxy.list.discovery[BACKEND]               [t|{\"data\":[{\"{#BACKEND_NAME}\":\"www-backend\"},{\"{#BACKEND_NAME}\":\"api-backend\"}]}]\n\nanapsix@lb1:~$ sudo zabbix_agentd -t haproxy.list.discovery[SERVERS]\n  haproxy.list.discovery[SERVERS]               [t|{\"data\":[{\"{#BACKEND_NAME}\":\"www-backend\",\"{#SERVER_NAME}\":\"www01\"},{\"{#BACKEND_NAME}\":\"www-backend\",\"{#SERVER_NAME}\":\"www02\"},{\"{#BACKEND_NAME}\":\"www-backend\",\"{#SERVER_NAME}\":\"www03\"},{\"{#BACKEND_NAME}\":\"api-backend\",\"{#SERVER_NAME}\":\"api01\"},{\"{#BACKEND_NAME}\":\"api-backend\",\"{#SERVER_NAME}\":\"api02\"},{\"{#BACKEND_NAME}\":\"api-backend\",\"{#SERVER_NAME}\":\"api03\"}]}]\n```\n\n* Add hosts with HAProxy installed to just imported Zabbix HAProxy template.\n* Wait for discovery.. Frontend(s), Backend(s) and Server(s) should show up under Host Items.\n   An easy way to see all data is via _Overview_ (make sure to pick right Group, one of the \"HAProxy\" applications and select _Data_ as Type)\n\n\n### Troubleshooting\n\n#### Security\nSELinux might be preventing the check from using the socket.\n```\n# check your audit logs\n$ tail -f /var/log/audit/audit.log\n\n# get more details\n$ tail -n100 -f /var/log/audit/audit.log | audit2why\n\n# look for haproxy related messages\n$ tail -n100 -f /var/log/audit/audit.log | grep haproxy | audit2why\n```\n\nYou can try temporarily disabling SELinux, while testing. It's up to you to re-enable it.\n```\n# disable SELinux, make sure to re-enable it, if you are relying on SELinux\n$ setenforce 0\n```\n\n#### Discover\n```\n/usr/local/bin/haproxy_discovery.sh $1 $2\n$1 is a path to haproxy socket\n$2 is FRONTEND or BACKEND or SERVERS\n\n# /usr/local/bin/haproxy_discovery.sh /var/run/haproxy/info.sock FRONTEND    # second argument is optional\n# /usr/local/bin/haproxy_discovery.sh /var/run/haproxy/info.sock BACKEND     # second argument is optional\n# /usr/local/bin/haproxy_discovery.sh /var/run/haproxy/info.sock SERVERS     # second argument is optional\n```\n\n#### haproxy_stats.sh script\n```\n## Usage: haproxy_stats.sh $1 $2 $3 $4\n### $1 is a path to haproxy socket - optional, defaults to /var/run/haproxy/info.sock\n### $2 is a name of the backend, as set in haproxy.cfg\n### $3 is a name of the server, as set in haproxy.cfg\n### $4 is a stat as references by HAProxy terminology\n# haproxy_stats.sh /var/run/haproxy/info.sock www-backend www01 status\n# haproxy_stats.sh www-backend BACKEND status\n# haproxy_stats.sh https-frontend FRONTEND status\n```\n\n\u003e For the list of stats HAProxy supports as of version 1.5\n\u003e see TEXT: http://www.haproxy.org/download/1.5/doc/configuration.txt\n\u003e see HTML: http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#9.1\n\n#### Stats\n```\n## Bytes In:      echo \"show stat\" | socat $1 stdio | grep \"^$2,$3\" | cut -d, -f9\n## Bytes Out:     echo \"show stat\" | socat $1 stdio | grep \"^$2,$3\" | cut -d, -f10\n## Session Rate:  echo \"show stat\" | socat $1 stdio | grep \"^$2,$3\" | cut -d, -f5\n### $1 is a path to haproxy socket\n### $2 is a name of the backend, as set in haproxy.cfg\n### $3 is a name of the server, as set in haproxy.cfg\n# echo \"show stat\" | socat /var/run/haproxy/info.sock stdio | grep \"^www-backend,www01\" | cut -d, -f9\n# echo \"show stat\" | socat /var/run/haproxy/info.sock stdio | grep \"^www-backend,BACKEND\" | cut -d, -f10\n# echo \"show stat\" | socat /var/run/haproxy/info.sock stdio | grep \"^https-frontend,FRONTEND\" | cut -d, -f5\n# echo \"show stat\" | socat /var/run/haproxy/info.sock stdio | grep \"^api-backend,api02\" | cut -d, -f18 | cut -d\\  -f1\n```\n\n#### More\nTake a look at the out put of the following to learn more about what is available though HAProxy socket\n```\necho \"show stat\" | socat /var/run/haproxy/info.sock stdio\n```\n\n### License\n\n[MIT License](http://opensource.org/licenses/MIT)\n\n    The MIT License (MIT)\n\n    Copyright (c) 2015-2020 \"Anastas Dancha \u003canapsix@random.io\u003e\"\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslachiewicz%2Fzabbix-haproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslachiewicz%2Fzabbix-haproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslachiewicz%2Fzabbix-haproxy/lists"}