Skip to content

Commit

Permalink
Merge pull request #11 from ARGOeu-Metrics/devel
Browse files Browse the repository at this point in the history
Version 0.3.0
  • Loading branch information
themiszamani authored Mar 7, 2024
2 parents e0f1b91 + 0331dd9 commit a0168af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Example execution of `check_status.py`
```
# /usr/libexec/argo/probes/argo-servicestatus/check_status.py -t 30 -u https://wiki.eoscfuture.eu/status
OK - Service available
OK - Service available|time=0.076267s;size=19B
```
4 changes: 3 additions & 1 deletion argo-probe-argo-servicestatus.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%global __python %{python3}

Name: argo-probe-argo-servicestatus
Version: 0.2.0
Version: 0.3.0
Release: 1%{?dist}
Summary: Monitoring scripts that check service status
License: GPLv3+
Expand Down Expand Up @@ -34,6 +34,8 @@ install -m 755 check_status.py %{buildroot}/%{_libexecdir}/argo/probes/argo-serv
%attr(0755,root,root) /%{_libexecdir}/argo/probes/argo-servicestatus/check_status.py

%changelog
* Thu Mar 7 2024 Katarina Zailac <kzailac@srce.hr> - 0.3.0-1
- ARGO-4476 Add performance data to argo-probe-argo-servicestatus
* Thu Jul 6 2023 Katarina Zailac <kzailac@srce.hr> - 0.2.0-1
- ARGO-4329 Fix an error in probe
- ARGO-4320 Generalize argo-probe-argo-servicestatus probe
Expand Down
24 changes: 20 additions & 4 deletions check_status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python3
import argparse
import json
import sys

import requests
Expand Down Expand Up @@ -36,18 +37,29 @@ def get_statuscode(self):

def check_status(args):
probe = ProbeResponse()
perf_data = ""
try:
response = requests.get(args.url, timeout=args.timeout)

response.raise_for_status()
response_time = response.elapsed.total_seconds()
response_size = len(response.content)

perf_data = f"|time={response_time}s;size={response_size}B"

status = response.json()[args.key]

response.raise_for_status()

if status.lower() == args.value:
probe.write_ok("Service available")
probe.write_ok(f"Service available{perf_data}")

else:
probe.write_warning(f"Service not available: {status}")
probe.write_critical(f"Service not available: {status}{perf_data}")

except json.decoder.JSONDecodeError as err:
probe.write_critical(
f"Error decoding JSON: {str(err)}{perf_data}"
)

except (
requests.exceptions.HTTPError,
Expand All @@ -56,7 +68,11 @@ def check_status(args):
ValueError,
KeyError
) as err:
probe.write_critical(str(err))
msg = str(err)
if perf_data:
msg = f"{msg}{perf_data}"

probe.write_critical(msg)

except Exception as err:
probe.write_unknown(str(err))
Expand Down

0 comments on commit a0168af

Please sign in to comment.