Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.0.1 #19

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/configs/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ server {
root /var/www/html/;
index index.php;

server_name 127.0.0.1;
server_name localhost 127.0.0.1;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;

location / {
location /http_auth/ {
auth_basic "Zabbix HTTP Auth";
auth_basic_user_file /etc/nginx/.htpasswd;

Expand All @@ -18,4 +18,12 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering on;
}

location /ssl_context/ {
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_buffering on;
}
}
19 changes: 19 additions & 0 deletions .github/configs/nginx.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[req]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
countryName = LV
localityName = Riga
organizationName = Zabbix SIA
organizationalUnitName = Integration team
emailAddress = [email protected]
[req_ext]
subjectAltName = @alt_names
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
IP.1 = 127.0.0.1
23 changes: 0 additions & 23 deletions .github/configs/nginx.crt

This file was deleted.

28 changes: 0 additions & 28 deletions .github/configs/nginx.key

This file was deleted.

136 changes: 134 additions & 2 deletions .github/scripts/additional_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# See the LICENSE file in the project root for more information.

import sys
import ssl
import base64
import unittest
from aiohttp import ClientSession, TCPConnector

sys.path.append('.')
from zabbix_utils.api import ZabbixAPI
Expand All @@ -24,9 +26,9 @@ class IntegrationAPITest(unittest.TestCase):
"""Test working with a real Zabbix API instance synchronously"""

def setUp(self):
self.url = ZABBIX_URL
self.user = ZABBIX_USER
self.password = ZABBIX_PASSWORD
self.url = ZABBIX_URL + '/http_auth/'
self.api = ZabbixAPI(
url=self.url,
user=self.user,
Expand Down Expand Up @@ -89,13 +91,76 @@ def test_user_get(self):
self.assertEqual(type(users), list, "Request user.get was going wrong")


class CustomCertAPITest(unittest.TestCase):
"""Test working with a real Zabbix API instance synchronously"""

def setUp(self):
self.user = ZABBIX_USER
self.password = ZABBIX_PASSWORD
self.url = ZABBIX_URL + '/ssl_context/'

context = ssl.create_default_context()
context.load_verify_locations('/etc/nginx/ssl/nginx.crt')

self.api = ZabbixAPI(
url=self.url,
user=self.user,
password=self.password,
skip_version_check=True,
ssl_context=context
)

def tearDown(self):
if self.api:
self.api.logout()

def test_login(self):
"""Tests login function works properly"""

self.assertEqual(
type(self.api), ZabbixAPI, "Login was going wrong")
self.assertEqual(
type(self.api.api_version()), APIVersion, "Version getting was going wrong")

def test_version_get(self):
"""Tests getting version info works properly"""

version = None
if self.api:
version = self.api.apiinfo.version()
self.assertEqual(
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")

def test_check_auth(self):
"""Tests checking authentication state works properly"""

resp = None
if self.api:
if self.api._ZabbixAPI__session_id == self.api._ZabbixAPI__token:
resp = self.api.user.checkAuthentication(token=self.api._ZabbixAPI__session_id)
else:
resp = self.api.user.checkAuthentication(sessionid=self.api._ZabbixAPI__session_id)
self.assertEqual(
type(resp), dict, "Request user.checkAuthentication was going wrong")

def test_user_get(self):
"""Tests getting users info works properly"""

users = None
if self.api:
users = self.api.user.get(
output=['userid', 'name']
)
self.assertEqual(type(users), list, "Request user.get was going wrong")


class IntegrationAsyncAPITest(unittest.IsolatedAsyncioTestCase):
"""Test working with a real Zabbix API instance asynchronously"""

async def asyncSetUp(self):
self.url = ZABBIX_URL
self.user = ZABBIX_USER
self.password = ZABBIX_PASSWORD
self.url = ZABBIX_URL + '/http_auth/'
self.api = AsyncZabbixAPI(
url=self.url,
skip_version_check=True,
Expand Down Expand Up @@ -163,5 +228,72 @@ async def test_user_get(self):
self.assertEqual(type(users), list, "Request user.get was going wrong")


class CustomCertAsyncAPITest(unittest.IsolatedAsyncioTestCase):
"""Test working with a real Zabbix API instance asynchronously"""

async def asyncSetUp(self):
self.user = ZABBIX_USER
self.password = ZABBIX_PASSWORD
self.url = ZABBIX_URL + '/ssl_context/'

context = ssl.create_default_context()
context.load_verify_locations('/etc/nginx/ssl/nginx.crt')
session = ClientSession(
connector=TCPConnector(ssl=context)
)

self.api = AsyncZabbixAPI(
url=self.url,
skip_version_check=True,
client_session=session
)
await self.api.login(
user=self.user,
password=self.password
)

async def asyncTearDown(self):
if self.api:
await self.api.logout()

async def test_login(self):
"""Tests login function works properly"""

self.assertEqual(
type(self.api), AsyncZabbixAPI, "Login was going wrong")
self.assertEqual(
type(self.api.api_version()), APIVersion, "Version getting was going wrong")

async def test_version_get(self):
"""Tests getting version info works properly"""

version = None
if self.api:
version = await self.api.apiinfo.version()
self.assertEqual(
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")

async def test_check_auth(self):
"""Tests checking authentication state works properly"""

resp = None
if self.api:
if self.api._AsyncZabbixAPI__session_id == self.api._AsyncZabbixAPI__token:
resp = await self.api.user.checkAuthentication(token=(self.api._AsyncZabbixAPI__session_id or ''))
else:
resp = await self.api.user.checkAuthentication(sessionid=(self.api._AsyncZabbixAPI__session_id or ''))
self.assertEqual(
type(resp), dict, "Request user.checkAuthentication was going wrong")

async def test_user_get(self):
"""Tests getting users info works properly"""

users = None
if self.api:
users = await self.api.user.get(
output=['userid', 'name']
)
self.assertEqual(type(users), list, "Request user.get was going wrong")

if __name__ == '__main__':
unittest.main()
12 changes: 9 additions & 3 deletions .github/scripts/library_import_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash

class=$1
error=$2
mode=$1
class=$2
error=$3

result=$(python3 -c "import sys; sys.path.append('.'); from zabbix_utils import $class; $class()" 2>&1)
cmd="import sys; sys.path.append('.'); from zabbix_utils import $class; $class()"
if [ $mode == "async" ]; then
cmd="import sys; import asyncio; sys.path.append('.'); from zabbix_utils import $class; exec('async def main():\n $class()'); asyncio.run(main())"
fi

result=$(python3 -c "$cmd" 2>&1)
echo "$result" | grep "$error" >/dev/null || echo "$result" | (python3 "./.github/scripts/telegram_msg.py" && echo "Error")
9 changes: 4 additions & 5 deletions .github/workflows/additional_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ jobs:
TBOT_CHAT: ${{ vars.TBOT_CHAT }}
SUBJECT: Importing test without requirements FAIL
run: |
bash ./.github/scripts/library_import_tests.sh "ZabbixAPI" "Unable to connect to" > /tmp/importing.log
bash ./.github/scripts/library_import_tests.sh "sync" "ZabbixAPI" "Unable to connect to" > /tmp/importing.log
- name: Check import of async without requirements
continue-on-error: true
env:
TBOT_TOKEN: ${{ secrets.TBOT_TOKEN }}
TBOT_CHAT: ${{ vars.TBOT_CHAT }}
SUBJECT: Importing test without requirements FAIL
run: |
bash ./.github/scripts/library_import_tests.sh "AsyncZabbixAPI" "ModuleNotFoundError:" > /tmp/importing.log
bash ./.github/scripts/library_import_tests.sh "async" "AsyncZabbixAPI" "ModuleNotFoundError:" > /tmp/importing.log
- name: Install requirements
run: |
pip install -r ./requirements.txt
Expand All @@ -52,7 +52,7 @@ jobs:
TBOT_CHAT: ${{ vars.TBOT_CHAT }}
SUBJECT: Importing tests with requirements FAIL
run: |
bash ./.github/scripts/library_import_tests.sh "AsyncZabbixAPI" "aiohttp.client.ClientSession" > /tmp/importing.log
bash ./.github/scripts/library_import_tests.sh "async" "AsyncZabbixAPI" "aiohttp.client.ClientSession" > /tmp/importing.log
- name: Raise an exception
run: |
test $(cat /tmp/importing.log | wc -l) -eq 0 || exit 1
Expand All @@ -77,9 +77,8 @@ jobs:
echo -e "CacheUpdateFrequency=1\n" >> ./conf/zabbix_server.conf
sudo mkdir -p /etc/nginx/ssl/
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/.htpasswd /etc/nginx/.htpasswd
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/nginx.crt /etc/nginx/ssl/nginx.crt
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/nginx.key /etc/nginx/ssl/nginx.key
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/default.conf /etc/nginx/sites-enabled/default
sudo openssl req -x509 -nodes -days 1 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -config $WORKDIR/${{ env.CONFIG_PATH }}/nginx.cnf
sudo chown -R www-data:www-data /etc/nginx/
cd ui
sudo rm /var/www/html/index.html
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [2.0.1](https://github.com/zabbix/python-zabbix-utils/compare/v2.0.0...v2.0.1) (2024-09-18)

### Features:

- added ssl_context argument to ZabbixAPI to allow more flexible configuration of SSL connections
- added support of SSL connection configuration to AsyncZabbixAPI

## [2.0.0](https://github.com/zabbix/python-zabbix-utils/compare/v1.1.1...v2.0.0) (2024-04-12)

### Features:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ $ git clone https://github.com/zabbix/python-zabbix-utils
Install **zabbix_utils** library using setup.py:

```bash
$ cd python-zabbix-utils-master/
$ cd python-zabbix-utils/
$ python3 setup.py install
```

Expand Down
Loading
Loading