Add compatibility workflows and integration tests (#1991)
Fixes #1986 Fixes #1994 - Updated .gitignore to include SSL certificate files. - Introduced new GitHub Actions workflows for testing compatibility with Zabbix versions 5.0, 6.0, 7.0, and 7.2. - Added integration tests for Zabbix API for each version, ensuring proper authentication and API version handling. - Updated Docker Compose files to support SSL configuration for Zabbix web services. - Removed deprecated default Docker Compose and bootstrap files. - Removed devenv for version 6.2.
This commit is contained in:
5
.changeset/purple-lions-join.md
Normal file
5
.changeset/purple-lions-join.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'grafana-zabbix': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix: Basic authentication in zabbix <7.2
|
||||||
35
.github/workflows/compatibility-50.yml
vendored
Normal file
35
.github/workflows/compatibility-50.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: zabbix_50
|
||||||
|
run-name: Compatibility with Zabbix 5.0 test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
compatibility-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5.3.0
|
||||||
|
|
||||||
|
- name: Start Zabbix environment
|
||||||
|
run: |
|
||||||
|
docker compose -f devenv/zabbix50/docker-compose.yml up -d
|
||||||
|
# Wait for Zabbix to be ready
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
env:
|
||||||
|
INTEGRATION_TEST50: 'true'
|
||||||
|
ZABBIX_URL: 'https://localhost/api_jsonrpc.php'
|
||||||
|
ZABBIX_USER: 'Admin'
|
||||||
|
ZABBIX_PASSWORD: 'zabbix'
|
||||||
|
run: go test -v ./pkg/zabbixapi/...
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: docker compose -f devenv/zabbix50/docker-compose.yml down -v
|
||||||
35
.github/workflows/compatibility-60.yml
vendored
Normal file
35
.github/workflows/compatibility-60.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: zabbix_60
|
||||||
|
run-name: Compatibility with Zabbix 6.0 test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
compatibility-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5.3.0
|
||||||
|
|
||||||
|
- name: Start Zabbix environment
|
||||||
|
run: |
|
||||||
|
docker compose -f devenv/zabbix60/docker-compose.yml up -d
|
||||||
|
# Wait for Zabbix to be ready
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
env:
|
||||||
|
INTEGRATION_TEST60: 'true'
|
||||||
|
ZABBIX_URL: 'https://localhost/api_jsonrpc.php'
|
||||||
|
ZABBIX_USER: 'Admin'
|
||||||
|
ZABBIX_PASSWORD: 'zabbix'
|
||||||
|
run: go test -v ./pkg/zabbixapi/...
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: docker compose -f devenv/zabbix60/docker-compose.yml down -v
|
||||||
35
.github/workflows/compatibility-70.yml
vendored
Normal file
35
.github/workflows/compatibility-70.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: zabbix_70
|
||||||
|
run-name: Compatibility with Zabbix 7.0 test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
compatibility-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5.3.0
|
||||||
|
|
||||||
|
- name: Start Zabbix environment
|
||||||
|
run: |
|
||||||
|
docker compose -f devenv/zabbix70/docker-compose.yml up -d
|
||||||
|
# Wait for Zabbix to be ready
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
env:
|
||||||
|
INTEGRATION_TEST70: 'true'
|
||||||
|
ZABBIX_URL: 'https://localhost/api_jsonrpc.php'
|
||||||
|
ZABBIX_USER: 'Admin'
|
||||||
|
ZABBIX_PASSWORD: 'zabbix'
|
||||||
|
run: go test -v ./pkg/zabbixapi/...
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: docker compose -f devenv/zabbix70/docker-compose.yml down -v
|
||||||
35
.github/workflows/compatibility-72.yml
vendored
Normal file
35
.github/workflows/compatibility-72.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: zabbix_72
|
||||||
|
run-name: Compatibility with Zabbix 7.2 test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
compatibility-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5.3.0
|
||||||
|
|
||||||
|
- name: Start Zabbix environment
|
||||||
|
run: |
|
||||||
|
docker compose -f devenv/zabbix72/docker-compose.yml up -d
|
||||||
|
# Wait for Zabbix to be ready
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
env:
|
||||||
|
INTEGRATION_TEST72: 'true'
|
||||||
|
ZABBIX_URL: 'http://localhost:8188/api_jsonrpc.php'
|
||||||
|
ZABBIX_USER: 'Admin'
|
||||||
|
ZABBIX_PASSWORD: 'zabbix'
|
||||||
|
run: go test -v ./pkg/zabbixapi/...
|
||||||
|
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: docker compose -f devenv/zabbix72/docker-compose.yml down -v
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -51,3 +51,7 @@ alexanderzobnin-zabbix-app.zip
|
|||||||
public/css/*.min.css
|
public/css/*.min.css
|
||||||
|
|
||||||
provisioning/
|
provisioning/
|
||||||
|
|
||||||
|
# SSL certificates
|
||||||
|
devenv/nginx/nginx.crt
|
||||||
|
devenv/nginx/nginx.key
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
ARG grafana_version=latest
|
|
||||||
|
|
||||||
FROM grafana/grafana:${grafana_version}
|
|
||||||
|
|
||||||
# Make it as simple as possible to access the grafana instance for development purposes
|
|
||||||
# Do NOT enable these settings in a public facing / production grafana instance
|
|
||||||
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
|
|
||||||
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
|
|
||||||
ENV GF_AUTH_BASIC_ENABLED "false"
|
|
||||||
# Set development mode so plugins can be loaded without the need to sign
|
|
||||||
ENV GF_DEFAULT_APP_MODE "development"
|
|
||||||
|
|
||||||
# Inject livereload script into grafana index.html
|
|
||||||
USER root
|
|
||||||
RUN sed -i 's/<\/body><\/html>/<script src=\"http:\/\/localhost:35729\/livereload.js\"><\/script><\/body><\/html>/g' /usr/share/grafana/public/views/index.html
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
FROM python:2.7
|
|
||||||
|
|
||||||
ENV ZBX_API_URL=http://zabbix-web:8080
|
|
||||||
ENV ZBX_API_USER="Admin"
|
|
||||||
ENV ZBX_API_PASSWORD="zabbix"
|
|
||||||
ENV ZBX_CONFIG="zbx_export_hosts.xml"
|
|
||||||
ENV ZBX_BOOTSTRAP_SCRIPT="bootstrap_config.py"
|
|
||||||
|
|
||||||
RUN pip install pyzabbix
|
|
||||||
|
|
||||||
ADD ./bootstrap_config.py /bootstrap_config.py
|
|
||||||
ADD ${ZBX_CONFIG} /${ZBX_CONFIG}
|
|
||||||
|
|
||||||
WORKDIR /
|
|
||||||
|
|
||||||
# Run bootstrap_config.py when the container launches
|
|
||||||
CMD ["python", "/bootstrap_config.py"]
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
import os
|
|
||||||
from time import sleep
|
|
||||||
from pyzabbix import ZabbixAPI, ZabbixAPIException
|
|
||||||
|
|
||||||
zabbix_url = os.environ['ZBX_API_URL']
|
|
||||||
zabbix_user = os.environ['ZBX_API_USER']
|
|
||||||
zabbix_password = os.environ['ZBX_API_PASSWORD']
|
|
||||||
print(zabbix_url, zabbix_user, zabbix_password)
|
|
||||||
|
|
||||||
zapi = ZabbixAPI(zabbix_url, timeout=5)
|
|
||||||
|
|
||||||
for i in range(10):
|
|
||||||
print("Trying to connected to Zabbix API %s" % zabbix_url)
|
|
||||||
try:
|
|
||||||
zapi.login(zabbix_user, zabbix_password)
|
|
||||||
print("Connected to Zabbix API Version %s" % zapi.api_version())
|
|
||||||
break
|
|
||||||
except ZabbixAPIException as e:
|
|
||||||
print e
|
|
||||||
sleep(5)
|
|
||||||
except:
|
|
||||||
print("Waiting")
|
|
||||||
sleep(5)
|
|
||||||
|
|
||||||
|
|
||||||
config_path = os.environ['ZBX_CONFIG']
|
|
||||||
import_rules = {
|
|
||||||
'discoveryRules': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'graphs': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'groups': {
|
|
||||||
'createMissing': True
|
|
||||||
},
|
|
||||||
'hosts': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'images': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'items': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'maps': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'templateLinkage': {
|
|
||||||
'createMissing': True,
|
|
||||||
},
|
|
||||||
'templates': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'triggers': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Importing Zabbix config from %s" % config_path)
|
|
||||||
with open(config_path, 'r') as f:
|
|
||||||
config = f.read()
|
|
||||||
|
|
||||||
try:
|
|
||||||
# https://github.com/lukecyca/pyzabbix/issues/62
|
|
||||||
import_result = zapi.confimport("xml", config, import_rules)
|
|
||||||
print(import_result)
|
|
||||||
except ZabbixAPIException as e:
|
|
||||||
print e
|
|
||||||
|
|
||||||
for h in zapi.host.get(output="extend"):
|
|
||||||
print(h['name'])
|
|
||||||
@@ -1,432 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<zabbix_export>
|
|
||||||
<version>6.0</version>
|
|
||||||
<date>2022-04-28T13:04:18Z</date>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<uuid>2e427c268ac1468b9add94b65e2d6c14</uuid>
|
|
||||||
<name>Backend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<uuid>d97ba66b283544339628b71975a6e68d</uuid>
|
|
||||||
<name>Frontend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<uuid>dc579cd7a1a34222933f24f52a68bcd8</uuid>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<uuid>6f6799aa69e844b4b3918f779f2abf08</uuid>
|
|
||||||
<name>Zabbix servers</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<uuid>7df96b18c230490a9a0a9e2307226338</uuid>
|
|
||||||
<name>Templates</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<hosts>
|
|
||||||
<host>
|
|
||||||
<host>backend01</host>
|
|
||||||
<name>backend01</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Backend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_backend_01</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>backend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>backend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>backend02</host>
|
|
||||||
<name>backend02</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Backend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_backend_02</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>backend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>backend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>frontend01</host>
|
|
||||||
<name>frontend01</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Frontend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_frontend_01</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>frontend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>frontend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>frontend02</host>
|
|
||||||
<name>frontend02</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Frontend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_frontend_02</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>frontend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>frontend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>Zabbix server</host>
|
|
||||||
<name>Zabbix server</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Linux by Zabbix agent</name>
|
|
||||||
</template>
|
|
||||||
<template>
|
|
||||||
<name>Zabbix server health</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Zabbix servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zabbix-agent</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
</hosts>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<uuid>2d7a65bb369c48199361913b223b1695</uuid>
|
|
||||||
<template>Template ZAS Agent</template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Zabbix agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Templates</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<items>
|
|
||||||
<item>
|
|
||||||
<uuid>e79d4215ec014b74923b905bb8f82410</uuid>
|
|
||||||
<name>Incoming network traffic on eth0</name>
|
|
||||||
<key>net.if.in[eth0]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<units>bps</units>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Network interfaces</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>18b377dae9fe48d093c16ee7a7c93320</uuid>
|
|
||||||
<name>Outgoing network traffic on eth0</name>
|
|
||||||
<key>net.if.out[eth0]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<units>bps</units>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Network interfaces</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>2479e055e91c476f9be93b5f363cfa2f</uuid>
|
|
||||||
<name>Processor load (1 min average per core)</name>
|
|
||||||
<key>system.cpu.load[percpu,avg1]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<description>The processor load is calculated as system CPU load divided by number of CPU cores.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<triggers>
|
|
||||||
<trigger>
|
|
||||||
<uuid>60e5484b60ca4061b21bd23f8364bd6e</uuid>
|
|
||||||
<expression>last(/Template ZAS Agent/system.cpu.load[percpu,avg1])>2</expression>
|
|
||||||
<name>Processor load is too high on {HOST.NAME}</name>
|
|
||||||
<priority>WARNING</priority>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>app</tag>
|
|
||||||
<value>performance</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>type</tag>
|
|
||||||
<value>cpu</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</trigger>
|
|
||||||
</triggers>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>f0dd4221793c49889cf2789806afa597</uuid>
|
|
||||||
<name>Processor load (15 min average per core)</name>
|
|
||||||
<key>system.cpu.load[percpu,avg15]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<description>The processor load is calculated as system CPU load divided by number of CPU cores.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>9a8b4a1f173b4f209723d820dc2e054a</uuid>
|
|
||||||
<name>CPU $2 time</name>
|
|
||||||
<key>system.cpu.util[,iowait]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<units>%</units>
|
|
||||||
<description>Amount of time the CPU has been waiting for I/O to complete.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<triggers>
|
|
||||||
<trigger>
|
|
||||||
<uuid>ceb468b9eb434fa6bd4c8a5d7507fd87</uuid>
|
|
||||||
<expression>avg(/Template ZAS Agent/system.cpu.util[,iowait],5m)>20</expression>
|
|
||||||
<name>Disk I/O is overloaded on {HOST.NAME}</name>
|
|
||||||
<priority>WARNING</priority>
|
|
||||||
<description>OS spends significant time waiting for I/O (input/output) operations. It could be indicator of performance issues with storage system.</description>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>disk</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>type</tag>
|
|
||||||
<value>disk</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</trigger>
|
|
||||||
</triggers>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>e6d19d47cf60452ead1e791da2d5c0dc</uuid>
|
|
||||||
<name>CPU $2 time</name>
|
|
||||||
<key>system.cpu.util[,system]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<units>%</units>
|
|
||||||
<description>The time the CPU has spent running the kernel and its processes.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>2d81fbc139774306959712a627c99b9a</uuid>
|
|
||||||
<name>CPU $2 time</name>
|
|
||||||
<key>system.cpu.util[,user]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<units>%</units>
|
|
||||||
<description>The time the CPU has spent running users' processes that are not niced.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
</items>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<graphs>
|
|
||||||
<graph>
|
|
||||||
<uuid>7aac0ec0c0e04b7a8bb6472d1faa7a09</uuid>
|
|
||||||
<name>CPU load</name>
|
|
||||||
<ymin_type_1>FIXED</ymin_type_1>
|
|
||||||
<graph_items>
|
|
||||||
<graph_item>
|
|
||||||
<color>009900</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.load[percpu,avg1]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>2</sortorder>
|
|
||||||
<color>990000</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.load[percpu,avg15]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
</graph_items>
|
|
||||||
</graph>
|
|
||||||
<graph>
|
|
||||||
<uuid>f25064d88b964a678fac7ea6095b238a</uuid>
|
|
||||||
<name>CPU utilization</name>
|
|
||||||
<show_triggers>NO</show_triggers>
|
|
||||||
<type>STACKED</type>
|
|
||||||
<ymin_type_1>FIXED</ymin_type_1>
|
|
||||||
<ymax_type_1>FIXED</ymax_type_1>
|
|
||||||
<graph_items>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>4</sortorder>
|
|
||||||
<drawtype>FILLED_REGION</drawtype>
|
|
||||||
<color>999900</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.util[,iowait]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>5</sortorder>
|
|
||||||
<drawtype>FILLED_REGION</drawtype>
|
|
||||||
<color>990000</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.util[,system]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>6</sortorder>
|
|
||||||
<drawtype>FILLED_REGION</drawtype>
|
|
||||||
<color>000099</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.util[,user]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
</graph_items>
|
|
||||||
</graph>
|
|
||||||
</graphs>
|
|
||||||
</zabbix_export>
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
# Grafana
|
|
||||||
grafana:
|
|
||||||
container_name: 'alexanderzobnin-boilerplate-app'
|
|
||||||
build:
|
|
||||||
context: ./
|
|
||||||
args:
|
|
||||||
grafana_version: ${GRAFANA_VERSION:-10.1.2}
|
|
||||||
ports:
|
|
||||||
- 3000:3000/tcp
|
|
||||||
volumes:
|
|
||||||
- ../../dist:/grafana-zabbix
|
|
||||||
- ../dashboards:/devenv/dashboards
|
|
||||||
- ../grafana.ini:/etc/grafana/grafana.ini:ro
|
|
||||||
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
|
|
||||||
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'
|
|
||||||
|
|
||||||
# Zabbix
|
|
||||||
zabbix-server:
|
|
||||||
image: zabbix/zabbix-server-pgsql:alpine-6.0-latest
|
|
||||||
ports:
|
|
||||||
- '10051:10051'
|
|
||||||
depends_on:
|
|
||||||
- database
|
|
||||||
environment:
|
|
||||||
DB_SERVER_HOST: database
|
|
||||||
DB_SERVER_PORT: 5432
|
|
||||||
POSTGRES_USER: zabbix
|
|
||||||
POSTGRES_PASSWORD: zabbix
|
|
||||||
POSTGRES_DB: zabbix
|
|
||||||
ZBX_TIMEOUT: 10
|
|
||||||
ZBX_STARTPOLLERS: 10
|
|
||||||
ZBX_STARTPOLLERSUNREACHABLE: 5
|
|
||||||
ZBX_DEBUGLEVEL: 3
|
|
||||||
|
|
||||||
zabbix-web:
|
|
||||||
image: zabbix/zabbix-web-apache-pgsql:alpine-6.0-latest
|
|
||||||
ports:
|
|
||||||
- '8188:8080'
|
|
||||||
depends_on:
|
|
||||||
- database
|
|
||||||
- zabbix-server
|
|
||||||
environment:
|
|
||||||
ZBX_SERVER_HOST: zabbix-server
|
|
||||||
ZBX_SERVER_PORT: 10051
|
|
||||||
DB_SERVER_HOST: database
|
|
||||||
DB_SERVER_PORT: 5432
|
|
||||||
POSTGRES_USER: zabbix
|
|
||||||
POSTGRES_PASSWORD: zabbix
|
|
||||||
POSTGRES_DB: zabbix
|
|
||||||
|
|
||||||
database:
|
|
||||||
image: postgres:15
|
|
||||||
ports:
|
|
||||||
- '15432:5432'
|
|
||||||
command: postgres -c 'max_connections=1000'
|
|
||||||
environment:
|
|
||||||
POSTGRES_USER: zabbix
|
|
||||||
POSTGRES_PASSWORD: zabbix
|
|
||||||
|
|
||||||
zabbix-agent:
|
|
||||||
image: zabbix/zabbix-agent:alpine-6.0-latest
|
|
||||||
environment:
|
|
||||||
ZBX_SERVER_HOST: zabbix-server
|
|
||||||
ZBX_SERVER_PORT: 10051
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# Bootstrap config
|
|
||||||
#########################################################
|
|
||||||
|
|
||||||
bootstrap:
|
|
||||||
build: ./bootstrap
|
|
||||||
environment:
|
|
||||||
ZBX_API_URL: http://zabbix-web:8080
|
|
||||||
ZBX_API_USER: Admin
|
|
||||||
ZBX_API_PASSWORD: zabbix
|
|
||||||
depends_on:
|
|
||||||
- database
|
|
||||||
- zabbix-server
|
|
||||||
- zabbix-web
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# Fake agents
|
|
||||||
#########################################################
|
|
||||||
|
|
||||||
# backend
|
|
||||||
redis_backend:
|
|
||||||
image: redis:alpine
|
|
||||||
|
|
||||||
zas_backend_01:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_backend
|
|
||||||
# restart: always
|
|
||||||
|
|
||||||
zas_backend_02:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_backend
|
|
||||||
|
|
||||||
# frontend
|
|
||||||
redis_frontend:
|
|
||||||
image: redis:alpine
|
|
||||||
|
|
||||||
zas_frontend_01:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_frontend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_frontend
|
|
||||||
|
|
||||||
zas_frontend_02:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_frontend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_frontend
|
|
||||||
1
devenv/nginx/.htpasswd
Normal file
1
devenv/nginx/.htpasswd
Normal file
@@ -0,0 +1 @@
|
|||||||
|
admin:$apr1$hosO.9ex$D2pmswVRynvDoLE.bYs2C.
|
||||||
29
devenv/nginx/default.conf
Normal file
29
devenv/nginx/default.conf
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
server {
|
||||||
|
listen 80 default;
|
||||||
|
listen 443 ssl;
|
||||||
|
root /var/www/html/;
|
||||||
|
index index.php;
|
||||||
|
|
||||||
|
server_name localhost 127.0.0.1;
|
||||||
|
ssl_certificate /etc/nginx/ssl/nginx.crt;
|
||||||
|
ssl_certificate_key /etc/nginx/ssl/nginx.key;
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
|
||||||
|
auth_basic "Zabbix HTTP Auth";
|
||||||
|
auth_basic_user_file /etc/nginx/.htpasswd;
|
||||||
|
|
||||||
|
# Prevent caching of authentication
|
||||||
|
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
|
||||||
|
add_header Pragma "no-cache";
|
||||||
|
add_header Expires "0";
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:8080/;
|
||||||
|
proxy_set_header Host $http_host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_buffering on;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,30 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
ssl-cert:
|
||||||
|
image: alpine:latest
|
||||||
|
command: |
|
||||||
|
sh -c "if [ ! -f /certs/nginx.crt ] || [ ! -f /certs/nginx.key ]; then
|
||||||
|
apk add --no-cache openssl &&
|
||||||
|
mkdir -p /certs &&
|
||||||
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /certs/nginx.key -out /certs/nginx.crt -subj '/C=US/ST=State/L=City/O=Organization/CN=localhost' &&
|
||||||
|
chmod 644 /certs/nginx.crt /certs/nginx.key
|
||||||
|
else
|
||||||
|
echo 'SSL certificates already exist, skipping generation'
|
||||||
|
fi"
|
||||||
|
volumes:
|
||||||
|
- ../nginx:/certs
|
||||||
|
|
||||||
|
# Grafana
|
||||||
|
grafana:
|
||||||
|
image: grafana/grafana:main
|
||||||
|
ports:
|
||||||
|
- '3001:3000'
|
||||||
|
volumes:
|
||||||
|
- ../..:/grafana-zabbix
|
||||||
|
- ../dashboards:/devenv/dashboards
|
||||||
|
- ../grafana.ini:/etc/grafana/grafana.ini:ro
|
||||||
|
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
|
||||||
|
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'
|
||||||
|
|
||||||
# Zabbix
|
# Zabbix
|
||||||
zabbix-server:
|
zabbix-server:
|
||||||
image: zabbix/zabbix-server-pgsql:alpine-5.0-latest
|
image: zabbix/zabbix-server-pgsql:alpine-5.0-latest
|
||||||
@@ -16,14 +40,17 @@ services:
|
|||||||
POSTGRES_DB: zabbix
|
POSTGRES_DB: zabbix
|
||||||
|
|
||||||
zabbix-web:
|
zabbix-web:
|
||||||
image: zabbix/zabbix-web-apache-pgsql:alpine-5.0-latest
|
image: zabbix/zabbix-web-nginx-pgsql:alpine-5.0-latest
|
||||||
ports:
|
ports:
|
||||||
|
- '443:443'
|
||||||
- '8188:8080'
|
- '8188:8080'
|
||||||
- '8189:8443'
|
|
||||||
# - "8188:80"
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- database
|
ssl-cert:
|
||||||
- zabbix-server
|
condition: service_completed_successfully
|
||||||
|
database:
|
||||||
|
condition: service_started
|
||||||
|
zabbix-server:
|
||||||
|
condition: service_started
|
||||||
environment:
|
environment:
|
||||||
ZBX_SERVER_HOST: zabbix-server
|
ZBX_SERVER_HOST: zabbix-server
|
||||||
ZBX_SERVER_PORT: 10051
|
ZBX_SERVER_PORT: 10051
|
||||||
@@ -34,7 +61,9 @@ services:
|
|||||||
POSTGRES_DB: zabbix
|
POSTGRES_DB: zabbix
|
||||||
ZBX_SESSION_NAME: zbx_sessionid_new
|
ZBX_SESSION_NAME: zbx_sessionid_new
|
||||||
volumes:
|
volumes:
|
||||||
- ./ssl:/etc/ssl/apache2:ro
|
- ../nginx:/etc/nginx/ssl:ro
|
||||||
|
- ../nginx/default.conf:/etc/nginx/http.d/default.conf:ro
|
||||||
|
- ../nginx/.htpasswd:/etc/nginx/.htpasswd:ro
|
||||||
|
|
||||||
database:
|
database:
|
||||||
image: postgres:14
|
image: postgres:14
|
||||||
@@ -76,7 +105,6 @@ services:
|
|||||||
ZBX_HOSTS_NUMBER: 10
|
ZBX_HOSTS_NUMBER: 10
|
||||||
environment:
|
environment:
|
||||||
ZBX_API_URL: http://zabbix-web:8080
|
ZBX_API_URL: http://zabbix-web:8080
|
||||||
# ZBX_API_URL: http://zabbix-web:80
|
|
||||||
ZBX_API_USER: Admin
|
ZBX_API_USER: Admin
|
||||||
ZBX_API_PASSWORD: zabbix
|
ZBX_API_PASSWORD: zabbix
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -98,7 +126,6 @@ services:
|
|||||||
- ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg
|
- ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg
|
||||||
environment:
|
environment:
|
||||||
REDIS_HOST: redis_backend
|
REDIS_HOST: redis_backend
|
||||||
# restart: always
|
|
||||||
|
|
||||||
zas_backend_02:
|
zas_backend_02:
|
||||||
build: ../zas-agent
|
build: ../zas-agent
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
ssl-cert:
|
||||||
|
image: alpine:latest
|
||||||
|
command: |
|
||||||
|
sh -c "if [ ! -f /certs/nginx.crt ] || [ ! -f /certs/nginx.key ]; then
|
||||||
|
apk add --no-cache openssl &&
|
||||||
|
mkdir -p /certs &&
|
||||||
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /certs/nginx.key -out /certs/nginx.crt -subj '/C=US/ST=State/L=City/O=Organization/CN=localhost' &&
|
||||||
|
chmod 644 /certs/nginx.crt /certs/nginx.key
|
||||||
|
else
|
||||||
|
echo 'SSL certificates already exist, skipping generation'
|
||||||
|
fi"
|
||||||
|
volumes:
|
||||||
|
- ../nginx:/certs
|
||||||
|
|
||||||
# Grafana
|
# Grafana
|
||||||
grafana:
|
grafana:
|
||||||
image: grafana/grafana:10.1.2
|
image: grafana/grafana:main
|
||||||
ports:
|
ports:
|
||||||
- '3001:3000'
|
- '3001:3000'
|
||||||
volumes:
|
volumes:
|
||||||
@@ -32,12 +44,17 @@ services:
|
|||||||
ZBX_DEBUGLEVEL: 3
|
ZBX_DEBUGLEVEL: 3
|
||||||
|
|
||||||
zabbix-web:
|
zabbix-web:
|
||||||
image: zabbix/zabbix-web-apache-pgsql:alpine-6.0-latest
|
image: zabbix/zabbix-web-nginx-pgsql:alpine-6.0-latest
|
||||||
ports:
|
ports:
|
||||||
|
- '443:443'
|
||||||
- '8188:8080'
|
- '8188:8080'
|
||||||
depends_on:
|
depends_on:
|
||||||
- database
|
- database
|
||||||
- zabbix-server
|
- zabbix-server
|
||||||
|
volumes:
|
||||||
|
- ../nginx:/etc/nginx/ssl:ro
|
||||||
|
- ../nginx/default.conf:/etc/nginx/http.d/default.conf:ro
|
||||||
|
- ../nginx/.htpasswd:/etc/nginx/.htpasswd:ro
|
||||||
environment:
|
environment:
|
||||||
ZBX_SERVER_HOST: zabbix-server
|
ZBX_SERVER_HOST: zabbix-server
|
||||||
ZBX_SERVER_PORT: 10051
|
ZBX_SERVER_PORT: 10051
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
FROM python:2.7
|
|
||||||
|
|
||||||
ENV ZBX_API_URL=http://zabbix-web:8080
|
|
||||||
ENV ZBX_API_USER="Admin"
|
|
||||||
ENV ZBX_API_PASSWORD="zabbix"
|
|
||||||
ENV ZBX_CONFIG="zbx_export_hosts.xml"
|
|
||||||
ENV ZBX_BOOTSTRAP_SCRIPT="bootstrap_config.py"
|
|
||||||
|
|
||||||
RUN pip install pyzabbix
|
|
||||||
|
|
||||||
ADD ./bootstrap_config.py /bootstrap_config.py
|
|
||||||
ADD ${ZBX_CONFIG} /${ZBX_CONFIG}
|
|
||||||
|
|
||||||
WORKDIR /
|
|
||||||
|
|
||||||
# Run bootstrap_config.py when the container launches
|
|
||||||
CMD ["python", "/bootstrap_config.py"]
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
import os
|
|
||||||
from time import sleep
|
|
||||||
from pyzabbix import ZabbixAPI, ZabbixAPIException
|
|
||||||
|
|
||||||
zabbix_url = os.environ['ZBX_API_URL']
|
|
||||||
zabbix_user = os.environ['ZBX_API_USER']
|
|
||||||
zabbix_password = os.environ['ZBX_API_PASSWORD']
|
|
||||||
print(zabbix_url, zabbix_user, zabbix_password)
|
|
||||||
|
|
||||||
zapi = ZabbixAPI(zabbix_url, timeout=5)
|
|
||||||
|
|
||||||
for i in range(10):
|
|
||||||
print("Trying to connected to Zabbix API %s" % zabbix_url)
|
|
||||||
try:
|
|
||||||
zapi.login(zabbix_user, zabbix_password)
|
|
||||||
print("Connected to Zabbix API Version %s" % zapi.api_version())
|
|
||||||
break
|
|
||||||
except ZabbixAPIException as e:
|
|
||||||
print e
|
|
||||||
sleep(5)
|
|
||||||
except:
|
|
||||||
print("Waiting")
|
|
||||||
sleep(5)
|
|
||||||
|
|
||||||
|
|
||||||
config_path = os.environ['ZBX_CONFIG']
|
|
||||||
import_rules = {
|
|
||||||
'discoveryRules': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'graphs': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'host_groups': {
|
|
||||||
'createMissing': True
|
|
||||||
},
|
|
||||||
'hosts': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'images': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'items': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'maps': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'templateLinkage': {
|
|
||||||
'createMissing': True,
|
|
||||||
},
|
|
||||||
'templates': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
'triggers': {
|
|
||||||
'createMissing': True,
|
|
||||||
'updateExisting': True
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
print("Importing Zabbix config from %s" % config_path)
|
|
||||||
with open(config_path, 'r') as f:
|
|
||||||
config = f.read()
|
|
||||||
|
|
||||||
try:
|
|
||||||
# https://github.com/lukecyca/pyzabbix/issues/62
|
|
||||||
import_result = zapi.confimport("xml", config, import_rules)
|
|
||||||
print(import_result)
|
|
||||||
except ZabbixAPIException as e:
|
|
||||||
print e
|
|
||||||
|
|
||||||
for h in zapi.host.get(output="extend"):
|
|
||||||
print(h['name'])
|
|
||||||
@@ -1,432 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<zabbix_export>
|
|
||||||
<version>6.2</version>
|
|
||||||
<date>2022-04-28T13:04:18Z</date>
|
|
||||||
<host_groups>
|
|
||||||
<host_group>
|
|
||||||
<uuid>2e427c268ac1468b9add94b65e2d6c14</uuid>
|
|
||||||
<name>Backend</name>
|
|
||||||
</host_group>
|
|
||||||
<host_group>
|
|
||||||
<uuid>d97ba66b283544339628b71975a6e68d</uuid>
|
|
||||||
<name>Frontend</name>
|
|
||||||
</host_group>
|
|
||||||
<host_group>
|
|
||||||
<uuid>dc579cd7a1a34222933f24f52a68bcd8</uuid>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</host_group>
|
|
||||||
<host_group>
|
|
||||||
<uuid>6f6799aa69e844b4b3918f779f2abf08</uuid>
|
|
||||||
<name>Zabbix servers</name>
|
|
||||||
</host_group>
|
|
||||||
<host_group>
|
|
||||||
<uuid>7df96b18c230490a9a0a9e2307226338</uuid>
|
|
||||||
<name>Templates</name>
|
|
||||||
</host_group>
|
|
||||||
</host_groups>
|
|
||||||
<hosts>
|
|
||||||
<host>
|
|
||||||
<host>backend01</host>
|
|
||||||
<name>backend01</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Backend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_backend_01</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>backend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>backend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>backend02</host>
|
|
||||||
<name>backend02</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Backend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_backend_02</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>backend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>backend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>frontend01</host>
|
|
||||||
<name>frontend01</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Frontend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_frontend_01</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>frontend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>frontend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>frontend02</host>
|
|
||||||
<name>frontend02</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Frontend</name>
|
|
||||||
</group>
|
|
||||||
<group>
|
|
||||||
<name>Linux servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zas_frontend_02</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>frontend</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>service</tag>
|
|
||||||
<value>frontend</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
<host>
|
|
||||||
<host>Zabbix server</host>
|
|
||||||
<name>Zabbix server</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Linux by Zabbix agent</name>
|
|
||||||
</template>
|
|
||||||
<template>
|
|
||||||
<name>Zabbix server health</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Zabbix servers</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<interfaces>
|
|
||||||
<interface>
|
|
||||||
<useip>NO</useip>
|
|
||||||
<dns>zabbix-agent</dns>
|
|
||||||
<interface_ref>if1</interface_ref>
|
|
||||||
</interface>
|
|
||||||
</interfaces>
|
|
||||||
<inventory_mode>DISABLED</inventory_mode>
|
|
||||||
</host>
|
|
||||||
</hosts>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<uuid>2d7a65bb369c48199361913b223b1695</uuid>
|
|
||||||
<template>Template ZAS Agent</template>
|
|
||||||
<name>Template ZAS Agent</name>
|
|
||||||
<templates>
|
|
||||||
<template>
|
|
||||||
<name>Zabbix agent</name>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<groups>
|
|
||||||
<group>
|
|
||||||
<name>Templates</name>
|
|
||||||
</group>
|
|
||||||
</groups>
|
|
||||||
<items>
|
|
||||||
<item>
|
|
||||||
<uuid>e79d4215ec014b74923b905bb8f82410</uuid>
|
|
||||||
<name>Incoming network traffic on eth0</name>
|
|
||||||
<key>net.if.in[eth0]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<units>bps</units>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Network interfaces</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>18b377dae9fe48d093c16ee7a7c93320</uuid>
|
|
||||||
<name>Outgoing network traffic on eth0</name>
|
|
||||||
<key>net.if.out[eth0]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<units>bps</units>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Network interfaces</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>2479e055e91c476f9be93b5f363cfa2f</uuid>
|
|
||||||
<name>Processor load (1 min average per core)</name>
|
|
||||||
<key>system.cpu.load[percpu,avg1]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<description>The processor load is calculated as system CPU load divided by number of CPU cores.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<triggers>
|
|
||||||
<trigger>
|
|
||||||
<uuid>60e5484b60ca4061b21bd23f8364bd6e</uuid>
|
|
||||||
<expression>last(/Template ZAS Agent/system.cpu.load[percpu,avg1])>2</expression>
|
|
||||||
<name>Processor load is too high on {HOST.NAME}</name>
|
|
||||||
<priority>WARNING</priority>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>app</tag>
|
|
||||||
<value>performance</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>type</tag>
|
|
||||||
<value>cpu</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</trigger>
|
|
||||||
</triggers>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>f0dd4221793c49889cf2789806afa597</uuid>
|
|
||||||
<name>Processor load (15 min average per core)</name>
|
|
||||||
<key>system.cpu.load[percpu,avg15]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<description>The processor load is calculated as system CPU load divided by number of CPU cores.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>9a8b4a1f173b4f209723d820dc2e054a</uuid>
|
|
||||||
<name>CPU $2 time</name>
|
|
||||||
<key>system.cpu.util[,iowait]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<units>%</units>
|
|
||||||
<description>Amount of time the CPU has been waiting for I/O to complete.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
<triggers>
|
|
||||||
<trigger>
|
|
||||||
<uuid>ceb468b9eb434fa6bd4c8a5d7507fd87</uuid>
|
|
||||||
<expression>avg(/Template ZAS Agent/system.cpu.util[,iowait],5m)>20</expression>
|
|
||||||
<name>Disk I/O is overloaded on {HOST.NAME}</name>
|
|
||||||
<priority>WARNING</priority>
|
|
||||||
<description>OS spends significant time waiting for I/O (input/output) operations. It could be indicator of performance issues with storage system.</description>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>disk</tag>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>type</tag>
|
|
||||||
<value>disk</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</trigger>
|
|
||||||
</triggers>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>e6d19d47cf60452ead1e791da2d5c0dc</uuid>
|
|
||||||
<name>CPU $2 time</name>
|
|
||||||
<key>system.cpu.util[,system]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<units>%</units>
|
|
||||||
<description>The time the CPU has spent running the kernel and its processes.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<uuid>2d81fbc139774306959712a627c99b9a</uuid>
|
|
||||||
<name>CPU $2 time</name>
|
|
||||||
<key>system.cpu.util[,user]</key>
|
|
||||||
<history>1d</history>
|
|
||||||
<value_type>FLOAT</value_type>
|
|
||||||
<units>%</units>
|
|
||||||
<description>The time the CPU has spent running users' processes that are not niced.</description>
|
|
||||||
<request_method>POST</request_method>
|
|
||||||
<tags>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>CPU</value>
|
|
||||||
</tag>
|
|
||||||
<tag>
|
|
||||||
<tag>Application</tag>
|
|
||||||
<value>Performance</value>
|
|
||||||
</tag>
|
|
||||||
</tags>
|
|
||||||
</item>
|
|
||||||
</items>
|
|
||||||
</template>
|
|
||||||
</templates>
|
|
||||||
<graphs>
|
|
||||||
<graph>
|
|
||||||
<uuid>7aac0ec0c0e04b7a8bb6472d1faa7a09</uuid>
|
|
||||||
<name>CPU load</name>
|
|
||||||
<ymin_type_1>FIXED</ymin_type_1>
|
|
||||||
<graph_items>
|
|
||||||
<graph_item>
|
|
||||||
<color>009900</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.load[percpu,avg1]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>2</sortorder>
|
|
||||||
<color>990000</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.load[percpu,avg15]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
</graph_items>
|
|
||||||
</graph>
|
|
||||||
<graph>
|
|
||||||
<uuid>f25064d88b964a678fac7ea6095b238a</uuid>
|
|
||||||
<name>CPU utilization</name>
|
|
||||||
<show_triggers>NO</show_triggers>
|
|
||||||
<type>STACKED</type>
|
|
||||||
<ymin_type_1>FIXED</ymin_type_1>
|
|
||||||
<ymax_type_1>FIXED</ymax_type_1>
|
|
||||||
<graph_items>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>4</sortorder>
|
|
||||||
<drawtype>FILLED_REGION</drawtype>
|
|
||||||
<color>999900</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.util[,iowait]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>5</sortorder>
|
|
||||||
<drawtype>FILLED_REGION</drawtype>
|
|
||||||
<color>990000</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.util[,system]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
<graph_item>
|
|
||||||
<sortorder>6</sortorder>
|
|
||||||
<drawtype>FILLED_REGION</drawtype>
|
|
||||||
<color>000099</color>
|
|
||||||
<item>
|
|
||||||
<host>Template ZAS Agent</host>
|
|
||||||
<key>system.cpu.util[,user]</key>
|
|
||||||
</item>
|
|
||||||
</graph_item>
|
|
||||||
</graph_items>
|
|
||||||
</graph>
|
|
||||||
</graphs>
|
|
||||||
</zabbix_export>
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
|
||||||
# Grafana
|
|
||||||
grafana:
|
|
||||||
image: grafana/grafana:10.1.2
|
|
||||||
ports:
|
|
||||||
- '3001:3000'
|
|
||||||
volumes:
|
|
||||||
- ../..:/grafana-zabbix
|
|
||||||
- ../dashboards:/devenv/dashboards
|
|
||||||
- ../grafana.ini:/etc/grafana/grafana.ini:ro
|
|
||||||
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
|
|
||||||
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'
|
|
||||||
|
|
||||||
# Zabbix
|
|
||||||
zabbix-server:
|
|
||||||
image: zabbix/zabbix-server-pgsql:alpine-6.2-latest
|
|
||||||
ports:
|
|
||||||
- '10051:10051'
|
|
||||||
depends_on:
|
|
||||||
- database
|
|
||||||
environment:
|
|
||||||
DB_SERVER_HOST: database
|
|
||||||
DB_SERVER_PORT: 5432
|
|
||||||
POSTGRES_USER: zabbix
|
|
||||||
POSTGRES_PASSWORD: zabbix
|
|
||||||
POSTGRES_DB: zabbix
|
|
||||||
ZBX_TIMEOUT: 10
|
|
||||||
ZBX_STARTPOLLERS: 10
|
|
||||||
ZBX_STARTPOLLERSUNREACHABLE: 5
|
|
||||||
ZBX_DEBUGLEVEL: 3
|
|
||||||
|
|
||||||
zabbix-web:
|
|
||||||
image: zabbix/zabbix-web-apache-pgsql:alpine-6.2-latest
|
|
||||||
ports:
|
|
||||||
- '8188:8080'
|
|
||||||
depends_on:
|
|
||||||
- database
|
|
||||||
- zabbix-server
|
|
||||||
environment:
|
|
||||||
ZBX_SERVER_HOST: zabbix-server
|
|
||||||
ZBX_SERVER_PORT: 10051
|
|
||||||
DB_SERVER_HOST: database
|
|
||||||
DB_SERVER_PORT: 5432
|
|
||||||
POSTGRES_USER: zabbix
|
|
||||||
POSTGRES_PASSWORD: zabbix
|
|
||||||
POSTGRES_DB: zabbix
|
|
||||||
|
|
||||||
database:
|
|
||||||
image: postgres:15
|
|
||||||
ports:
|
|
||||||
- '15432:5432'
|
|
||||||
command: postgres -c 'max_connections=1000'
|
|
||||||
environment:
|
|
||||||
POSTGRES_USER: zabbix
|
|
||||||
POSTGRES_PASSWORD: zabbix
|
|
||||||
|
|
||||||
zabbix-agent:
|
|
||||||
image: zabbix/zabbix-agent:alpine-6.2-latest
|
|
||||||
environment:
|
|
||||||
ZBX_SERVER_HOST: zabbix-server
|
|
||||||
ZBX_SERVER_PORT: 10051
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# Bootstrap config
|
|
||||||
#########################################################
|
|
||||||
|
|
||||||
bootstrap:
|
|
||||||
build: ./bootstrap
|
|
||||||
environment:
|
|
||||||
ZBX_API_URL: http://zabbix-web:8080
|
|
||||||
ZBX_API_USER: Admin
|
|
||||||
ZBX_API_PASSWORD: zabbix
|
|
||||||
depends_on:
|
|
||||||
- database
|
|
||||||
- zabbix-server
|
|
||||||
- zabbix-web
|
|
||||||
|
|
||||||
#########################################################
|
|
||||||
# Fake agents
|
|
||||||
#########################################################
|
|
||||||
|
|
||||||
# backend
|
|
||||||
redis_backend:
|
|
||||||
image: redis:alpine
|
|
||||||
|
|
||||||
zas_backend_01:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_backend
|
|
||||||
# restart: always
|
|
||||||
|
|
||||||
zas_backend_02:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_backend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_backend
|
|
||||||
|
|
||||||
# frontend
|
|
||||||
redis_frontend:
|
|
||||||
image: redis:alpine
|
|
||||||
|
|
||||||
zas_frontend_01:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_frontend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_frontend
|
|
||||||
|
|
||||||
zas_frontend_02:
|
|
||||||
build: ../zas-agent
|
|
||||||
volumes:
|
|
||||||
- ../zas-agent/conf/zas_scenario_frontend.cfg:/etc/zas_scenario.cfg
|
|
||||||
environment:
|
|
||||||
REDIS_HOST: redis_frontend
|
|
||||||
@@ -1,9 +1,21 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
ssl-cert:
|
||||||
|
image: alpine:latest
|
||||||
|
command: |
|
||||||
|
sh -c "if [ ! -f /certs/nginx.crt ] || [ ! -f /certs/nginx.key ]; then
|
||||||
|
apk add --no-cache openssl &&
|
||||||
|
mkdir -p /certs &&
|
||||||
|
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /certs/nginx.key -out /certs/nginx.crt -subj '/C=US/ST=State/L=City/O=Organization/CN=localhost' &&
|
||||||
|
chmod 644 /certs/nginx.crt /certs/nginx.key
|
||||||
|
else
|
||||||
|
echo 'SSL certificates already exist, skipping generation'
|
||||||
|
fi"
|
||||||
|
volumes:
|
||||||
|
- ../nginx:/certs
|
||||||
|
|
||||||
# Grafana
|
# Grafana
|
||||||
grafana:
|
grafana:
|
||||||
image: grafana/grafana:10.1.2
|
image: grafana/grafana:main
|
||||||
ports:
|
ports:
|
||||||
- '3001:3000'
|
- '3001:3000'
|
||||||
volumes:
|
volumes:
|
||||||
@@ -32,12 +44,17 @@ services:
|
|||||||
ZBX_DEBUGLEVEL: 3
|
ZBX_DEBUGLEVEL: 3
|
||||||
|
|
||||||
zabbix-web:
|
zabbix-web:
|
||||||
image: zabbix/zabbix-web-apache-pgsql:alpine-7.0-latest
|
image: zabbix/zabbix-web-nginx-pgsql:alpine-7.0-latest
|
||||||
ports:
|
ports:
|
||||||
|
- '443:443'
|
||||||
- '8188:8080'
|
- '8188:8080'
|
||||||
depends_on:
|
depends_on:
|
||||||
- database
|
- database
|
||||||
- zabbix-server
|
- zabbix-server
|
||||||
|
volumes:
|
||||||
|
- ../nginx:/etc/nginx/ssl:ro
|
||||||
|
- ../nginx/default.conf:/etc/nginx/http.d/default.conf:ro
|
||||||
|
- ../nginx/.htpasswd:/etc/nginx/.htpasswd:ro
|
||||||
environment:
|
environment:
|
||||||
ZBX_SERVER_HOST: zabbix-server
|
ZBX_SERVER_HOST: zabbix-server
|
||||||
ZBX_SERVER_PORT: 10051
|
ZBX_SERVER_PORT: 10051
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# Grafana
|
# Grafana
|
||||||
# grafana:
|
grafana:
|
||||||
# image: grafana/grafana:10.1.2
|
image: grafana/grafana:main
|
||||||
# ports:
|
ports:
|
||||||
# - '3001:3000'
|
- '3001:3000'
|
||||||
# volumes:
|
volumes:
|
||||||
# - ../..:/grafana-zabbix
|
- ../..:/grafana-zabbix
|
||||||
# - ../dashboards:/devenv/dashboards
|
- ../dashboards:/devenv/dashboards
|
||||||
# - ../grafana.ini:/etc/grafana/grafana.ini:ro
|
- ../grafana.ini:/etc/grafana/grafana.ini:ro
|
||||||
# - '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
|
- '../datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml'
|
||||||
# - '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'
|
- '../dashboards.yaml:/etc/grafana/provisioning/dashboards/dashboards.yaml'
|
||||||
|
|
||||||
# Zabbix
|
# Zabbix
|
||||||
zabbix-server:
|
zabbix-server:
|
||||||
image: zabbix/zabbix-server-pgsql:alpine-7.2-latest
|
image: zabbix/zabbix-server-pgsql:alpine-7.2-latest
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func newZabbixDatasourceInstance(ctx context.Context, dsSettings backend.DataSou
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
zabbixAPI, err := zabbixapi.New(dsSettings.URL, client)
|
zabbixAPI, err := zabbixapi.New(dsSettings, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Error initializing Zabbix API", "error", err)
|
logger.Error("Error initializing Zabbix API", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ var (
|
|||||||
// ZabbixAPI is a simple client responsible for making request to Zabbix API
|
// ZabbixAPI is a simple client responsible for making request to Zabbix API
|
||||||
type ZabbixAPI struct {
|
type ZabbixAPI struct {
|
||||||
url *url.URL
|
url *url.URL
|
||||||
|
dsSettings backend.DataSourceInstanceSettings
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
auth string
|
auth string
|
||||||
@@ -34,15 +35,16 @@ type ZabbixAPI struct {
|
|||||||
type ZabbixAPIParams = map[string]interface{}
|
type ZabbixAPIParams = map[string]interface{}
|
||||||
|
|
||||||
// New returns new ZabbixAPI instance initialized with given URL or error.
|
// New returns new ZabbixAPI instance initialized with given URL or error.
|
||||||
func New(apiURL string, client *http.Client) (*ZabbixAPI, error) {
|
func New(dsSettings backend.DataSourceInstanceSettings, client *http.Client) (*ZabbixAPI, error) {
|
||||||
apiLogger := log.New()
|
apiLogger := log.New()
|
||||||
zabbixURL, err := url.Parse(apiURL)
|
zabbixURL, err := url.Parse(dsSettings.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ZabbixAPI{
|
return &ZabbixAPI{
|
||||||
url: zabbixURL,
|
url: zabbixURL,
|
||||||
|
dsSettings: dsSettings,
|
||||||
logger: apiLogger,
|
logger: apiLogger,
|
||||||
httpClient: client,
|
httpClient: client,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -98,7 +100,7 @@ func (api *ZabbixAPI) request(ctx context.Context, method string, params ZabbixA
|
|||||||
|
|
||||||
// Zabbix v7.2 and later deprecated `auth` parameter and replaced it with using Auth header
|
// Zabbix v7.2 and later deprecated `auth` parameter and replaced it with using Auth header
|
||||||
// `auth` parameter throws an error in new versions so we need to add it only for older versions
|
// `auth` parameter throws an error in new versions so we need to add it only for older versions
|
||||||
if auth != "" && version < 70 {
|
if auth != "" && version < 72 {
|
||||||
apiRequest["auth"] = auth
|
apiRequest["auth"] = auth
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +116,10 @@ func (api *ZabbixAPI) request(ctx context.Context, method string, params ZabbixA
|
|||||||
|
|
||||||
metrics.ZabbixAPIQueryTotal.WithLabelValues(method).Inc()
|
metrics.ZabbixAPIQueryTotal.WithLabelValues(method).Inc()
|
||||||
|
|
||||||
if auth != "" {
|
if auth != "" && version >= 72 {
|
||||||
|
if api.dsSettings.BasicAuthEnabled {
|
||||||
|
return nil, backend.DownstreamError(errors.New("Basic Auth is not supported for Zabbix v7.2 and later"))
|
||||||
|
}
|
||||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", auth))
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", auth))
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|||||||
148
pkg/zabbixapi/zabbix_api_50_integration_test.go
Normal file
148
pkg/zabbixapi/zabbix_api_50_integration_test.go
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
package zabbixapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/alexanderzobnin/grafana-zabbix/pkg/httpclient"
|
||||||
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These tests require a running Zabbix server and proper environment variables
|
||||||
|
// ZABBIX_URL - URL of the Zabbix server (e.g., http://localhost/zabbix/api_jsonrpc.php)
|
||||||
|
// ZABBIX_USER - Username for authentication
|
||||||
|
// ZABBIX_PASSWORD - Password for authentication
|
||||||
|
// To run locally, start devenv/zabbix50 and run INTEGRATION_TEST50=true ZABBIX_URL="https://localhost/api_jsonrpc.php" ZABBIX_USER="Admin" ZABBIX_PASSWORD="zabbix" go test -v ./pkg/zabbixapi/...
|
||||||
|
func TestIntegrationZabbixAPI50(t *testing.T) {
|
||||||
|
// Skip if not running integration tests
|
||||||
|
if os.Getenv("INTEGRATION_TEST50") != "true" {
|
||||||
|
t.Skip("Skipping integration test")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get test configuration from environment
|
||||||
|
zabbixURL := os.Getenv("ZABBIX_URL")
|
||||||
|
zabbixUser := os.Getenv("ZABBIX_USER")
|
||||||
|
zabbixPassword := os.Getenv("ZABBIX_PASSWORD")
|
||||||
|
zabbixVersion := 50
|
||||||
|
|
||||||
|
// Validate required environment variables
|
||||||
|
require.NotEmpty(t, zabbixURL, "ZABBIX_URL environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixUser, "ZABBIX_USER environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixPassword, "ZABBIX_PASSWORD environment variable is required")
|
||||||
|
|
||||||
|
// Create new Zabbix API instance
|
||||||
|
dsSettings := backend.DataSourceInstanceSettings{
|
||||||
|
URL: zabbixURL,
|
||||||
|
BasicAuthEnabled: true,
|
||||||
|
BasicAuthUser: "admin",
|
||||||
|
DecryptedSecureJSONData: map[string]string{
|
||||||
|
"basicAuthPassword": "secret",
|
||||||
|
},
|
||||||
|
JSONData: json.RawMessage(`{"tlsSkipVerify": true}`),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create HTTP client with TLS skip verify and basic auth
|
||||||
|
httpClient, err := httpclient.New(context.Background(), &dsSettings, 10*time.Second)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, httpClient)
|
||||||
|
|
||||||
|
// Create new Zabbix API instance with basic auth client
|
||||||
|
api, err := New(dsSettings, httpClient)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, api)
|
||||||
|
|
||||||
|
// Test authentication
|
||||||
|
t.Run("Authentication", func(t *testing.T) {
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, api.GetAuth(), "Authentication token should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test API version check
|
||||||
|
t.Run("API Version Check", func(t *testing.T) {
|
||||||
|
// Try to get API version
|
||||||
|
resp, err := api.RequestUnauthenticated(context.Background(), "apiinfo.version", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
version := resp.MustString()
|
||||||
|
assert.NotEmpty(t, version, "API version should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test host group retrieval
|
||||||
|
t.Run("Get Host Groups", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Get host groups
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"output": "extend",
|
||||||
|
}
|
||||||
|
resp, err := api.Request(context.Background(), "hostgroup.get", params, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
// Verify response is an array
|
||||||
|
groups, err := resp.Array()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotNil(t, groups, "Host groups should not be nil")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test error handling
|
||||||
|
t.Run("Error Handling", func(t *testing.T) {
|
||||||
|
// Try to make a request without authentication
|
||||||
|
api.SetAuth("")
|
||||||
|
_, err := api.Request(context.Background(), "hostgroup.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.True(t, backend.IsDownstreamError(err))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test auth parameter is in request body for v5.0
|
||||||
|
t.Run("Auth Parameter In Request Body", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Create a test client that captures the request body
|
||||||
|
var requestBody map[string]interface{}
|
||||||
|
testClient := NewTestClient(func(req *http.Request) *http.Response {
|
||||||
|
// Read and parse the request body
|
||||||
|
body, err := io.ReadAll(req.Body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(body, &requestBody)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth header is not present
|
||||||
|
assert.Empty(t, req.Header.Get("Authorization"), "Authorization header should not be present for v5.0")
|
||||||
|
|
||||||
|
// Return a mock response
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: 200,
|
||||||
|
Body: io.NopCloser(bytes.NewBufferString(`{"result": "test"}`)),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create a new API instance with the test client
|
||||||
|
apiWithTestClient, err := New(dsSettings, testClient)
|
||||||
|
require.NoError(t, err)
|
||||||
|
apiWithTestClient.SetAuth(api.GetAuth())
|
||||||
|
|
||||||
|
// Make a request
|
||||||
|
_, err = apiWithTestClient.Request(context.Background(), "test.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth parameter is in the request body
|
||||||
|
auth, hasAuth := requestBody["auth"]
|
||||||
|
assert.True(t, hasAuth, "Auth parameter should be present in request body for v5.0")
|
||||||
|
assert.Equal(t, api.GetAuth(), auth, "Auth parameter should match the set auth token")
|
||||||
|
})
|
||||||
|
}
|
||||||
147
pkg/zabbixapi/zabbix_api_60_integration_test.go
Normal file
147
pkg/zabbixapi/zabbix_api_60_integration_test.go
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
package zabbixapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/alexanderzobnin/grafana-zabbix/pkg/httpclient"
|
||||||
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These tests require a running Zabbix server and proper environment variables
|
||||||
|
// ZABBIX_URL - URL of the Zabbix server (e.g., http://localhost/zabbix/api_jsonrpc.php)
|
||||||
|
// ZABBIX_USER - Username for authentication
|
||||||
|
// ZABBIX_PASSWORD - Password for authentication
|
||||||
|
// To run locally, start devenv/zabbix60 and run INTEGRATION_TEST60=true ZABBIX_URL="https://localhost/api_jsonrpc.php" ZABBIX_USER="Admin" ZABBIX_PASSWORD="zabbix" go test -v ./pkg/zabbixapi/...
|
||||||
|
func TestIntegrationZabbixAPI60(t *testing.T) {
|
||||||
|
// Skip if not running integration tests
|
||||||
|
if os.Getenv("INTEGRATION_TEST60") != "true" {
|
||||||
|
t.Skip("Skipping integration test")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get test configuration from environment
|
||||||
|
zabbixURL := os.Getenv("ZABBIX_URL")
|
||||||
|
zabbixUser := os.Getenv("ZABBIX_USER")
|
||||||
|
zabbixPassword := os.Getenv("ZABBIX_PASSWORD")
|
||||||
|
zabbixVersion := 60
|
||||||
|
|
||||||
|
// Validate required environment variables
|
||||||
|
require.NotEmpty(t, zabbixURL, "ZABBIX_URL environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixUser, "ZABBIX_USER environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixPassword, "ZABBIX_PASSWORD environment variable is required")
|
||||||
|
|
||||||
|
dsSettings := backend.DataSourceInstanceSettings{
|
||||||
|
URL: zabbixURL,
|
||||||
|
BasicAuthEnabled: true,
|
||||||
|
BasicAuthUser: "admin",
|
||||||
|
DecryptedSecureJSONData: map[string]string{
|
||||||
|
"basicAuthPassword": "secret",
|
||||||
|
},
|
||||||
|
JSONData: json.RawMessage(`{"tlsSkipVerify": true}`),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create HTTP client with TLS skip verify and basic auth
|
||||||
|
httpClient, err := httpclient.New(context.Background(), &dsSettings, 10*time.Second)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, httpClient)
|
||||||
|
|
||||||
|
// Create new Zabbix API instance with basic auth client
|
||||||
|
api, err := New(dsSettings, httpClient)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, api)
|
||||||
|
|
||||||
|
// Test authentication
|
||||||
|
t.Run("Authentication", func(t *testing.T) {
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, api.GetAuth(), "Authentication token should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test API version check
|
||||||
|
t.Run("API Version Check", func(t *testing.T) {
|
||||||
|
// Try to get API version
|
||||||
|
resp, err := api.RequestUnauthenticated(context.Background(), "apiinfo.version", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
version := resp.MustString()
|
||||||
|
assert.NotEmpty(t, version, "API version should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test host group retrieval
|
||||||
|
t.Run("Get Host Groups", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Get host groups
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"output": "extend",
|
||||||
|
}
|
||||||
|
resp, err := api.Request(context.Background(), "hostgroup.get", params, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
// Verify response is an array
|
||||||
|
groups, err := resp.Array()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotNil(t, groups, "Host groups should not be nil")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test error handling
|
||||||
|
t.Run("Error Handling", func(t *testing.T) {
|
||||||
|
// Try to make a request without authentication
|
||||||
|
api.SetAuth("")
|
||||||
|
_, err := api.Request(context.Background(), "hostgroup.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.True(t, backend.IsDownstreamError(err))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test auth parameter is in request body for v6.0
|
||||||
|
t.Run("Auth Parameter In Request Body", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Create a test client that captures the request body
|
||||||
|
var requestBody map[string]interface{}
|
||||||
|
testClient := NewTestClient(func(req *http.Request) *http.Response {
|
||||||
|
// Read and parse the request body
|
||||||
|
body, err := io.ReadAll(req.Body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(body, &requestBody)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth header is not present
|
||||||
|
assert.Empty(t, req.Header.Get("Authorization"), "Authorization header should not be present for v6.0")
|
||||||
|
|
||||||
|
// Return a mock response
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: 200,
|
||||||
|
Body: io.NopCloser(bytes.NewBufferString(`{"result": "test"}`)),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create a new API instance with the test client
|
||||||
|
apiWithTestClient, err := New(dsSettings, testClient)
|
||||||
|
require.NoError(t, err)
|
||||||
|
apiWithTestClient.SetAuth(api.GetAuth())
|
||||||
|
|
||||||
|
// Make a request
|
||||||
|
_, err = apiWithTestClient.Request(context.Background(), "test.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth parameter is in the request body
|
||||||
|
auth, hasAuth := requestBody["auth"]
|
||||||
|
assert.True(t, hasAuth, "Auth parameter should be present in request body for v6.0")
|
||||||
|
assert.Equal(t, api.GetAuth(), auth, "Auth parameter should match the set auth token")
|
||||||
|
})
|
||||||
|
}
|
||||||
149
pkg/zabbixapi/zabbix_api_70_integration_test.go
Normal file
149
pkg/zabbixapi/zabbix_api_70_integration_test.go
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
package zabbixapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/alexanderzobnin/grafana-zabbix/pkg/httpclient"
|
||||||
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These tests require a running Zabbix server and proper environment variables
|
||||||
|
// ZABBIX_URL - URL of the Zabbix server (e.g., http://localhost/zabbix/api_jsonrpc.php)
|
||||||
|
// ZABBIX_USER - Username for authentication
|
||||||
|
// ZABBIX_PASSWORD - Password for authentication
|
||||||
|
// ZABBIX_VERSION - Zabbix API version (e.g., 65 for 6.5)
|
||||||
|
// To run locally, start devenv/zabbix70 and run INTEGRATION_TEST70=true ZABBIX_URL="https://localhost/api_jsonrpc.php" ZABBIX_USER="Admin" ZABBIX_PASSWORD="zabbix" go test -v ./pkg/zabbixapi/...
|
||||||
|
|
||||||
|
func TestIntegrationZabbixAPI70(t *testing.T) {
|
||||||
|
// Skip if not running integration tests
|
||||||
|
if os.Getenv("INTEGRATION_TEST70") != "true" {
|
||||||
|
t.Skip("Skipping integration test")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get test configuration from environment
|
||||||
|
zabbixURL := os.Getenv("ZABBIX_URL")
|
||||||
|
zabbixUser := os.Getenv("ZABBIX_USER")
|
||||||
|
zabbixPassword := os.Getenv("ZABBIX_PASSWORD")
|
||||||
|
zabbixVersion := 70
|
||||||
|
|
||||||
|
// Validate required environment variables
|
||||||
|
require.NotEmpty(t, zabbixURL, "ZABBIX_URL environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixUser, "ZABBIX_USER environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixPassword, "ZABBIX_PASSWORD environment variable is required")
|
||||||
|
|
||||||
|
dsSettings := backend.DataSourceInstanceSettings{
|
||||||
|
URL: zabbixURL,
|
||||||
|
BasicAuthEnabled: true,
|
||||||
|
BasicAuthUser: "admin",
|
||||||
|
DecryptedSecureJSONData: map[string]string{
|
||||||
|
"basicAuthPassword": "secret",
|
||||||
|
},
|
||||||
|
JSONData: json.RawMessage(`{"tlsSkipVerify": true}`),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create HTTP client with TLS skip verify and basic auth
|
||||||
|
httpClient, err := httpclient.New(context.Background(), &dsSettings, 10*time.Second)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, httpClient)
|
||||||
|
|
||||||
|
// Create new Zabbix API instance with basic auth client
|
||||||
|
api, err := New(dsSettings, httpClient)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, api)
|
||||||
|
|
||||||
|
// Test authentication
|
||||||
|
t.Run("Authentication", func(t *testing.T) {
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, api.GetAuth(), "Authentication token should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test API version check
|
||||||
|
t.Run("API Version Check", func(t *testing.T) {
|
||||||
|
// Try to get API version
|
||||||
|
resp, err := api.RequestUnauthenticated(context.Background(), "apiinfo.version", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
version := resp.MustString()
|
||||||
|
assert.NotEmpty(t, version, "API version should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test host group retrieval
|
||||||
|
t.Run("Get Host Groups", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Get host groups
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"output": "extend",
|
||||||
|
}
|
||||||
|
resp, err := api.Request(context.Background(), "hostgroup.get", params, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
// Verify response is an array
|
||||||
|
groups, err := resp.Array()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotNil(t, groups, "Host groups should not be nil")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test error handling
|
||||||
|
t.Run("Error Handling", func(t *testing.T) {
|
||||||
|
// Try to make a request without authentication
|
||||||
|
api.SetAuth("")
|
||||||
|
_, err := api.Request(context.Background(), "hostgroup.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.True(t, backend.IsDownstreamError(err))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test auth parameter is in request body for v7.0
|
||||||
|
t.Run("Auth Parameter In Request Body", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Create a test client that captures the request body
|
||||||
|
var requestBody map[string]interface{}
|
||||||
|
testClient := NewTestClient(func(req *http.Request) *http.Response {
|
||||||
|
// Read and parse the request body
|
||||||
|
body, err := io.ReadAll(req.Body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(body, &requestBody)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth header is not present
|
||||||
|
assert.Empty(t, req.Header.Get("Authorization"), "Authorization header should not be present for v7.0")
|
||||||
|
|
||||||
|
// Return a mock response
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: 200,
|
||||||
|
Body: io.NopCloser(bytes.NewBufferString(`{"result": "test"}`)),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create a new API instance with the test client
|
||||||
|
apiWithTestClient, err := New(dsSettings, testClient)
|
||||||
|
require.NoError(t, err)
|
||||||
|
apiWithTestClient.SetAuth(api.GetAuth())
|
||||||
|
|
||||||
|
// Make a request
|
||||||
|
_, err = apiWithTestClient.Request(context.Background(), "test.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth parameter is in the request body
|
||||||
|
auth, hasAuth := requestBody["auth"]
|
||||||
|
assert.True(t, hasAuth, "Auth parameter should be present in request body for v7.0")
|
||||||
|
assert.Equal(t, api.GetAuth(), auth, "Auth parameter should match the set auth token")
|
||||||
|
})
|
||||||
|
}
|
||||||
161
pkg/zabbixapi/zabbix_api_72_integration_test.go
Normal file
161
pkg/zabbixapi/zabbix_api_72_integration_test.go
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
package zabbixapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These tests require a running Zabbix server and proper environment variables
|
||||||
|
// ZABBIX_URL - URL of the Zabbix server (e.g., http://localhost/zabbix/api_jsonrpc.php)
|
||||||
|
// ZABBIX_USER - Username for authentication
|
||||||
|
// ZABBIX_PASSWORD - Password for authentication
|
||||||
|
// To run locally, start devenv/zabbix72 and run INTEGRATION_TEST72=true ZABBIX_URL="http://localhost:8188/api_jsonrpc.php" ZABBIX_USER="Admin" ZABBIX_PASSWORD="zabbix" go test -v ./pkg/zabbixapi/...
|
||||||
|
|
||||||
|
func TestIntegrationZabbixAPI72(t *testing.T) {
|
||||||
|
// Skip if not running integration tests
|
||||||
|
if os.Getenv("INTEGRATION_TEST72") != "true" {
|
||||||
|
t.Skip("Skipping integration test")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get test configuration from environment
|
||||||
|
zabbixURL := os.Getenv("ZABBIX_URL")
|
||||||
|
zabbixUser := os.Getenv("ZABBIX_USER")
|
||||||
|
zabbixPassword := os.Getenv("ZABBIX_PASSWORD")
|
||||||
|
zabbixVersion := 72
|
||||||
|
|
||||||
|
// Validate required environment variables
|
||||||
|
require.NotEmpty(t, zabbixURL, "ZABBIX_URL environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixUser, "ZABBIX_USER environment variable is required")
|
||||||
|
require.NotEmpty(t, zabbixPassword, "ZABBIX_PASSWORD environment variable is required")
|
||||||
|
|
||||||
|
// Create new Zabbix API instance
|
||||||
|
dsSettings := backend.DataSourceInstanceSettings{
|
||||||
|
URL: zabbixURL,
|
||||||
|
}
|
||||||
|
api, err := New(dsSettings, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, api)
|
||||||
|
|
||||||
|
// Test authentication
|
||||||
|
t.Run("Authentication", func(t *testing.T) {
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, api.GetAuth(), "Authentication token should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test API version check
|
||||||
|
t.Run("API Version Check", func(t *testing.T) {
|
||||||
|
// Try to get API version
|
||||||
|
resp, err := api.RequestUnauthenticated(context.Background(), "apiinfo.version", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
version := resp.MustString()
|
||||||
|
assert.NotEmpty(t, version, "API version should not be empty")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test host group retrieval
|
||||||
|
t.Run("Get Host Groups", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Get host groups
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"output": "extend",
|
||||||
|
}
|
||||||
|
resp, err := api.Request(context.Background(), "hostgroup.get", params, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, resp)
|
||||||
|
|
||||||
|
// Verify response is an array
|
||||||
|
groups, err := resp.Array()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.NotNil(t, groups, "Host groups should not be nil")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test error handling
|
||||||
|
t.Run("Error Handling", func(t *testing.T) {
|
||||||
|
// Try to make a request without authentication
|
||||||
|
api.SetAuth("")
|
||||||
|
_, err := api.Request(context.Background(), "hostgroup.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.True(t, backend.IsDownstreamError(err))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test auth parameter is not in request body for v7.2+
|
||||||
|
t.Run("Auth Parameter Not In Request Body", func(t *testing.T) {
|
||||||
|
// First authenticate
|
||||||
|
err := api.Authenticate(context.Background(), zabbixUser, zabbixPassword, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Create a test client that captures the request body
|
||||||
|
var requestBody map[string]interface{}
|
||||||
|
testClient := NewTestClient(func(req *http.Request) *http.Response {
|
||||||
|
// Read and parse the request body
|
||||||
|
body, err := io.ReadAll(req.Body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
err = json.Unmarshal(body, &requestBody)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth header is present
|
||||||
|
assert.Equal(t, "Bearer "+api.GetAuth(), req.Header.Get("Authorization"), "Authorization header should be present with Bearer token")
|
||||||
|
|
||||||
|
// Return a mock response
|
||||||
|
return &http.Response{
|
||||||
|
StatusCode: 200,
|
||||||
|
Body: io.NopCloser(bytes.NewBufferString(`{"result": "test"}`)),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create a new API instance with the test client
|
||||||
|
apiWithTestClient, err := New(dsSettings, testClient)
|
||||||
|
require.NoError(t, err)
|
||||||
|
apiWithTestClient.SetAuth(api.GetAuth())
|
||||||
|
|
||||||
|
// Make a request
|
||||||
|
_, err = apiWithTestClient.Request(context.Background(), "test.get", map[string]interface{}{}, zabbixVersion)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify auth parameter is not in the request body
|
||||||
|
_, hasAuth := requestBody["auth"]
|
||||||
|
assert.False(t, hasAuth, "Auth parameter should not be present in request body for v7.2+")
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test basic auth is not supported in v7.2+
|
||||||
|
t.Run("Basic Auth Not Supported", func(t *testing.T) {
|
||||||
|
// Create settings with basic auth enabled
|
||||||
|
dsSettingsWithBasicAuth := backend.DataSourceInstanceSettings{
|
||||||
|
URL: zabbixURL,
|
||||||
|
BasicAuthEnabled: true,
|
||||||
|
BasicAuthUser: zabbixUser,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new API instance with basic auth enabled
|
||||||
|
apiWithBasicAuth, err := New(dsSettingsWithBasicAuth, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, apiWithBasicAuth)
|
||||||
|
|
||||||
|
// Get host groups
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"output": "extend",
|
||||||
|
}
|
||||||
|
|
||||||
|
apiWithBasicAuth.SetAuth("something")
|
||||||
|
|
||||||
|
// Try to authenticate
|
||||||
|
_, err = apiWithBasicAuth.Request(context.Background(), "hostgroup.get", params, zabbixVersion)
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "Basic Auth is not supported for Zabbix v7.2 and later")
|
||||||
|
assert.True(t, backend.IsDownstreamError(err))
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user