Skip to content

Commit e4a2ec8

Browse files
authored
Release v2.0.1
2 parents 442cc87 + ba152b8 commit e4a2ec8

File tree

15 files changed

+304
-68
lines changed

15 files changed

+304
-68
lines changed

.github/configs/default.conf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ server {
44
root /var/www/html/;
55
index index.php;
66

7-
server_name 127.0.0.1;
7+
server_name localhost 127.0.0.1;
88
ssl_certificate /etc/nginx/ssl/nginx.crt;
99
ssl_certificate_key /etc/nginx/ssl/nginx.key;
1010

11-
location / {
11+
location /http_auth/ {
1212
auth_basic "Zabbix HTTP Auth";
1313
auth_basic_user_file /etc/nginx/.htpasswd;
1414

@@ -18,4 +18,12 @@ server {
1818
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1919
proxy_buffering on;
2020
}
21+
22+
location /ssl_context/ {
23+
proxy_pass http://localhost:8080/;
24+
proxy_set_header Host $http_host;
25+
proxy_set_header X-Real-IP $remote_addr;
26+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
27+
proxy_buffering on;
28+
}
2129
}

.github/configs/nginx.cnf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[req]
2+
default_bits = 2048
3+
distinguished_name = req_distinguished_name
4+
req_extensions = req_ext
5+
x509_extensions = v3_req
6+
prompt = no
7+
[req_distinguished_name]
8+
countryName = LV
9+
localityName = Riga
10+
organizationName = Zabbix SIA
11+
organizationalUnitName = Integration team
12+
emailAddress = [email protected]
13+
[req_ext]
14+
subjectAltName = @alt_names
15+
[v3_req]
16+
subjectAltName = @alt_names
17+
[alt_names]
18+
DNS.1 = localhost
19+
IP.1 = 127.0.0.1

.github/configs/nginx.crt

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/configs/nginx.key

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/scripts/additional_api_tests.py

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
# See the LICENSE file in the project root for more information.
66

77
import sys
8+
import ssl
89
import base64
910
import unittest
11+
from aiohttp import ClientSession, TCPConnector
1012

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

2628
def setUp(self):
27-
self.url = ZABBIX_URL
2829
self.user = ZABBIX_USER
2930
self.password = ZABBIX_PASSWORD
31+
self.url = ZABBIX_URL + '/http_auth/'
3032
self.api = ZabbixAPI(
3133
url=self.url,
3234
user=self.user,
@@ -89,13 +91,76 @@ def test_user_get(self):
8991
self.assertEqual(type(users), list, "Request user.get was going wrong")
9092

9193

94+
class CustomCertAPITest(unittest.TestCase):
95+
"""Test working with a real Zabbix API instance synchronously"""
96+
97+
def setUp(self):
98+
self.user = ZABBIX_USER
99+
self.password = ZABBIX_PASSWORD
100+
self.url = ZABBIX_URL + '/ssl_context/'
101+
102+
context = ssl.create_default_context()
103+
context.load_verify_locations('/etc/nginx/ssl/nginx.crt')
104+
105+
self.api = ZabbixAPI(
106+
url=self.url,
107+
user=self.user,
108+
password=self.password,
109+
skip_version_check=True,
110+
ssl_context=context
111+
)
112+
113+
def tearDown(self):
114+
if self.api:
115+
self.api.logout()
116+
117+
def test_login(self):
118+
"""Tests login function works properly"""
119+
120+
self.assertEqual(
121+
type(self.api), ZabbixAPI, "Login was going wrong")
122+
self.assertEqual(
123+
type(self.api.api_version()), APIVersion, "Version getting was going wrong")
124+
125+
def test_version_get(self):
126+
"""Tests getting version info works properly"""
127+
128+
version = None
129+
if self.api:
130+
version = self.api.apiinfo.version()
131+
self.assertEqual(
132+
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")
133+
134+
def test_check_auth(self):
135+
"""Tests checking authentication state works properly"""
136+
137+
resp = None
138+
if self.api:
139+
if self.api._ZabbixAPI__session_id == self.api._ZabbixAPI__token:
140+
resp = self.api.user.checkAuthentication(token=self.api._ZabbixAPI__session_id)
141+
else:
142+
resp = self.api.user.checkAuthentication(sessionid=self.api._ZabbixAPI__session_id)
143+
self.assertEqual(
144+
type(resp), dict, "Request user.checkAuthentication was going wrong")
145+
146+
def test_user_get(self):
147+
"""Tests getting users info works properly"""
148+
149+
users = None
150+
if self.api:
151+
users = self.api.user.get(
152+
output=['userid', 'name']
153+
)
154+
self.assertEqual(type(users), list, "Request user.get was going wrong")
155+
156+
92157
class IntegrationAsyncAPITest(unittest.IsolatedAsyncioTestCase):
93158
"""Test working with a real Zabbix API instance asynchronously"""
94159

95160
async def asyncSetUp(self):
96-
self.url = ZABBIX_URL
97161
self.user = ZABBIX_USER
98162
self.password = ZABBIX_PASSWORD
163+
self.url = ZABBIX_URL + '/http_auth/'
99164
self.api = AsyncZabbixAPI(
100165
url=self.url,
101166
skip_version_check=True,
@@ -163,5 +228,72 @@ async def test_user_get(self):
163228
self.assertEqual(type(users), list, "Request user.get was going wrong")
164229

165230

231+
class CustomCertAsyncAPITest(unittest.IsolatedAsyncioTestCase):
232+
"""Test working with a real Zabbix API instance asynchronously"""
233+
234+
async def asyncSetUp(self):
235+
self.user = ZABBIX_USER
236+
self.password = ZABBIX_PASSWORD
237+
self.url = ZABBIX_URL + '/ssl_context/'
238+
239+
context = ssl.create_default_context()
240+
context.load_verify_locations('/etc/nginx/ssl/nginx.crt')
241+
session = ClientSession(
242+
connector=TCPConnector(ssl=context)
243+
)
244+
245+
self.api = AsyncZabbixAPI(
246+
url=self.url,
247+
skip_version_check=True,
248+
client_session=session
249+
)
250+
await self.api.login(
251+
user=self.user,
252+
password=self.password
253+
)
254+
255+
async def asyncTearDown(self):
256+
if self.api:
257+
await self.api.logout()
258+
259+
async def test_login(self):
260+
"""Tests login function works properly"""
261+
262+
self.assertEqual(
263+
type(self.api), AsyncZabbixAPI, "Login was going wrong")
264+
self.assertEqual(
265+
type(self.api.api_version()), APIVersion, "Version getting was going wrong")
266+
267+
async def test_version_get(self):
268+
"""Tests getting version info works properly"""
269+
270+
version = None
271+
if self.api:
272+
version = await self.api.apiinfo.version()
273+
self.assertEqual(
274+
version, str(self.api.api_version()), "Request apiinfo.version was going wrong")
275+
276+
async def test_check_auth(self):
277+
"""Tests checking authentication state works properly"""
278+
279+
resp = None
280+
if self.api:
281+
if self.api._AsyncZabbixAPI__session_id == self.api._AsyncZabbixAPI__token:
282+
resp = await self.api.user.checkAuthentication(token=(self.api._AsyncZabbixAPI__session_id or ''))
283+
else:
284+
resp = await self.api.user.checkAuthentication(sessionid=(self.api._AsyncZabbixAPI__session_id or ''))
285+
self.assertEqual(
286+
type(resp), dict, "Request user.checkAuthentication was going wrong")
287+
288+
async def test_user_get(self):
289+
"""Tests getting users info works properly"""
290+
291+
users = None
292+
if self.api:
293+
users = await self.api.user.get(
294+
output=['userid', 'name']
295+
)
296+
self.assertEqual(type(users), list, "Request user.get was going wrong")
297+
166298
if __name__ == '__main__':
167299
unittest.main()
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/bin/bash
22

3-
class=$1
4-
error=$2
3+
mode=$1
4+
class=$2
5+
error=$3
56

6-
result=$(python3 -c "import sys; sys.path.append('.'); from zabbix_utils import $class; $class()" 2>&1)
7+
cmd="import sys; sys.path.append('.'); from zabbix_utils import $class; $class()"
8+
if [ $mode == "async" ]; then
9+
cmd="import sys; import asyncio; sys.path.append('.'); from zabbix_utils import $class; exec('async def main():\n $class()'); asyncio.run(main())"
10+
fi
11+
12+
result=$(python3 -c "$cmd" 2>&1)
713
echo "$result" | grep "$error" >/dev/null || echo "$result" | (python3 "./.github/scripts/telegram_msg.py" && echo "Error")

.github/workflows/additional_tests.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ jobs:
3333
TBOT_CHAT: ${{ vars.TBOT_CHAT }}
3434
SUBJECT: Importing test without requirements FAIL
3535
run: |
36-
bash ./.github/scripts/library_import_tests.sh "ZabbixAPI" "Unable to connect to" > /tmp/importing.log
36+
bash ./.github/scripts/library_import_tests.sh "sync" "ZabbixAPI" "Unable to connect to" > /tmp/importing.log
3737
- name: Check import of async without requirements
3838
continue-on-error: true
3939
env:
4040
TBOT_TOKEN: ${{ secrets.TBOT_TOKEN }}
4141
TBOT_CHAT: ${{ vars.TBOT_CHAT }}
4242
SUBJECT: Importing test without requirements FAIL
4343
run: |
44-
bash ./.github/scripts/library_import_tests.sh "AsyncZabbixAPI" "ModuleNotFoundError:" > /tmp/importing.log
44+
bash ./.github/scripts/library_import_tests.sh "async" "AsyncZabbixAPI" "ModuleNotFoundError:" > /tmp/importing.log
4545
- name: Install requirements
4646
run: |
4747
pip install -r ./requirements.txt
@@ -52,7 +52,7 @@ jobs:
5252
TBOT_CHAT: ${{ vars.TBOT_CHAT }}
5353
SUBJECT: Importing tests with requirements FAIL
5454
run: |
55-
bash ./.github/scripts/library_import_tests.sh "AsyncZabbixAPI" "aiohttp.client.ClientSession" > /tmp/importing.log
55+
bash ./.github/scripts/library_import_tests.sh "async" "AsyncZabbixAPI" "aiohttp.client.ClientSession" > /tmp/importing.log
5656
- name: Raise an exception
5757
run: |
5858
test $(cat /tmp/importing.log | wc -l) -eq 0 || exit 1
@@ -77,9 +77,8 @@ jobs:
7777
echo -e "CacheUpdateFrequency=1\n" >> ./conf/zabbix_server.conf
7878
sudo mkdir -p /etc/nginx/ssl/
7979
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/.htpasswd /etc/nginx/.htpasswd
80-
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/nginx.crt /etc/nginx/ssl/nginx.crt
81-
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/nginx.key /etc/nginx/ssl/nginx.key
8280
sudo cp $WORKDIR/${{ env.CONFIG_PATH }}/default.conf /etc/nginx/sites-enabled/default
81+
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
8382
sudo chown -R www-data:www-data /etc/nginx/
8483
cd ui
8584
sudo rm /var/www/html/index.html

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [2.0.1](https://github.com/zabbix/python-zabbix-utils/compare/v2.0.0...v2.0.1) (2024-09-18)
2+
3+
### Features:
4+
5+
- added ssl_context argument to ZabbixAPI to allow more flexible configuration of SSL connections
6+
- added support of SSL connection configuration to AsyncZabbixAPI
7+
18
## [2.0.0](https://github.com/zabbix/python-zabbix-utils/compare/v1.1.1...v2.0.0) (2024-04-12)
29

310
### Features:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ $ git clone https://github.com/zabbix/python-zabbix-utils
9494
Install **zabbix_utils** library using setup.py:
9595

9696
```bash
97-
$ cd python-zabbix-utils-master/
97+
$ cd python-zabbix-utils/
9898
$ python3 setup.py install
9999
```
100100

0 commit comments

Comments
 (0)