This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from ARGOeu/devel
Version 0.1.10
- Loading branch information
Showing
9 changed files
with
295 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import socket | ||
from nagios_plugins_argo.NagiosResponse import NagiosResponse | ||
|
||
maxcmdlength = 128 | ||
timeout = 10 | ||
|
||
def parse_result(query): | ||
try: | ||
w, r = query.split('+') | ||
|
||
w = w.split(':')[1] | ||
r = int(r.split(':')[1]) | ||
|
||
except (ValueError, KeyError): | ||
return (w, 'error') | ||
|
||
return (w, r) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-s', dest='socket', required=True, type=str, help='AMS inspection socket') | ||
parser.add_argument('-q', dest='query', action='append', required=True, type=str, help='Query') | ||
parser.add_argument('-c', dest='threshold', action='append', required=True, type=int, help='Threshold') | ||
parser.add_argument('-t', dest='timeout', required=False, type=int, help='Timeout') | ||
arguments = parser.parse_args() | ||
|
||
nr = NagiosResponse() | ||
|
||
if len(arguments.threshold) != len(arguments.query): | ||
nr.setCode(2) | ||
nr.writeCriticalMessage('Wrong arguments') | ||
print nr.getMsg() | ||
raise SystemExit(nr.getCode()) | ||
|
||
if arguments.timeout: | ||
timeo = arguments.timeout | ||
else: | ||
timeo = timeout | ||
|
||
try: | ||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.setblocking(0) | ||
sock.settimeout(timeo) | ||
|
||
sock.connect(arguments.socket) | ||
sock.send(' '.join(arguments.query), maxcmdlength) | ||
data = sock.recv(maxcmdlength) | ||
|
||
lr = list() | ||
for r in data.split(): | ||
lr.append(parse_result(r)) | ||
|
||
error = False | ||
for e in lr: | ||
if e[1] == 'error': | ||
nr.setCode(2) | ||
nr.writeCriticalMessage('Worker {0} {1}'.format(e[0], e[1])) | ||
error = True | ||
if error: | ||
print nr.getMsg() | ||
raise SystemExit(nr.getCode()) | ||
|
||
error = False | ||
nr.setCode(0) | ||
i = 0 | ||
while i < len(lr): | ||
e = lr[i] | ||
if e[1] < arguments.threshold[i]: | ||
nr.setCode(2) | ||
nr.writeCriticalMessage('Worker {0} published {1} (threshold {2})'.format(e[0], e[1], arguments.threshold[i])) | ||
error = True | ||
i+=1 | ||
|
||
if error: | ||
print nr.getMsg() | ||
raise SystemExit(nr.getCode()) | ||
else: | ||
i = 0 | ||
nr.setCode(0) | ||
while i < len(lr): | ||
e = lr[i] | ||
nr.writeOkMessage('Worker {0} published {1} (threshold {2})'.format(e[0], e[1], arguments.threshold[i])) | ||
i+=1 | ||
|
||
print nr.getMsg() | ||
raise SystemExit(nr.getCode()) | ||
|
||
|
||
except socket.timeout as e: | ||
nr.setCode(2) | ||
nr.writeCriticalMessage('Socket response timeout after {0}s'.format(timeo)) | ||
print nr.getMsg() | ||
raise SystemExit(nr.getCode()) | ||
|
||
except socket.error as e: | ||
nr.setCode(2) | ||
nr.writeCriticalMessage('Socket error: {0}'.format(str(e))) | ||
print nr.getMsg() | ||
raise SystemExit(nr.getCode()) | ||
|
||
finally: | ||
sock.close() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env python | ||
|
||
from argparse import ArgumentParser | ||
import datetime | ||
import time | ||
import json | ||
from argo_ams_library import ArgoMessagingService, AmsException | ||
from NagiosResponse import NagiosResponse | ||
|
||
|
||
def main(): | ||
TIMEOUT = 180 | ||
INTERVAL = 300 | ||
|
||
parser = ArgumentParser(description="Nagios probe for monitoring the compute engine's flow.") | ||
parser.add_argument('-H', dest='host', type=str, default='msg-devel.argo.grnet.gr', help='FQDN of AMS Service') | ||
parser.add_argument('--token', type=str, required=True, help='Given token') | ||
parser.add_argument('--project', type=str, required=True, help='Project registered in AMS Service') | ||
parser.add_argument('--push_topic', type=str, default='create_data', help='Given topic') | ||
parser.add_argument('--push_subscription', type=str, default='create_data_sub', help='Push_Subscription name') | ||
parser.add_argument('--pull_subscription', type=str, default='retrieve_data_sub', help='Push_Subscription name') | ||
parser.add_argument('-t', dest='timeout', type=int, default=TIMEOUT, help='Timeout for ams calls') | ||
parser.add_argument('-i', dest='interval', type=int, default=INTERVAL, help='The amount of time the probe should try to read from ams, beforing exiting') | ||
|
||
cmd_options = parser.parse_args() | ||
|
||
run_timestamp = str(datetime.datetime.now()) | ||
|
||
nagios = NagiosResponse("System Dataflow at " + run_timestamp + " completed successfully.") | ||
ams = ArgoMessagingService(endpoint=cmd_options.host, token=cmd_options.token, project=cmd_options.project) | ||
try: | ||
# For both subscriptions move their offset to max | ||
move_sub_offset_to_max(ams, cmd_options.push_subscription, timeout=cmd_options.timeout) | ||
move_sub_offset_to_max(ams, cmd_options.pull_subscription, timeout=cmd_options.timeout) | ||
|
||
# publish a message with the current timestamp as its content | ||
req_data = {'message': run_timestamp, 'errors': []} | ||
d1 = {'data': json.dumps(req_data), 'attributes': {}} | ||
ams.publish(cmd_options.push_topic, d1, timeout=cmd_options.timeout) | ||
start = time.time() | ||
no_resp = True | ||
while no_resp: | ||
end = time.time() | ||
# check if the systsem has written to the retrieve topic | ||
resp = ams.pull_sub(cmd_options.pull_subscription, timeout=cmd_options.timeout) | ||
if len(resp) > 0: | ||
no_resp = False | ||
resp_data = json.loads(resp[0][1]._data) | ||
# check if the submitted and retrieved data differ | ||
if req_data != resp_data: | ||
nagios_report(nagios, 'critical', "System Dataflow at " + run_timestamp + " completed with errors. Expected: " + str(req_data) + ". Found: " + str(resp_data)+".") | ||
# check if data was retrieved within the expected timeout period, BUT had some kind of delay | ||
elif req_data == resp_data and end-start > cmd_options.interval: | ||
nagios_report(nagios, 'warning', "System Dataflow at " + run_timestamp + " completed successfully using an extra time of: " + str((end-start)-cmd_options.interval) + "s.") | ||
|
||
if (end-start) > 2 * cmd_options.interval: | ||
nagios_report(nagios, 'critical', "System Dataflow at " + run_timestamp + " returned with no message from the systsem after " + str(2 * cmd_options.interval) + "s.") | ||
|
||
# check for a response every 10 seconds | ||
time.sleep(10) | ||
|
||
print(nagios.getMsg()) | ||
raise SystemExit(nagios.getCode()) | ||
|
||
except AmsException as e: | ||
nagios_report(nagios, 'critical', e.msg) | ||
|
||
|
||
def nagios_report(nagios, status, msg): | ||
nagios_method = getattr(nagios, "write{0}Message".format(status.capitalize())) | ||
nagios_method(msg) | ||
nagios_status = getattr(nagios, status.upper()) | ||
nagios.setCode(nagios_status) | ||
if status == 'critical': | ||
print(nagios.getMsg()) | ||
raise SystemExit(nagios.getCode()) | ||
|
||
|
||
def move_sub_offset_to_max(ams, sub, **reqkwargs): | ||
# Retrieve the max offset for the given subscription | ||
max_sub_offset = ams.getoffsets_sub(sub, "max", **reqkwargs) | ||
# Move the current offset to the max position | ||
ams.modifyoffset_sub(sub, max_sub_offset, **reqkwargs) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
Name: nagios-plugins-argo | ||
Summary: ARGO components related probes. | ||
Version: 0.1.8 | ||
Version: 0.1.10 | ||
Release: 1%{?dist} | ||
License: ASL 2.0 | ||
Source0: %{name}-%{version}.tar.gz | ||
|
@@ -44,6 +44,8 @@ rm -rf %{buildroot} | |
|
||
|
||
%changelog | ||
* Tue Mar 27 2018 Daniel Vrcic <[email protected]> - 0.1.9-1%{?dist} | ||
- added argo-nagios-ams-publisher | ||
* Mon Dec 4 2017 Daniel Vrcic <[email protected]> - 0.1.8-1%{?dist} | ||
- connectors-probe warning logic revised | ||
- connectors-probe updated global.conf parsing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env python | ||
|
||
from nagios_plugins_argo import amspub_check | ||
|
||
amspub_check.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python | ||
|
||
from nagios_plugins_argo import ce_check | ||
|
||
ce_check.main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters