Compilar el modulo zabbix module docker.so

From Zabbix-ES
Jump to navigation Jump to search

Compilar el modulo zabbix_module_docker.so

ORIGEN: https://github.com/monitoringartist/zabbix-docker-monitoring#compilation
# Required CentOS/RHEL apps:   yum install -y wget autoconf automake gcc git pcre-devel
# Required Debian/Ubuntu apps: apt-get install -y wget autoconf automake gcc git make pkg-config libpcre3-dev
# Required Fedora apps:        dnf install -y wget autoconf automake gcc git make pcre-devel
# Required openSUSE apps:      zypper install -y wget autoconf automake gcc git make pkg-config pcre-devel
# Required Gentoo apps 1:      emerge net-misc/wget sys-devel/autoconf sys-devel/automake sys-devel/gcc
# Required Gentoo apps 2:      emerge dev-vcs/git sys-devel/make dev-util/pkgconfig dev-libs/libpcre
# Source, use your version:    git clone -b 4.2.2 --depth 1 https://git.zabbix.com/scm/zbx/zabbix.git /usr/src/zabbix_4.2.2
# git clone -b 5.0.1 --depth 1 https://git.zabbix.com/scm/zbx/zabbix.git /usr/src/zabbix_5.0.1
# cd /usr/src/zabbix_5.0.1
# ./bootstrap.sh
# ./configure --enable-agent
# mkdir src/modules/zabbix_module_docker
# cd src/modules/zabbix_module_docker
# wget https://raw.githubusercontent.com/monitoringartist/zabbix-docker-monitoring/master/src/modules/zabbix_module_docker/zabbix_module_docker.c
# wget https://raw.githubusercontent.com/monitoringartist/zabbix-docker-monitoring/master/src/modules/zabbix_module_docker/Makefile
- Antes de compilar hay que aplicar 2 Patchs File:Zabbix module docker.c.patch1 File:Zabbix module docker.c.patch2
# wget -O zabbix_module_docker.c.patch1 https://www.zabbix-es.com.es/images/7/70/Zabbix_module_docker.c.patch1
# wget -O zabbix_module_docker.c.patch2 https://www.zabbix-es.com.es/images/b/ba/Zabbix_module_docker.c.patch2
# patch zabbix_module_docker.c zabbix_module_docker.c.patch1
# patch zabbix_module_docker.c zabbix_module_docker.c.patch2  
# make
- El modulo solo funciona con el Agente 4.4.2 que es el que utilizamos para compilarlo. Para compilar el agente necesitamos hacer lo siguiente.
# cd /usr/src/zabbix_4.2.2/src
# make

- Los nuevos binarios están en: 
  zabbix_agentd -> /usr/src/zabbix_4.2.2/src/zabbix_agent
  zabbix_sender -> /usr/src/zabbix_4.2.2/src/zabbix_sender
  zabbix_get    -> /usr/src/zabbix_4.2.2/src/zabbix_get

Configuración del Agente

# vi /etc/zabbix/zabbix_agent.conf
LoadModulePath=/etc/zabbix/modules/
LoadModule=zabbix_module_docker.so 
AllowRoot=1

Configuracion a nivel de OS

# usermod -aG docker zabbix

Agregamos el Template de Monitoring Artist

https://raw.githubusercontent.com/monitoringartist/zabbix-docker-monitoring/master/template/Zabbix-Template-App-Docker.xml

Realizamos una prueba desde el Zabbix Server

# zabbix_get -s swarm01 -k docker.discovery | jq
{
  "data": [
    {
      "{#FCONTAINERID}": "f2bef83d2563c8171ff076aff7072b25dfd11dc0799a09faa4d7924fc21ba8a2",
      "{#SCONTAINERID}": "f2bef83d2563",
      "{#SYSTEM.HOSTNAME}": "swarm01",
      "{#HCONTAINERID}": "Grafana_MAY_may.luaaiagp06ftbotxwbtaaewh9.dlagz3bgov6heelhcd050ojvt"
    },
    {
      "{#FCONTAINERID}": "613b905237e932d82e3da4ae5e99d634aff476a9ab745f57cc138d43406ee68e",
      "{#SCONTAINERID}": "613b905237e9",
      "{#SYSTEM.HOSTNAME}": "swarm01",
      "{#HCONTAINERID}": "Registry_gsis.1.bf5t542mklknqly0y7mnrc7ky"
    },
    {
      "{#FCONTAINERID}": "0cf45bb9a25a853e15f419c0c5668cbbebf598344681a2c31ac13b1016f25e1f",
      "{#SCONTAINERID}": "0cf45bb9a25a",
      "{#SYSTEM.HOSTNAME}": "swarm01",
      "{#HCONTAINERID}": "DrawIO_drawio.luaaiagp06ftbotxwbtaaewh9.bdai7p9lxljlk1re4opyy8zi8"
    },
    {
      "{#FCONTAINERID}": "a013f330b50a6396d4f4ad90412ea9478a4be9401b1ce20da1411c964dac032e",
      "{#SCONTAINERID}": "a013f330b50a",
      "{#SYSTEM.HOSTNAME}": "swarm01",
      "{#HCONTAINERID}": "Grafana_GSIS_grafana.luaaiagp06ftbotxwbtaaewh9.w80v29y8at7m5ehayyuj6scny"
    }
  ]
}