Skip to content

Commit

Permalink
added workflow with integration tests for Zabbix sender
Browse files Browse the repository at this point in the history
  • Loading branch information
aiantsen committed Oct 25, 2023
1 parent b2fdb92 commit e58d02e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/scripts/integration_sender_test.py
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()
49 changes: 49 additions & 0 deletions .github/workflows/integration_sender.yaml
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

0 comments on commit e58d02e

Please sign in to comment.