Skip to content

Commit

Permalink
skip tests if dependant tests are failing, WARNING if LsDir tests ret…
Browse files Browse the repository at this point in the history
…urns SRM_TOO_MANY_RESULTS
  • Loading branch information
andrea-manzi committed Jul 28, 2020
1 parent 3c72e71 commit dc76c7a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
11 changes: 9 additions & 2 deletions nagios-plugins-srm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%define nagios_plugins_dir %{_libdir}/nagios/plugins

Name: nagios-plugins-srm
Version: 0.0.3
Version: 0.0.5
Release: 1%{?dist}
Summary: Nagios probes to be run remotely against SRM mendpoints
License: ASL 2.0
Expand Down Expand Up @@ -53,13 +53,20 @@ rm -rf %{buildroot}
%doc LICENSE README.md

%changelog
* Tue Jul 28 2020 Andrea Manzi <[email protected]> - 0.0.5-0
- skip tests if dependant tests are failing
- WARNING if LsDir tests returns SRM_TOO_MANY_RESULTS

* Tue Jun 30 2020 Andrea Manzi <[email protected]> - 0.0.4-0
- set credentials via API

* Tue Jun 09 2020 Andrea Manzi <[email protected]> - 0.0.3-0
- add gfal2-plugin-gsiftp dependency
- add option to specify proxy path

* Fri May 22 2020 Andrea Manzi <[email protected]> - 0.0.2-0
- update spec
- add shabang
- add shebang

* Thu Apr 23 2020 Andrea Manzi <[email protected]> - 0.0.1-0
- first version
75 changes: 59 additions & 16 deletions plugins/srm_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from urllib.parse import urlparse


PROBE_VERSION = "v0.0.3"
PROBE_VERSION = "v0.0.5"


# ########################################################################### #
Expand Down Expand Up @@ -190,12 +190,19 @@ def metricVOLsDir(args, io):
"""
List content of VO's top level space area(s) in SRM using gfal2.listdir().
"""

# verify previous test succeeded
results = app.metric_results()
if (results[0][1] != nap.OK ):
io.set_status(nap.WARNING, "VOLsDir skipped")
return

srms = []
try:
for srm in _voInfoDictionary.keys():
srms.append(srm)
if not srms:
io.set_status(nap.CRITICAL, 'No SRM endpoints found to test')
io.set_status(nap.WARNING, 'No SRM endpoints found to test')
return
except Exception as e:
io.set_status('UNKNOWN', 'Error reading SRM to test')
Expand All @@ -208,24 +215,35 @@ def metricVOLsDir(args, io):
io.status = nap.OK
except gfal2.GError as e:
er = e.message
io.status = nap.CRITICAL
if er:
io.summary = '[Err:%s];' % str(er)
# SRM_TOO_MANY_RESULTS is handled as an error in gfal2, we don't want to report it as Critical here
if "SRM_TOO_MANY_RESULTS" in er:
io.summary = '[WARN:%s];' % str(er)
io.status = nap.WARNING
else:
io.status = nap.CRITICAL
io.summary = '[Err:%s];' % str(er)
else:
io.status = nap.CRITICAL
io.summary = 'Error'
except Exception as e:
io.set_status(
nap.UNKNOWN, 'problem invoking gfal2 listdir(): %s:%s' %
nap.CRITICAL, 'problem invoking gfal2 listdir(): %s:%s' %
(str(e), sys.exc_info()[0]))


@app.metric(seq=3, metric_name="VOPut", passive=True)
def metricVOPut(args, io):
"""Copy a local file to the SRM into space area(s) defined by VO."""

# verify VOGetSurls test succeeded
results = app.metric_results()
if (results[0][1] != nap.OK ):
io.set_status(nap.WARNING, "VOLsDir skipped")
return

if len(_voInfoDictionary.keys()) == 0:
io.set_status(nap.CRITICAL, 'No SRM endpoints found to test')
io.set_status(nap.WARNING, 'No SRM endpoints found to test')
return

# multiple 'SAPath's are possible
Expand Down Expand Up @@ -272,16 +290,22 @@ def metricVOPut(args, io):
io.summary = stMsg % ' NOT'
except Exception as e:
io.set_status(
nap.UNKNOWN, 'problem invoking gfal2 filecopy(): %s:%s' %
nap.CRITICAL, 'problem invoking gfal2 filecopy(): %s:%s' %
(str(e), sys.exc_info()[0]))


@app.metric(seq=4, metric_name="VOLs", passive=True)
def metricVOLs(args, io):
"""Stat (previously copied) file(s) on the SRM."""

# verify previous test succeeded
results = app.metric_results()
if ( results[2][1] != nap.OK ):
io.set_status(nap.WARNING, "VOLs skipped")
return

if len(_voInfoDictionary.keys()) == 0:
io.set_status(nap.CRITICAL, 'No SRM endpoints found to test')
io.set_status(nap.WARNING, 'No SRM endpoints found to test')
return

srms = []
Expand All @@ -307,16 +331,22 @@ def metricVOLs(args, io):

except Exception as e:
io.set_status(
nap.UNKNOWN, 'problem invoking gfal2 stat(): %s:%s' %
nap.CRITICAL, 'problem invoking gfal2 stat(): %s:%s' %
(str(e), sys.exc_info()[0]))


@app.metric(seq=5, metric_name="VOGetTurl", passive=True)
def metricVOGetTURLs(ags, io):
"""Get Transport URLs for the file copied to storage"""

# verify previous test succeeded
results = app.metric_results()
if (results[3][1] != nap.OK ):
io.set_status(nap.WARNING, "VOGetTurl skipped")
return

if len(_voInfoDictionary.keys()) == 0:
io.set_status(nap.CRITICAL, 'No SRM endpoints found to test')
io.set_status(nap.WARNING, 'No SRM endpoints found to test')
return

for srmendpt in _voInfoDictionary.keys():
Expand All @@ -343,17 +373,22 @@ def metricVOGetTURLs(ags, io):
io.summary = 'protocol FAILED-[%s]' % protocol
except Exception as e:
io.set_status(
nap.UNKNOWN, 'problem invoking gfal2 getxattr(): %s:%s' %
nap.CRITICAL, 'problem invoking gfal2 getxattr(): %s:%s' %
(str(e), sys.exc_info()[0]))


@app.metric(seq=6, metric_name="VOGet", passive=True)
def metricVOGet(args, io):
"""Copy given remote file(s) from SRM to a local file."""

# verify previous test succeeded
results = app.metric_results()
if ( results[4][1] != nap.OK ):
io.set_status(nap.WARNING, "VOGet skipped")
return

if len(_voInfoDictionary.keys()) == 0:
io.set_status(nap.CRITICAL, 'No SRM endpoints found to test')
io.set_status(nap.WARNING, 'No SRM endpoints found to test')
return

for srmendpt in _voInfoDictionary.keys():
Expand Down Expand Up @@ -393,14 +428,20 @@ def metricVOGet(args, io):
io.summary = stMsg % ' NOT'
except Exception as e:
io.set_status(
nap.UNKNOWN, 'problem invoking gfal2 filecopy(): %s:%s' %
nap.CRITICAL, 'problem invoking gfal2 filecopy(): %s:%s' %
(str(e), sys.exc_info()[0]))


@app.metric(seq=7, metric_name="VODel", passive=True)
def metricVODel(args, io):
"""Delete given file(s) from SRM."""

# skip only if the put failed
results = app.metric_results()
if ( results[2][1] != nap.OK ):
io.set_status(nap.WARNING, "VODel skipped")
return

if len(_voInfoDictionary.keys()) == 0:
io.set_status(nap.CRITICAL, 'No SRM endpoints found to test')

Expand All @@ -422,7 +463,7 @@ def metricVODel(args, io):
io.status = nap.CRITICAL
except Exception as e:
io.set_status(
nap.UNKNOWN, 'problem invoking gfal2 unlink(): %s:%s' %
nap.CRITICAL, 'problem invoking gfal2 unlink(): %s:%s' %
(str(e), sys.exc_info()[0]))


Expand All @@ -436,8 +477,10 @@ def metricVOAlll(args, io):

if all(st == 0 for st in statuses):
io.set_status(nap.OK, "All fine")
if 2 in statuses:
io.set_status(nap.CRITICAL, "Error executing passive checks")
elif nap.CRITICAL in statuses:
io.set_status(nap.CRITICAL, "Critical error executing tests")
else:
io.set_status(nap.WARNING, "Some of the tests returned a warning")

try:
shutil.rmtree(workdir_metric)
Expand Down

0 comments on commit dc76c7a

Please sign in to comment.