Skip to content

Commit

Permalink
B2SAHRE for rocky 9
Browse files Browse the repository at this point in the history
  • Loading branch information
themiszamani committed Jul 31, 2024
2 parents 2cc37cb + 27e28e6 commit a94adc2
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 23 deletions.
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM rockylinux:9
# eudat-docker.artifactory.ci.csc.fi/

LABEL maintainer Giacomo Furlan <[email protected]>
LABEL description="Image to test nagios plugin on eudat b2share instances."

RUN dnf update -y && \
dnf install -y python3.9 && \
dnf install -y python3.9-pip

WORKDIR /root

ADD check_b2share.py check_b2share.py
ADD requirements.txt requirements.txt

RUN pip3 install -r requirements.txt
11 changes: 10 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ pipeline {
stages {
stage ('Build'){
parallel {

stage ('Build Rocky 9 RPM') {
steps {
echo 'Building Rocky 9 RPM...'
withCredentials(bindings: [sshUserPrivateKey(credentialsId: 'jenkins-rpm-repo', usernameVariable: 'REPOUSER', \
keyFileVariable: 'REPOKEY')]) {
sh "/home/jenkins/build-rpm.sh -w ${WORKSPACE} -b ${BRANCH_NAME} -d rocky9 -p ${PROJECT_DIR} -s ${REPOKEY}"
}
archiveArtifacts artifacts: '**/*.rpm', fingerprint: true
}
}
stage ('Build Centos 7') {
agent {
docker {
Expand Down
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# B2SHARE Monitoring probe for ARGO

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

## Overview
The B2SHARE probe for ARGO does the following interaction
The B2SHARE probe for ARGO does the following interaction
with B2SHARE REST API:

- Search for records
- Fetch record's metadata from search results
- Fetch record's metadata schema
- Validate record's metadata agains record's metadata schema
- If a record with file is available, check that a file
- If a record with file is available, check that a file
should be able to be downloaded (HTTP HEAD request)

B2SHARE ARGO probe:
Expand All @@ -27,6 +25,30 @@ B2SHARE ARGO probe:
## Pre-requisites:
- None


## Package dependences

Python modules "requests" and "jsonschema" have the following dependencies:

```python
requests==2.31.0
├── certifi [required: >=2017.4.17, installed: 2024.2.2]
├── charset-normalizer [required: >=2,<4, installed: 3.3.2]
├── idna [required: >=2.5,<4, installed: 3.6]
└── urllib3 [required: >=1.21.1,<3, installed: 2.2.1]


jsonschema==4.21.1
├── attrs [required: >=22.2.0, installed: 23.2.0]
├── jsonschema-specifications [required: >=2023.03.6, installed: 2023.12.1]
│ └── referencing [required: >=0.31.0, installed: 0.34.0]
│ ├── attrs [required: >=22.2.0, installed: 23.2.0]
│ └── rpds-py [required: >=0.7.0, installed: 0.18.0]
├── referencing [required: >=0.28.4, installed: 0.34.0]
│ ├── attrs [required: >=22.2.0, installed: 23.2.0]
│ └── rpds-py [required: >=0.7.0, installed: 0.18.0]
└── rpds-py [required: >=0.7.1, installed: 0.18.0]
```
## How it works?

```
Expand All @@ -50,7 +72,7 @@ optional arguments:

Example

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

```
TLS certificate verification: OFF
Expand All @@ -70,6 +92,16 @@ Fetching first file of the bucket.
---------------------------
OK, records, metadata schemas and files are accessible.
```
# How to run the code in a conatiner

In the root folder of the project, build the container:
```bash
docker build -t <name_of_the_image>:<tag_of_the_image> .
```
Then run the code in the container
```bash
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
```

## Credits
This code is based on [EUDAT-B2ACCESS/b2access-probe](https://github.com/EUDAT-B2ACCESS/b2access-probe)
46 changes: 46 additions & 0 deletions argo-probe-eudat-b2share
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Name: argo-probe-eudat-b2share
Version: 0.7
Release: 1%{?dist}
Summary: Monitoring scripts that check the functionalities of B2SHARE
License: GPLv3+
Packager: Themis Zamani <[email protected]>

Source: %{name}-%{version}.tar.gz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}
AutoReqProv: no
Requires: python3
Requires: python3-requests
Requires: python-jsonschema
Requires: python-enum34

%description
Nagios probe to check functionality of B2SHARE service

%prep
%setup -q

%define _unpackaged_files_terminate_build 0

%install
install -d %{buildroot}/%{_libexecdir}/argo/probes/eudat-b2share
install -m 755 check_b2share.py %{buildroot}/%{_libexecdir}/argo/probes/eudat-b2share/check_b2share.py

%files
%dir /%{_libexecdir}/argo
%dir /%{_libexecdir}/argo/probes/
%dir /%{_libexecdir}/argo/probes/eudat-b2share

%attr(0755,root,root) /%{_libexecdir}/argo/probes/eudat-b2share/check_b2share.py

%changelog
* Fri Apr 05 2024 Giacomo Furlan <[email protected]> - 0.2.1
- Update python to 3.9
- Update requirements and dependencies
- Remove validator dependency
* Mon Mar 14 2022 Themis Zamani <[email protected]> - 0.5
- Update package prerequisites based on argo monitoring.
* Tue Nov 27 2018 Themis Zamani <[email protected]> - 0.1-1
- Initial version of the package.
* Tue Nov 27 2018 Harri Hirvonsalo <[email protected]> - 0.1-1
- Initial version of the package.
14 changes: 11 additions & 3 deletions argo-probe-eudat-b2share.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: argo-probe-eudat-b2share
Version: 0.6
Version: 0.7
Release: 1%{?dist}
Summary: Monitoring scripts that check the functionalities of B2SHARE
License: GPLv3+
Expand All @@ -9,7 +9,10 @@ Source: %{name}-%{version}.tar.gz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}
AutoReqProv: no
Requires: python-requests, python2-jsonschema, python-enum34
Requires: python3
Requires: python3-requests
Requires: python-jsonschema
Requires: python-enum34

%description
Nagios probe to check functionality of B2SHARE service
Expand All @@ -31,10 +34,15 @@ install -m 755 check_b2share.py %{buildroot}/%{_libexecdir}/argo/probes/eudat-b2
%attr(0755,root,root) /%{_libexecdir}/argo/probes/eudat-b2share/check_b2share.py

%changelog
* Fri Apr 05 2024 Giacomo Furlan <[email protected]> - 0.2.1
- Update python to 3.9
- Update requirements and dependencies
- Remove validator dependency
* Mon Mar 14 2022 Themis Zamani <[email protected]> - 0.5
- Update package prerequisites based on argo monitoring.
* Mon Mar 14 2022 Themis Zamani <[email protected]> - 0.5
- Update package prerequisites based on argo monitoring.
* Tue Nov 27 2018 Themis Zamani <[email protected]> - 0.1-1
- Initial version of the package.
* Tue Nov 27 2018 Harri Hirvonsalo <[email protected]> - 0.1-1
- Initial version of the package.

33 changes: 21 additions & 12 deletions check_b2share.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@

import jsonschema
import requests
import requests.packages.urllib3
import validators
from requests.exceptions import HTTPError
from requests.models import PreparedRequest
from requests.exceptions import HTTPError, MissingSchema


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

return r.json()

def validate_url(url):
"""Validate if a string is an url.
Based on https://stackoverflow.com/a/34266413
(python-validators package was not available as rpm package in Rocky Linux 9)
"""
prepared_request = PreparedRequest()
try:
prepared_request.prepare_url(url, None)
if not prepared_request.url:
return False
except MissingSchema:
return False
return True


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

# Validate parameters
if not validators.url(param.url):
if not validate_url(param.url):
raise SyntaxError(
'CRITICAL: Invalid URL syntax {0}'.format(
param.url))
Expand Down Expand Up @@ -149,14 +162,10 @@ def get_dict_from_url(url, verify_tls_cert=False, verbosity=False):

rec_with_files_url = None
for hit in search_results['hits']['hits']:
if 'files' in hit:
# Check if there are files in the record
if len(hit['files']) > 0:
# NTS: Could throw KeyError if there is something
# seriously wrong or B2SHARE REST API responses have
# changed.
rec_with_files_url = hit['links']['self']
break
# Check if there are files in the record
if len(hit.get('files', "")) > 0:
rec_with_files_url = hit['links']['self']
break

if rec_with_files_url:

Expand Down
19 changes: 19 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# This file is part of B2SHARE Nagios monitoring plugin.
#
# Copyright (C) 2024 Harri Hirvonsalo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

jsonschema==4.21.1
requests==2.31.0

0 comments on commit a94adc2

Please sign in to comment.