-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added workflow with integration tests for Zabbix sender
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
import unittest | ||
|
||
sys.path.append('.') | ||
from zabbix_utils.sender import ZabbixItem, ZabbixSender, ZabbixResponse | ||
|
||
|
||
class IntegrationSenderTest(unittest.TestCase): | ||
"""Test working with a real Zabbix server/proxy instance""" | ||
|
||
def setUp(self): | ||
self.ip = '127.0.0.1' | ||
self.port = 10051 | ||
self.chunk_size = 10 | ||
self.sender = ZabbixSender( | ||
server=self.ip, | ||
port=self.port, | ||
chunk_size=self.chunk_size | ||
) | ||
|
||
def test_send(self): | ||
"""Tests sending item values works properly""" | ||
|
||
items = [ | ||
ZabbixItem('host1', 'item.key1', 10), | ||
ZabbixItem('host1', 'item.key2', 'test message'), | ||
ZabbixItem('host2', 'item.key1', -1, 1695713666), | ||
ZabbixItem('host3', 'item.key1', '{"msg":"test message"}'), | ||
ZabbixItem('host2', 'item.key1', 0, 1695713666, 100) | ||
] | ||
chunks_resp = self.sender.send(items) | ||
|
||
self.assertEqual(type(chunks_resp), list, "Sending item values was going wrong") | ||
for resp in chunks_resp: | ||
self.assertEqual(type(resp), ZabbixResponse, "Sending item values was going wrong") | ||
for key in ('processed', 'failed', 'total', 'time', 'chunk'): | ||
try: | ||
self.assertIsNotNone(getattr(resp, key), f"There aren't expected '{key}' value") | ||
except AttributeError: | ||
self.fail(f"raised unexpected Exception for attribute: {key}") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: sender | ||
run-name: Run Zabbix sender integration test | ||
|
||
on: | ||
#push: | ||
# branches: [main] | ||
#pull_request: | ||
# branches: [main] | ||
workflow_dispatch: | ||
|
||
env: | ||
ZABBIX_VERSION: '6.0' | ||
ZABBIX_BRANCH: master | ||
CONFIG_PATH: .github/configs/ | ||
TEST_FILE: integration_sender_test.py | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install packages | ||
run: | | ||
sudo wget https://repo.zabbix.com/zabbix/${{ env.ZABBIX_VERSION }}/ubuntu/pool/main/z/zabbix-release/zabbix-release_${{ env.ZABBIX_VERSION }}-4+ubuntu22.04_all.deb | ||
sudo dpkg -i zabbix-release_${{ env.ZABBIX_VERSION }}-4+ubuntu22.04_all.deb | ||
sudo apt update && sudo apt install -y zabbix-proxy-sqlite3 | ||
- name: Prepare environment | ||
run: | | ||
sudo mkdir -p /var/log/zabbix/ | ||
sudo chown -R zabbix. /var/log/zabbix/ | ||
sudo sed -i 's#DBName=zabbix_proxy#DBName=/tmp/proxy.db#' /etc/zabbix/zabbix_proxy.conf | ||
- name: Start Zabbix proxy | ||
run: | | ||
sudo zabbix_proxy -c /etc/zabbix/zabbix_proxy.conf | ||
- name: Install python3 | ||
run: | | ||
sudo apt-get install -y python3 python3-pip python-is-python3 | ||
pip install typing-extensions>=4.0.0 | ||
- name: Integration test | ||
continue-on-error: true | ||
run: | | ||
python ./.github/scripts/$TEST_FILE 2>/tmp/integration.log >/dev/null | ||
- name: Send report | ||
env: | ||
TBOT_TOKEN: ${{ secrets.TBOT_TOKEN }} | ||
TBOT_CHAT: ${{ vars.TBOT_CHAT }} | ||
SUBJECT: Zabbix sender integration test FAIL | ||
run: tail -n1 /tmp/integration.log | grep "OK" 1>/dev/null || tail /tmp/integration.log | python ./.github/scripts/telegram_msg.py | exit 1 |