{"id":13779608,"url":"https://github.com/zabbix-tools/zabbix-module-python","last_synced_at":"2026-03-11T10:36:11.520Z","repository":{"id":79498710,"uuid":"69144653","full_name":"zabbix-tools/zabbix-module-python","owner":"zabbix-tools","description":"Embedded Python interpreter module for Zabbix","archived":false,"fork":false,"pushed_at":"2018-09-11T18:19:23.000Z","size":48,"stargazers_count":33,"open_issues_count":8,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-05-18T21:39:44.404Z","etag":null,"topics":["python","zabbix","zabbix-loadable"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zabbix-tools.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-25T04:58:04.000Z","updated_at":"2023-08-25T19:04:38.000Z","dependencies_parsed_at":"2023-04-08T07:46:58.023Z","dependency_job_id":null,"html_url":"https://github.com/zabbix-tools/zabbix-module-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabbix-tools%2Fzabbix-module-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabbix-tools%2Fzabbix-module-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabbix-tools%2Fzabbix-module-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabbix-tools%2Fzabbix-module-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zabbix-tools","download_url":"https://codeload.github.com/zabbix-tools/zabbix-module-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224713624,"owners_count":17357247,"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","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":["python","zabbix","zabbix-loadable"],"created_at":"2024-08-03T18:01:07.006Z","updated_at":"2024-11-17T15:30:33.474Z","avatar_url":"https://github.com/zabbix-tools.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# zabbix-module-python\n\nEmbedded Python interpreter module for Zabbix.\n\nThis [native Zabbix module](https://www.zabbix.com/documentation/3.2/manual/config/items/loadablemodules)\nallows you to write extensions for Zabbix in Python and run them embedded in the\nZabbix agent, server or proxy.\n\nWhy bother?\n\n* Extensions are much simpler to write and manage.\n  \n  The following is a working Zabbix module written in Python. It creates item\n  key `python.echo[]` which simply returns a string concatenation of each given\n  parameter:\n\n  ```python\n  import zabbix_module\n\n  def echo(request):\n    return \" \".join(request.params)\n\n  def zbx_module_item_list():\n    return [\n      zabbix_module.AgentItem(\"python.echo\", fn = echo, test_param = [ 'hello', 'world' ]),\n    ]\n\n  ```\n\n  It works like this:\n\n  ```\n  $ zabbix_agentd -t python.echo[hello,world]\n  zabbix_agentd [19]: loaded python modules: dummy.py\n  python.echo[hello,world]                      [s|hello world]\n  ```\n\n* The embedded interpreter outperforms User Parameter scripts by an order of\n  magnitude with a lower memory footprint\n\n* Maintaining state between requests, working with threads or watching resources\n  is much simpler in a long lived, shared library context than in on-demand\n  script calls\n\n\n## Requirements\n\nThis project is immature and pre-release. \n\nFor now, testing has only been completed with the following prerequisites:\n\n* Debian Jessie\n* Zabbix Agent v3.2\n* Python v3.4\n\n\n## Installation\n\nThis project is immature and pre-release. \n\nDownload [source tarball here](http://s3.cavaliercoder.com/libzbxpython/libzbxpython-1.0.0.tar.gz).\n\n* Build configure scripts\n\n  ```\n  ./autogen.sh\n  ```\n* Configure module sources with the desired Python version, the location of\n  Zabbix sources and the install location of the Zabbix configuration directory\n\n  ```\n  $ PYTHON_VERSION=3 ./configure \\\n                        --libdir=/usr/lib/zabbix/modules \\\n                        --with-zabbix=/usr/src/zabbix-3.2.0 \\\n                        --with-zabbix-conf=/etc/zabbix\n  ```\n\n* Compile the module binary\n  \n  ```\n  $ make\n  ```\n\n* Install the Zabbix and Python modules\n  \n  ```\n  $ make install\n  ```\n\n## Usage\n\nSee `dummy.py` for a fully functioning example.\n\n* Python modules need to be installed in a `python` subdirectory of the Zabbix\n  module directory (default: `/usr/lib/zabbix/modules/python3`)\n\n* Start your Python module with `import zabbix_module`\n\n* If you need to initialize any globals or threads before Zabbix forks, you may\n  do this by implementing `zbx_module_init`:\n\n  ```python\n  def zbx_module_init():\n    zabbix_module.info(\"Initalized my module\")\n  ```\n\n* Create handler functions for each item you wish to create. These funtions\n  should accept a single `request` parameter and must return either a positive\n  integer, a double or a string with less than 255 characters\n\n  ```python\n  def my_handler(request):\n    return 'hello world'\n  ```\n\n  The `request` parameter is an `AgentRequest` object and exposes the requested\n  key and parameters.\n\n* Register your item handlers by implementing `zbx_module_item_list`\n\n  ```python\n  def zbx_module_item_list():\n    return [\n      zabbix_module.AgentItem(\"my.item\", fn = my_handler)\n    ]\n  ```\n\n* For discovery rules, convert a `dict` into a JSON discovery string using\n  the `discovery` function:\n\n  ```python\n  def my_handler(request):\n    return zabbix_module.discovery( [ { 'id': 1 }, { 'id': 2 } ] )\n  ```\n\n* To send an error to Zabbix, simply raise an exception:\n  \n  ```python\n  def my_handler(request):\n    raise ValueError('Something went wrong')\n  ```\n\n* You can log messages to the Zabbix log file using any of the following\n  functions: `trace`, `debug`, `info`, `warning`, `error` or `critical`\n\n  ```python\n  def my_hander(request):\n    zabbix_module.info(\"Received request {0}\".format(request))\n\n    return 1\n\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzabbix-tools%2Fzabbix-module-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzabbix-tools%2Fzabbix-module-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzabbix-tools%2Fzabbix-module-python/lists"}