Skip to content

Commit 34b8fed

Browse files
committed
Update Python version and dependencies
- Update to python 3.9 - Update dependencies - Add Dockerfile - Update documentation
1 parent d7fe89d commit 34b8fed

File tree

5 files changed

+84
-30
lines changed

5 files changed

+84
-30
lines changed

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM rockylinux:9
2+
# eudat-docker.artifactory.ci.csc.fi/
3+
4+
LABEL maintainer Giacomo Furlan <[email protected]>
5+
LABEL description="Image to test nagios plugin on eudat b2share instances."
6+
7+
RUN dnf update -y && \
8+
dnf install -y python3.9 && \
9+
dnf install -y python3.9-pip
10+
11+
WORKDIR /root
12+
13+
ADD check_b2share.py check_b2share.py
14+
ADD requirements.txt requirements.txt
15+
16+
RUN pip3 install -r requirements.txt

README.md

+39-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
# B2SHARE Monitoring probe for ARGO
22

33
## Setting up environment
4-
This probe has been written for Python 3 and tested with Python 3.5.2
5-
You may need to install (using e.g. `pip`) the following Python modules as
4+
This probe has been written for Python 3 and tested with Python 3.9
5+
You may need to install (using e.g. `pip3`) the following Python modules as
66
they do not come with original distribution:
77
- requests
88
- jsonschema
9-
- validators
10-
- enum (in case lower than Python 3.4)
119

1210
## Overview
13-
The B2SHARE probe for ARGO does the following interaction
11+
The B2SHARE probe for ARGO does the following interaction
1412
with B2SHARE REST API:
1513

1614
- Search for records
1715
- Fetch record's metadata from search results
1816
- Fetch record's metadata schema
1917
- Validate record's metadata agains record's metadata schema
20-
- If a record with file is available, check that a file
18+
- If a record with file is available, check that a file
2119
should be able to be downloaded (HTTP HEAD request)
2220

2321
B2SHARE ARGO probe:
@@ -27,6 +25,30 @@ B2SHARE ARGO probe:
2725
## Pre-requisites:
2826
- None
2927

28+
29+
## Package dependences
30+
31+
Python modules "requests" and "jsonschema" have the following dependencies:
32+
33+
```python
34+
requests==2.31.0
35+
├── certifi [required: >=2017.4.17, installed: 2024.2.2]
36+
├── charset-normalizer [required: >=2,<4, installed: 3.3.2]
37+
├── idna [required: >=2.5,<4, installed: 3.6]
38+
└── urllib3 [required: >=1.21.1,<3, installed: 2.2.1]
39+
40+
41+
jsonschema==4.21.1
42+
├── attrs [required: >=22.2.0, installed: 23.2.0]
43+
├── jsonschema-specifications [required: >=2023.03.6, installed: 2023.12.1]
44+
│ └── referencing [required: >=0.31.0, installed: 0.34.0]
45+
│ ├── attrs [required: >=22.2.0, installed: 23.2.0]
46+
│ └── rpds-py [required: >=0.7.0, installed: 0.18.0]
47+
├── referencing [required: >=0.28.4, installed: 0.34.0]
48+
│ ├── attrs [required: >=22.2.0, installed: 23.2.0]
49+
│ └── rpds-py [required: >=0.7.0, installed: 0.18.0]
50+
└── rpds-py [required: >=0.7.1, installed: 0.18.0]
51+
```
3052
## How it works?
3153

3254
```
@@ -50,7 +72,7 @@ optional arguments:
5072

5173
Example
5274

53-
`$ python check_b2share.py -u https://b2share.eudat.eu:443 -t 15 -vv`
75+
`$ python3 check_b2share.py -u https://b2share.eudat.eu:443 -t 15 -vv`
5476

5577
```
5678
TLS certificate verification: OFF
@@ -70,6 +92,16 @@ Fetching first file of the bucket.
7092
---------------------------
7193
OK, records, metadata schemas and files are accessible.
7294
```
95+
# How to run the code in a conatiner
96+
97+
In the root folder of the project, build the container:
98+
```bash
99+
docker build -t <name_of_the_image>:<tag_of_the_image> .
100+
```
101+
Then run the code in the container
102+
```bash
103+
docker run -it --rm <name_of_the_image>:<tag_of_the_image> python3 check_b2share.py -u https://b2share.eudat.eu:443 -t 15 -vv
104+
```
73105

74106
## Credits
75107
This code is based on [EUDAT-B2ACCESS/b2access-probe](https://github.com/EUDAT-B2ACCESS/b2access-probe)

check_b2share.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424

2525
import jsonschema
2626
import requests
27-
import requests.packages.urllib3
28-
import validators
29-
from requests.exceptions import HTTPError
27+
from requests.models import PreparedRequest
28+
from requests.exceptions import HTTPError, MissingSchema
3029

3130

3231
class Verbosity(IntEnum):
@@ -64,6 +63,20 @@ def get_dict_from_url(url, verify_tls_cert=False, verbosity=False):
6463

6564
return r.json()
6665

66+
def validate_url(url):
67+
"""Validate if a string is an url.
68+
Based on https://stackoverflow.com/a/34266413
69+
(python-validators package was not available as rpm package in Rocky Linux 9)
70+
"""
71+
prepared_request = PreparedRequest()
72+
try:
73+
prepared_request.prepare_url(url, None)
74+
if not prepared_request.url:
75+
return False
76+
except MissingSchema:
77+
return False
78+
return True
79+
6780

6881
if __name__ == '__main__':
6982
parser = argparse.ArgumentParser(description='B2SHARE Nagios probe')
@@ -101,7 +114,7 @@ def get_dict_from_url(url, verify_tls_cert=False, verbosity=False):
101114
verbosity = Verbosity(param.verbose)
102115

103116
# Validate parameters
104-
if not validators.url(param.url):
117+
if not validate_url(param.url):
105118
raise SyntaxError(
106119
'CRITICAL: Invalid URL syntax {0}'.format(
107120
param.url))

nagios-plugins-eudat-b2share.spec

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
Name: nagios-plugins-eudat-b2share
17-
Version: 0.1.1
17+
Version: 0.2.1
1818
Release: 1%{?dist}
1919
Summary: Nagios B2SHARE probe
2020
License: Apache License, Version 2.0
@@ -26,11 +26,9 @@ BuildRoot: %{_tmppath}/%{name}-%{version}
2626

2727
AutoReqProv: no
2828

29-
Requires: python
30-
Requires: python-argparse
31-
Requires: python-requests
32-
Requires: python-jsonschema
33-
Requires: python-validators
29+
Requires: python3
30+
Requires: python3-requests
31+
Requires: python3-jsonschema
3432

3533

3634
%description
@@ -40,7 +38,7 @@ Nagios probe to check functionality of B2SHARE Service
4038
%setup -q
4139

4240
%define _unpackaged_files_terminate_build 0
43-
%define probe_namespace eudat-b2share
41+
%define probe_namespace eudat-b2share
4442

4543
%install
4644

@@ -55,6 +53,10 @@ install -m 755 check_b2share.py %{buildroot}/%{_libexecdir}/argo-monitoring/prob
5553
%attr(0755,root,root) /%{_libexecdir}/argo-monitoring/probes/%{probe_namespace}/check_b2share.py
5654

5755
%changelog
56+
* Fri Apr 05 2024 Giacomo Furlan <[email protected]> - 0.2.1
57+
- Update python to 3.9
58+
- Update requirements and dependencies
59+
- Remove validator dependency
5860
* Mon Sep 02 2019 Harri Hirvonsalo <[email protected]> - 0.1.1-1
5961
- Improved error handling to address false positive alerts.
6062
* Wed Dec 05 2018 Harri Hirvonsalo <[email protected]> - 0.1-1

requirements.txt

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of B2SHARE Nagios monitoring plugin.
33
#
4-
# Copyright (C) 2018 Harri Hirvonsalo
4+
# Copyright (C) 2024 Harri Hirvonsalo
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -15,14 +15,5 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
attrs==19.1.0 # from jsonschema
19-
certifi==2019.6.16 # from requests
20-
chardet==3.0.4 # from requests
21-
decorator==4.4.0 # from validators
22-
idna==2.8 # from requests
23-
jsonschema==3.0.2
24-
pyrsistent==0.15.4 # from jsonschema
25-
requests==2.22.0
26-
six==1.12.0 # from validators, jsonschema
27-
urllib3==1.25.3 # from requests
28-
validators==0.14.0
18+
jsonschema==4.21.1
19+
requests==2.31.0

0 commit comments

Comments
 (0)