Install and configure zabbix-agent on RHEL and Solaris servers and populate zabbix-server using Zabbix API

I always liked to develop custom shell scripts and play with monitoring applications like Nagios and Zabbix, but i was in a awkward situation.

After install and do final customizations on my zabbix-server and database server i realized that i needed install the zabbix-agent on more than three thousand servers that run not just LInux, but Solaris too. In that moment i lifted and went to the coffee shop.

I spent some time thinking in how to automate that job and i remembered that i used Ansible to automate little things, like deploy shell scripts and binaries, collect tar files, install packages and manage services.

In that moment a quest was born. And the quest was ‘make a Ansible role to automate the boring job’

I spend two days studying more about DevOps with Ansible in *nix world and i created and published in Ansible Galaxy the role ‘kdiegorsantos.zabbix-agent’ that can be used to install and configure zabbix-agent on RHEL and Solaris servers and populate zabbix-server using the Zabbix API.

zabbix-agent

This ansible role can be used to install and configure zabbix-agent on RHEL 5/6/7 and Solaris 10 servers. We have tasks to:

  1. install zabbix-agent and dependencies via YUM on RHEL servers.
  2. Deploy the zabbix-agent binary to Solaris servers.
  3. Configure zabbix-agent parameters.
  4. Start and manage zabbix-agent service.
  5. Add or update the zabbix-agent host on the zabbix-server via API.

Requirements

Ansible 1.5.4 or higher.

Role Variables

All variables are set in default\main.yml.

# zabbix-api
zabbix_api_use: True                                # True or False, to enable or not zabbix-api.
zabbix_url: "http://zabbix.mydomain/zabbix"         # The main page of your zabbix server.
zabbix_api_user: "zabbix_admin_username"            # zabbix admin username.
zabbix_api_pass: "zabbix_admin_password"            # zabbix admin password.
zabbix_create_hostgroup: absent                     # if the group not exists create it or not.
zabbix_create_host: present                         # if the host not exists create it or not.
zabbix_host_status: enabled                         # enalbe or disable the host.
zabbix_useuip: 1                                    # use ip and not dns.
zabbix_host_groups_rhel:                            # default group for Linux hosts.
  - Linux Servers
zabbix_link_templates_rhel:                         # default template for Linux hosts.
  - Template OS Linux
zabbix_host_groups_sun:                             # default group for Solaris hosts.
  - Solaris Servers
zabbix_link_templates_sun:                          # default template for Solaris hosts.
  - Template OS Solaris

Dependencies

You’ll need to install zabbix-api to be able to add or update host information on zabbix-server.

Installation:

# pip install zabbix-api

Short example:

>>> from zabbix_api import ZabbixAPI
>>> zapi = ZabbixAPI(server="https://server/")
>>> zapi.login("login", "password")
>>> zapi.trigger.get({"expandExpression": "extend", "triggerids": range(0, 100)})

See also:

Installation

Install using ansible-galaxy.

$ ansible-galaxy install kdiegorsantos.zabbix-agent

Example Playbook

After change the default variables you can run this role using the ansible-playbook command.

# ansible-playbook /etc/ansible/roles/zabbix-agent/role.yml

License

This project is licensed under the MIT license. See included LICENSE.md.

Author Information

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s