{"id":19458478,"url":"https://github.com/postgrespro/mamonsu","last_synced_at":"2025-04-08T08:11:54.723Z","repository":{"id":43057554,"uuid":"50690011","full_name":"postgrespro/mamonsu","owner":"postgrespro","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-05T16:39:57.000Z","size":40340,"stargazers_count":189,"open_issues_count":28,"forks_count":30,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-04-01T05:38:09.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/postgrespro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-29T20:42:24.000Z","updated_at":"2025-03-05T14:58:24.000Z","dependencies_parsed_at":"2023-01-30T00:30:59.230Z","dependency_job_id":"1a01fb95-1937-4dd6-bd22-573852e20260","html_url":"https://github.com/postgrespro/mamonsu","commit_stats":{"total_commits":1216,"total_committers":25,"mean_commits":48.64,"dds":0.6710526315789473,"last_synced_commit":"fd75eb02d15732a1f9429653d6e4045ae604da5b"},"previous_names":[],"tags_count":143,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fmamonsu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fmamonsu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fmamonsu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postgrespro%2Fmamonsu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postgrespro","download_url":"https://codeload.github.com/postgrespro/mamonsu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801170,"owners_count":20998339,"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":[],"created_at":"2024-11-10T17:27:15.388Z","updated_at":"2025-04-08T08:11:54.705Z","avatar_url":"https://github.com/postgrespro.png","language":"Python","funding_links":[],"categories":["Compiled list","Monitoring/Statistics/Perfomance"],"sub_categories":["plv8:","Zabbix"],"readme":"# mamonsu: monitoring agent for PostgreSQL\n_mamonsu_ is an active agent for collecting PostgreSQL instance and operating system metrics that can interact with Zabbix.\n***\n## Build status\n\u003cimg alt=\"\" src=\"documentation/images/mamonsu_header.png\" align=\"right\" /\u003e\n\n![Build Status](https://github.com/postgrespro/mamonsu/actions/workflows/mamonsu-tests-master.yml/badge.svg)\n***\n## License\nDevelopment version, available on GitHub, released under BSD 3-clause.\n***\n## Compatibility\nPython 3.3+  \n\nSupported platforms:\n- Linux;\n- FreeBSD;\n- Windows;\n\nSupported Zabbix server versions: 4.0.44 - 6.4.13\n\nSupported PostgreSQL versions: 12 - 17\n***\n\n***Table of Contents***\n- [mamonsu: concepts](#mamonsu-concepts)\n- [Requirements](#requirements)\n- [Features](#features)\n  - [Metrics](#metrics)\n  - [Zabbix Screens](#zabbix-screens)\n  - [Tools](#tools)\n- [Build](#build)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Configuration](#configuration)\n  - [Template creation and upload](#template-creation-and-upload)\n  - [Run](#run)\n  - [Template update](#template-update)\n  - [Best practices](#best-practices)\n- [Additional chapters](#additional-chapters)\n\n## mamonsu: concepts\nBased by Zabbix, _mamonsu_ provides an extensible cross-platform solution that can collect and visualize multiple PostgreSQL/PostgresPro and system metrics. _mamonsu_ has about 90 PostgreSQL metrics and about 40 system metrics. The agent collects [metrics](documentation/metrics.md) such as database availability, number of connections, locks, WAL problems, checkpoints, background writer activity, memory problems and many others. Unlike many monitoring agents configured to collect PostgreSQL metrics, _mamonsu_ uses a single database connection, which minimizes performance impact on the monitored system. _mamonsu_ also contains a number of [tools](documentation/tools.md) for interacting with the Zabbix API, obtaining system information and information about collected metrics.    \n_mamonsu_ is written entirely in Python 3 and has a plugin architecture. It is an active agent, which means that it sends the data to the Zabbix server once it is collected. Pre-configured to monitor multiple PostgreSQL and system metrics out of the box, _mamonsu_ can be extended with your own [custom plugins](documentation/adding_custom_plugins.md) to track other metrics crucial for your system.  \n_mamonsu_ can be installed on the same server where the DBMS we are going to monitor is located or on remote server, but:  \n\u003e **_NOTE:_**  While _mamonsu_ can collect PostgreSQL metrics from a remote server, system metrics are only collected locally. If you choose to collect PostgreSQL metrics remotely, make sure to disable collection of system metrics to avoid confusion, as they will be displayed under the same host in Zabbix.\n \nA template generated by _mamonsu_ must be bound to the Zabbix host to receive and display metrics.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=\"640\" alt=\"mamonsu default scheme\" src=\"documentation/images/mamonsu_default_scheme.png\" /\u003e\n\u003c/p\u003e\n\n_mamonsu_ can be easily customized. You can configure such parameters as the data collection interval for each plugin (by default it is 60 seconds), the size of the message queue for the Zabbix server, optionally disable/enable various components.\n\n## Requirements\nOnly Python3.3+ and any text editor.\n\n## Features\n### Metrics\n_mamonsu_ by default has 3 plugin groups and all of them are active:\n- **common:** _mamonsu_ own metrics such as availability, plugin errors;\n- **system:** contains *nix and windows metric sets. For example, on UNIX-based platforms you can collect specific metrics such as load average, open files count, CPU nice/idle/system time, etc.;\n- **pgsql:** PostgreSQL/PostgresPro specific metrics;\n\n\u003cp align=\"center\"\u003e\n    \u003cimg width=\"640\" alt=\"mamonsu PG metrics\" src=\"documentation/images/mamonsu_PG_plugins.png\" /\u003e\n\u003c/p\u003e\n\n_mamonsu_ not only collects metrics, but provides triggers and graphs.     \nSee details in chapter called \"[Metrics](documentation/metrics.md)\".\n### Zabbix Screens\nSince _mamonsu_ **_3.0_** template contains screens:\n- Overview  \n  Contains graphs representing general important metrics: PostgreSQL connections, shared buffers size and usage, autovacuum, tuples, checkpoint, background worker, system CPU and memory.\n    \u003cdetails\u003e\n        \u003csummary\u003eClick to view\u003c/summary\u003e\n        \u003cimg src=\"documentation/images/mamonsu_overview.png\" alt=\"mamonsu Overview\"/\u003e\n    \u003c/details\u003e\n\n\n- PostgreSQL Instance  \n  Contains information about Instance availability\n    \u003cdetails\u003e\n        \u003csummary\u003eClick to view\u003c/summary\u003e\n        \u003cimg src=\"documentation/images/mamonsu_pg_instance.png\" alt=\"mamonsu PostgreSQL Instance\"/\u003e\n    \u003c/details\u003e\n\n\n- PostgreSQL Locks\n    \u003cdetails\u003e\n        \u003csummary\u003eClick to view\u003c/summary\u003e\n        \u003cimg src=\"documentation/images/mamonsu_pg_locks.png\" alt=\"mamonsu PostgreSQL Locks\"/\u003e\n    \u003c/details\u003e\n\n\n- PostgreSQL Transactions  \n    \u003cdetails\u003e\n        \u003csummary\u003eClick to view\u003c/summary\u003e\n        \u003cimg src=\"documentation/images/mamonsu_pg_transactions.png\" alt=\"mamonsu PostgreSQL Transactions\"/\u003e\n    \u003c/details\u003e\n\n\n- PostgreSQL WAL  \n  Contains information about WAL size, archiving\n    \u003cdetails\u003e\n        \u003csummary\u003eClick to view\u003c/summary\u003e\n        \u003cimg src=\"documentation/images/mamonsu_pg_wal.png\" alt=\"mamonsu PostgreSQL WAL\"/\u003e\n    \u003c/details\u003e\n\n\n- System  \n  Contains information about state of the system\n    \u003cdetails\u003e\n        \u003csummary\u003eClick to view\u003c/summary\u003e\n        \u003cimg src=\"documentation/images/mamonsu_system.png\" alt=\"mamonsu System\"/\u003e\n    \u003c/details\u003e\n\n\n- mamonsu Dashboard (*only for Zabbix 6.0+*)  \n  Pretty dashboard containing all necessary PostgreSQL and system information.\n    \u003cdetails\u003e\n        \u003csummary\u003eClick to view\u003c/summary\u003e\n        \u003cimg src=\"documentation/images/mamonsu_dashboard.png\" alt=\"mamonsu Dashboard\"/\u003e\n    \u003c/details\u003e\n\n\n### Tools\n_mamonsu_ provides the command-line interface for updating some Zabbix server settings, as well as getting an overview of the monitored system configuration and tuning PostgreSQL and system settings on the fly. Also it provides tool to generate a detailed report on the hardware, operating system, memory usage and other parameters of the monitored system. List of _mamonsu_ commands and options:  \n\n    mamonsu agent [agent_action] [-c | --config]  \n    mamonsu bootstrap [-M mamonsu_user] [-x | --create-extensions] [-c | --config] [connection_options]  \n    mamonsu export {template | config} filename [export_options]  \n    mamonsu report [report_options] [connection_options]  \n    mamonsu tune [tuning_options] [connection_options]  \n    mamonsu upload [upload_options]  \n    mamonsu zabbix {template | host | hostgroup} server_action  \n    mamonsu zabbix item {error | lastvalue | lastclock} host_id  \n    mamonsu zabbix dashboard upload [template_name]  \n    mamonsu zabbix version  \n    mamonsu --version  \n    mamonsu --help\n\nFor all details, see the chapter called “[Tools](documentation/tools.md)\".\n## Build\n**Build deb:**\n```shell\n$ apt-get install make dpkg-dev debhelper python3-dev python3-setuptools\n$ git clone ... \u0026\u0026 cd mamonsu \u0026\u0026 make deb \u0026\u0026 dpkg -i mamonsu*.deb\n```  \n**Build rpm:**  \n```shell\n$ yum install make rpm-build python3-devel python3-setuptools\n$ git clone ... \u0026\u0026 cd mamonsu \u0026\u0026 make rpm \u0026\u0026 rpm -i mamonsu*.rpm\n```  \n**Build win32 exe:**  \n```shell\n$ git clone ... \u0026\u0026 cd mamonsu \u0026\u0026 py setup_win32.py py2exe\n$ copy dist\\mamonsu.exe c:\\mamonsu\n$ copy dist\\service_win32.exe c:\\mamonsu\n$ c:\\mamonsu\\mamonsu.exe -w c:\\mamonsu\\agent.conf\n$ c:\\mamonsu\\service_win32.exe -install\n$ net start mamonsu\n```\nor\n```shell\n$ pyinstaller --onefile mamonsu_win32.spec\n$ pyinstaller --onefile service_win32.spec\n```  \n**Build NSIS installer:**  \n```shell\n$ git clone ... \u0026\u0026 cd mamonsu \u0026\u0026 py setup_win32.py py2exe\n$ makensis packaging\\win\\mamonsu.nsis\n```\n\n## Installation\nTo use _mamonsu_, you must create a Zabbix account and set up a Zabbix server as explained in [Zabbix documentation](https://www.zabbix.com/documentation/current/). Naturally, you must also have a PostgreSQL instance up and running if you are going to monitor PostgreSQL metrics.  \nPre-built _mamonsu_ packages are provided in official Postgres Pro repository: [repo/mamonsu](https://repo.postgrespro.ru/mamonsu/)  \n\n**Install from repository using script:**  \n```shell\n$ wget https://repo.postgrespro.ru/mamonsu/keys/pgpro-repo-add.sh\n$ sudo chmod 700 ./pgpro-repo-add.sh\n$ sudo ./pgpro-repo-add.sh\n```   \n\nInstall package   \n- for RH-like:  \n  ```shell\n  $ yum install mamonsu\n  ```  \n- for SLES:\n  ```shell\n  $ zypper install mamonsu\n  ```  \n- for Debian, Ubuntu, AltLinux, AltlLinux-spt:\n  ```shell\n  $ apt-get update\n  $ apt-get install mamonsu\n  ```  \n**For Windows:**  \nPre-Build packages for Windows: [Windows installer](https://repo.postgrespro.ru/mamonsu/win/)  \n\n**Build and install from source code:**\n```shell\ngit clone ... \u0026\u0026 cd mamonsu \u0026\u0026 python3 setup.py build \u0026\u0026 python3 setup.py install\n```  \n\n## Usage\n### Configuration\n1. **Optionally, bootstrap _mamonsu_**  \nIf you omit this step, metrics can only be collected on behalf of a superuser, which is not recommended.\n   - Create a non-privileged database user for _mamonsu_. For example:\n   ```sql\n   CREATE USER mamonsu_user WITH PASSWORD 'mamonsu_password';\n   ```\n   - Create a database that will be used for connection to PostgreSQL. For example:  \n   ```sql\n   CREATE DATABASE mamonsu_database OWNER mamonsu_user;\n   ```  \n   - Run the following command to bootstrap _mamonsu_:\n    ```shell\n    mamonsu bootstrap [-M mamonsu_user] [-x | --create-extensions] [-c | --config] [connection_options]\n    ```\n    For details of usage, see “[Tools](documentation/tools.md#bootstrap)\".  \nAs the result of this operation, monitoring functions are created in the *mamonsu_database* in *mamonsu* schema, and the right to execute them is granted to the *mamonsu_user*. Thus, a superuser connection is no longer required. _mamonsu_ also creates several tables in the specified database. Do not delete these tables as they are required for _mamonsu_ to work.  \n2. **Configure _mamonsu_**  \n    Edit the *agent.conf* configuration file.    \n    Configure Zabbix-related settings. The address field must point to the running Zabbix server, while the client field must provide the name of the Zabbix host. You can find the list of hosts available for your account in the Zabbix web interface under Configuration \u003e Hosts.    \n    ```editorconfig\n    [zabbix]\n    ; enabled by default\n    enabled = True\n    client = zabbix_host_name\n    address = zabbix_server\n    ```  \n    By default, _mamonsu_ will collect both PostgreSQL and system metrics. If required, you can disable metrics collection of either type by setting the enabled parameter to False in the [postgres] or [system] section of the *agent.conf* file, respectively.  \n    ```editorconfig\n    [system]\n    ; enabled by default\n    enabled = True\n    ```  \n    If you are going to collect PostgreSQL metrics, specify connection parameters for the PostgreSQL server you are going to monitor. In the user, password and database fields, you must specify the *mamonsu_user*, *mamonsu_password* and the *mamonsu_database* used for `bootstrap`, respectively. If you skipped the `bootstrap`, specify a superuser credentials and the database to connect to.  \n    \u003e **_NOTE:_** _mamonsu_ stores passwords as plain text in its configuration file, so control access to this file. By default configuration file _agent.conf_ should have read/write permissions for _mamonsu_ user only.  \n    ```editorconfig\n    [postgres]\n    ; enabled by default\n    enabled = True\n    user = mamonsu_user\n    database = mamonsu_database\n    password = mamonsu_password\n    port = 5432  \n    ```  \n   These are the main _mamonsu_ settings to get started. You can also fine-tune other _mamonsu_ settings as explained in the chapter called \"[Configuration file](documentation/configuration_file.md)\".  \n### Template creation and upload  \n1. **Generate a template** that defines how to visualize collected metrics on the Zabbix server:  \n    ```shell\n    mamonsu export template template.xml\n    ```  \n    _mamonsu_ generates the *template.xml* file in your current directory. By default, the name of the template that will be displayed in the Zabbix account is *mamonsu PostgreSQL OS*, where *OS* is the name of your operating system. To get a template with a different display name, you can run the above command with the *--template-name* option.    \n2. **Optionally, specify your Zabbix account settings** in the following environment variables on your monitoring system:  \n   - Set the ZABBIX_USER and ZABBIX_PASSWD variables to the login and password of your Zabbix account, respectively.\n   - Set the ZABBIX_URL to http://zabbix/\n   \n    If you skip this step, you will have to add the following options to all `mamonsu zabbix` commands that you run:  \n    ```shell\n    --url=http://zabbix/ --user=zabbix_login --password=zabbix_password\n    ```  \n3. **Upload the template.xml to the Zabbix server**\n    ```shell\n    mamonsu zabbix template export template.xml\n    ```  \n    Alternatively, you can upload the template through the Zabbix web interface: log in to your Zabbix account and select Templates \u003e Import.\n\n4. **Link the generated template to the host to be monitored**  \nIn the Zabbix web interface, select your host, go to Templates \u003e Add, select your template, and click Update. If you would like to link a template with a new Zabbix host, you can do it from the command line using `mamonsu zabbix` commands. See the section called \"[Zabbix cli](documentation/tools.md#zabbix-cli)\" for details.  \n### Run\nOn UNIX-like systems:\n```shell\n$ service mamonsu start\n```\nor by hand:\n```shell\n$ mamonsu -d -a /etc/mamonsu/plugins -c /etc/mamonsu/agent.conf -p /var/run/mamonsu.pid\n```\n### Template update\nIn order to correctly update the template after minor update and save all the data, it is necessary to generate the same template and application names. You can find your current template name in the Zabbix web interface under Configuration \u003e Templates and application name in Configuration \u003e Templates \u003e Applications.  \nAfter getting current template and application names, you should generate template like this:  \n```shell\nmamonsu export template template.xml --template-name=\"CURRENT_TEMPLATE_NAME\" --application=\"CURRENT_APPLICATION_NAME\"\n```\nNext, upload new template to the Zabbix server. You can do it via command line interface:  \n```shell\nmamonsu zabbix template export template.xml\n```\nOr through the Zabbix web interface:  \n\u003e **_NOTE:_**  While uploading through the Zabbix web interface, you must set *Delete missing* parameter to true for Value mappings, Template dashboards, Items, Discovery rules, Triggers and Graphs.  \n\n\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"Zabbix Template Import\" src=\"documentation/images/zabbix_import_template.png\" /\u003e\n\u003c/p\u003e\n\n### Best practices\n  \n**Zabbix host setup only with `mamonsu zabbix` cli**\n1. Generate a template\n    ```shell\n    mamonsu export template template.xml\n    ```\n2. Set Zabbix variables\n    ```shell\n    export ZABBIX_USER=Admin\n    export ZABBIX_PASSWD=zabbix\n    export ZABBIX_URL=http://zabbix/\n    ```\n3. Upload template\n    ```shell\n    mamonsu zabbix template export template.xml\n    ```\n4. Create host and link template\n    ```shell\n    mamonsu zabbix host create \"pg-host\" $(mamonsu zabbix hostgroup id \"Linux Servers\") $(mamonsu zabbix template id \"mamonsu PostgreSQL Linux\") \"10.10.0.4\"\n    ```\n   This snippet shows how to create Zabbix host called *pg-host* with mamonsu template in hostgroup *Linux Servers* with address *10.10.0.4*.\n \n**_mamonsu_ setup with remote PostgreSQL**\n1. Generate and upload template  \n    ```shell\n    mamonsu export template template.xml; mamonsu zabbix template export template.xml \n    ```\n2. Add remote PostgreSQL host\n   ```shell\n    mamonsu zabbix host create \"remote-pg-1\" $(mamonsu zabbix hostgroup id \"Linux servers\") $(mamonsu zabbix template id \"mamonsu PostgreSQL Linux\") \"45.45.200.5\"\n    ```\n3. Setup agent.conf\n   ```editorconfig\n    [postgres]\n    enabled = True\n    user = mamonsu\n    password = mamonsu\n    database = postgres\n    host = 45.45.200.5\n    port = 5432\n    application_name = mamonsu\n    query_timeout = 10\n    \n    [zabbix]\n    enabled = True\n    client = remote-pg-1\n    address = 127.0.0.1\n    port = 10051\n    re_send = False\n    ```\n\n**_mamonsu_ setup with remote PostgreSQL via SSH tunnel**\n1. Generate and upload template  \n    ```shell\n    mamonsu export template template.xml; mamonsu zabbix template export template.xml \n    ```\n2. Add remote PostgreSQL host\n   ```shell\n    mamonsu zabbix host create \"remote-pg-1\" $(mamonsu zabbix hostgroup id \"Linux servers\") $(mamonsu zabbix template id \"mamonsu PostgreSQL Linux\") \"45.45.200.5\"\n    ```\n3. Setup SSH tunnel\n    ```shell\n    ssh -L 63333:localhost:5432 user@45.45.200.5\n    ```\n4. Setup *agent.conf*\n   ```editorconfig\n    [postgres]\n    enabled = True\n    user = mamonsu\n    password = mamonsu\n    database = postgres\n    host = localhost\n    port = 63333\n    application_name = mamonsu\n    query_timeout = 10\n    \n    [zabbix]\n    enabled = True\n    client = remote-pg-1\n    address = 127.0.0.1\n    port = 10051\n    re_send = False\n    ```\n   \n**Major update**  \nIf you want to upgrade _mamonsu_ to a version that is not compatible with the previous one, what you must do to continue using the application depends on whether you need to retain the metrics data collected.  \nIf you do not need to retain the collected data, just unlink old template and link a new one.  \n\nIf you need to retain the collected data, do the following:\n\n1. Install the new version of _mamonsu_.\n2. Generate a new template for the Zabbix server.\n3. If you performed a bootstrap using the previous version of _mamonsu_, run the bootstrap command again.\n4. Upload the new template to the Zabbix server.\n5. Rename the host for which you want to retain the collected data and leave the old template linked to that host.\n6. Create a new host for the same system and link the new template to it.\n7. Restart _mamonsu_. It will collect data for the new host. The old host will no longer be used, but the data collected will be available.  \n\nThe difficulty is that Zabbix cannot massively rename hosts.  \nWe offer the following recommendations:\n1. If you have access to the Zabbix database:  \nMass rename hosts via SQL:\n    ```shell\n    zabbix=# SELECT host, name FROM hosts\n    zabbix-# WHERE host LIKE '%local-pg%';\n    -[ RECORD 1 ]----\n    host | local-pg-2\n    name | local-pg-2\n    -[ RECORD 2 ]----\n    host | local-pg-3\n    name | local-pg-3\n    \n    zabbix=# UPDATE hosts\n    zabbix=# SET host = host || ' OLD-mamonsu',\n    zabbix=#     name = name || ' OLD-mamonsu'\n    zabbix=# WHERE host LIKE '%local-pg%';\n    UPDATE 2\n    zabbix=# SELECT host, name FROM hosts\n    zabbix=# WHERE host LIKE '%local-pg%';\n    -[ RECORD 1 ]----------------\n    host | local-pg-2 OLD-mamonsu\n    name | local-pg-2 OLD-mamonsu\n    -[ RECORD 2 ]----------------\n    host | local-pg-3 OLD-mamonsu\n    name | local-pg-3 OLD-mamonsu\n    ```\n2. Using Zabbix API:  \nAPI query:\n    ```shell\n    curl -H \"Content-type: application/json-rpc\" -X POST http://zabbix/api_jsonrpc.php -d'\n    {\n        \"jsonrpc\": \"2.0\",\n        \"method\": \"host.update\",\n        \"params\": {\n            \"hostid\": \"HOST_ID\",\n            \"host\": \"local-pg-3 OLD-mamonsu\",\n            \"name\": \"local-pg-3 OLD-mamonsu\"\n        },\n        \"auth\": \"AUTH_TOKEN\",\n        \"id\": 1\n    }'\n    ```\n   \u003cdetails\u003e\n   \u003csummary\u003eScript\u003c/summary\u003e\n   \n    ```shell\n    #!/bin/bash\n     \n    ZABBIX_URL=\"http://zabbix/\"\n    ZABBIX_USER=\"Admin\"\n    ZABBIX_PASSWORD=\"zabbix\"\n    ZABBIX_PATTERN=\"\"\n    ZABBIX_SUFFIX=\"OLD\"\n     \n    for parameter in \"$@\"\n    do\n    case $parameter in\n        -u=*|--url=*) # zabbix url\n        ZABBIX_URL=\"${parameter#*=}\"\n        shift\n        ;;\n        -U=*|--user=*) # zabbix user\n        ZABBIX_USER=\"${parameter#*=}\"\n        shift\n        ;;\n        -P=*|--password=*) # zabbix password\n        ZABBIX_PASSWORD=\"${parameter#*=}\"\n        shift\n        ;;\n        -p=*|--pattern=*) # zabbix host pattern\n        ZABBIX_PATTERN=\"${parameter#*=}\"\n        shift\n        ;;\n        -s=*|--suffix=*) # zabbix host suffix\n        ZABBIX_SUFFIX=\"${parameter#*=}\"\n        shift\n        ;;\n        *)\n              # unknown option\n        ;;\n    esac\n    done\n     \n    # get Zabbix auth token\n    auth_token=$(curl -H \"Content-type: application/json-rpc\" -X POST ${ZABBIX_URL}api_jsonrpc.php -d'\n    {\n        \"jsonrpc\": \"2.0\",\n        \"method\": \"user.login\",\n        \"params\": {\n        \"user\": \"'${ZABBIX_USER}'\",\n        \"password\": \"'${ZABBIX_PASSWORD}'\"\n        },\n        \"id\": 1\n    }' | python3 -c \"import sys, json; print(json.load(sys.stdin)['result'])\")\n     \n    # get array of Zabbix hosts to rename\n    readarray -t hosts \u003c \u003c(mamonsu zabbix --url=${ZABBIX_URL} --user=${ZABBIX_USER} --password=${ZABBIX_PASSWORD} host list | awk '{ print \"\\\"\"$0\"\\\"\"}' | grep ${ZABBIX_PATTERN})\n    hosts=(\"${hosts[@]//\\\"/}\")\n     \n    hosts_dict={}\n    # create dict from array (id:name)\n    for host in \"${hosts[@]}\"\n    do\n        hosts_dict[$(mamonsu zabbix --url=${ZABBIX_URL} --user=${ZABBIX_USER} --password=${ZABBIX_PASSWORD} host id \"${host}\")]=$host\n    done\n     \n    for key in \"${!hosts_dict[@]}\"; do\n        if [ ${key} -ne 0 ]; then\n        eval 'curl -H \"Content-type: application/json-rpc\" -X POST ${ZABBIX_URL}api_jsonrpc.php -d '\\''\n    {\n        \"jsonrpc\": \"2.0\",\n        \"method\": \"host.update\",\n        \"params\": {\n            \"hostid\": \"'${key}'\",\n            \"host\": \"'${hosts_dict[$key]}' '${ZABBIX_SUFFIX}'\",\n            \"name\": \"'${hosts_dict[$key]}' '${ZABBIX_SUFFIX}'\"\n        },\n        \"auth\": \"'${auth_token}'\",\n        \"id\": 1\n    }'\\'''\n        fi\n    done\n    ```\n   \n   \u003c/details\u003e\n\n    Script usage example:\n    ```shell\n    ./rename_zabbix_hosts.sh --url=http://localzabbix/ --pattern=\"local-pg\" --suffix=\"OLD-mamonsu\"\n    ```\n   \n## Additional chapters\n- [**Adding custom plugins**](documentation/adding_custom_plugins.md)\n- [**Configuration file**](documentation/configuration_file.md)\n- [**Metrics**](documentation/metrics.md)\n- [**Tools**](documentation/tools.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fmamonsu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostgrespro%2Fmamonsu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostgrespro%2Fmamonsu/lists"}