Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from ARGOeu/devel
Browse files Browse the repository at this point in the history
Version 0.1.6-4
  • Loading branch information
themiszamani authored May 4, 2017
2 parents b921fd6 + b409e16 commit 125f093
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 7 deletions.
41 changes: 41 additions & 0 deletions modules/NagiosResponse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class NagiosResponse:
_msgBagWarning = []
_msgBagCritical = []
_okMsg = ""
_code = None

OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3

def __init__(self, ok_msg=""):
self._code = self.OK
self._okMsg = ok_msg


def writeWarningMessage(self, msg):
self._msgBagWarning.append(msg)

def writeCriticalMessage(self, msg):
self._msgBagCritical.append(msg)

def setCode(self, code):
self._code = code

def getCode(self):
return self._code

def getMsg(self):
if self._code == self.WARNING:
return "WARNING - " + self._toString(self._msgBagWarning)
elif self._code == self.CRITICAL:
return "CRITICAL - " + self._toString(self._msgBagCritical)
elif self._code == self.OK:
return "OK - " + self._okMsg if self._okMsg else "OK"
else:
return "UNKNOWN!"

def _toString(self, msgArray):
return ' | '.join(msgArray)

93 changes: 93 additions & 0 deletions modules/connectors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/python

import sys, os
import argparse
import copy

from datetime import datetime, timedelta
from pprint import pprint
from argo_egi_connectors.config import Global, CustomerConf
from NagiosResponse import NagiosResponse

downtime_state = 'downtimes-ok'
poem_state = 'poem-ok'
topology_state = 'topology-ok'
weights_state = 'weights-ok'

def check_file_ok(fname):
if os.path.isfile(fname):
fh = open(fname, 'r')
if fh.read().strip() == 'True':
return 0
else:
return 2

else:
return 1

def process_customer_jobs(files, cust_header, cust_conf, root_dir, date_sufix, nagios):
file_names=[downtime_state, poem_state, topology_state, weights_state]
if files is not None:
file_names = files

customer_jobs = cust_conf.get_jobs(cust_header)
for job in customer_jobs:
for filename in file_names:
if filename == downtime_state:
dates = copy.copy(date_sufix)[:-1]
dates.append(datetime.today().strftime("%Y_%m_%d"))
else:
dates = date_sufix

false_count = 0

for sufix in dates:
full_name = cust_conf.get_fullstatedir(root_dir, cust_header, job)+ '/' + filename + '_' + sufix
ret_val = check_file_ok(full_name)

if ret_val != 0:
false_count += 1
if (false_count == len(dates)):
nagios.setCode(nagios.CRITICAL)
nagios.writeCriticalMessage("Customer: " + cust_conf.get_custname(cust_header) + ", Job: " + job + ", File: " + filename.replace("-ok", "").upper() + " not ok for last " + str(len(dates)) + " days!")
elif (false_count == len(dates) - 1 and nagios.getCode() <= nagios.WARNING):
nagios.setCode(nagios.WARNING)
nagios.writeWarningMessage("Customer: " + cust_conf.get_custname(cust_header) + ", Job: " + job + ", File: " + filename.replace("-ok", "").upper() + " not ok.")

def process_customer(cmd_options, root_directory, date_sufix, nagios):
customer_conf = CustomerConf(sys.argv[0], cmd_options.config, jobattrs='')
customer_conf.parse()

for cust_header in customer_conf.get_customers():
process_customer_jobs(cmd_options.filename, cust_header, customer_conf, root_directory, date_sufix, nagios)

def main():
parser = argparse.ArgumentParser()
parser.add_argument('-c', dest='config', required=True, type=str, help='config file')
parser.add_argument('-f', dest='filename', required=False, type=str, nargs='+', help='file names to monitor. Default: downtimes-ok poem-ok topology-ok weights-ok')
cmd_options = parser.parse_args()

opts = {"InputState": ["SaveDir", "Days"]}
global_conf = Global(None, opts)

options = global_conf.parse();
root_directory = options.values()[0]
days_num = int(options.values()[1])
todays_date = datetime.today()

days = []
for i in range(1, days_num + 1):
days.append(todays_date + timedelta(days=-i))

date_sufix = []
for day in days:
date_sufix.append(day.strftime("%Y_%m_%d"))

nagios = NagiosResponse("All connectors are working fine.")
process_customer(cmd_options, root_directory, date_sufix, nagios)

print(nagios.getMsg())
raise SystemExit(nagios.getCode())

if __name__ == "__main__":
main()
8 changes: 5 additions & 3 deletions modules/poem.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('-H', dest='hostname', required=True, type=str, help='hostname')
parser.add_argument('-r', dest='profile', required=True, type=str, help='profile name')
parser.add_argument('--cert', dest='cert', default=HOSTCERT, type=str, help='Certificate')
parser.add_argument('--key', dest='key', default=HOSTKEY, type=str, help='Certificate key')
parser.add_argument('--capath', dest='capath', default=CAPATH, type=str, help='CA directory')
parser.add_argument('-t', dest='timeout', required=True, type=int, default=180)
arguments = parser.parse_args()
Expand All @@ -123,21 +125,21 @@ def main():

# verify client certificate
try:
requests.get('https://' + arguments.hostname + '/poem/', cert=(HOSTCERT, HOSTKEY), verify=True)
requests.get('https://' + arguments.hostname + '/poem/', cert=(arguments.cert, arguments.key), verify=True)
except requests.exceptions.RequestException as e:
print "CRITICAL - Client certificate verification failed: %s" % errmsg_from_excp(e)
raise SystemExit(2)

try:
metrics = requests.get('https://' + arguments.hostname + MIP_API, cert=(HOSTCERT, HOSTKEY), verify=True)
metrics = requests.get('https://' + arguments.hostname + MIP_API, cert=(arguments.cert, arguments.key), verify=True)
metricsjson = metrics.json()
except requests.exceptions.RequestException as e:
print 'CRITICAL - cannot connect to %s: %s' % ('https://' + arguments.hostname + MIP_API,
errmsg_from_excp(e))
raise SystemExit(2)

try:
profiles = requests.get('https://' + arguments.hostname + '/poem/api/0.2/json/profiles', cert=(HOSTCERT, HOSTKEY), verify=True)
profiles = requests.get('https://' + arguments.hostname + '/poem/api/0.2/json/profiles', cert=(arguments.cert, arguments.key), verify=True)
profilesjson = profiles.json()
except requests.exceptions.RequestException as e:
print 'CRITICAL - cannot connect to %s: %s' % ('https://' + arguments.hostname + PR_API,
Expand Down
21 changes: 17 additions & 4 deletions nagios-plugins-argo.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Name: nagios-plugins-argo
Summary: ARGO components related probes.
Version: 0.1.5
Release: 2%{?dist}
Version: 0.1.6
Release: 4%{?dist}
License: ASL 2.0
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Expand All @@ -16,9 +16,10 @@ Requires: python-requests, pyOpenSSL, python-argparse, nagios-plugins-file_age,
%description
This package includes probes for ARGO components.
Currently it supports the following components:
- ARGO Web API
- ARGO Consumer log
- POEM
- ARGO EGI Connectors
- ARGO Web API
- POEM service

%prep
%setup -q
Expand All @@ -42,6 +43,18 @@ rm -rf %{buildroot}


%changelog
* Wed Apr 26 2017 Daniel Vrcic <[email protected]> - 0.1.6-4%{?dist}
- converted tab to whitespaces
- check current date for the downtimes state
- vertical line separator for multiple fail msgs
* Wed Apr 26 2017 Hrvoje Sute <[email protected]> - 0.1.6-3%{?dist}
- More descriptive OK status
* Tue Apr 25 2017 Hrvoje Sute <[email protected]> - 0.1.6-2%{?dist}
- Removed debugger lefover module
* Thu Apr 20 2017 Hrvoje Sute <[email protected]> - 0.1.6-1%{?dist}
- ARGO-754 Nagios sensor for connectors component
* Thu Apr 6 2017 Daniel Vrcic <[email protected]> - 0.1.5-3%{?dist}
- ARGO-773 POEM probe should have argument for client certificate
* Tue Mar 21 2017 Daniel Vrcic <[email protected]>, Themis Zamani <[email protected]> - 0.1.5-2%{?dist}
- POEM probe verify certs in all request calls to remove warning msg
- ARGO-756 [WEB API] - New status check to nagios internal probe
Expand Down
Loading

0 comments on commit 125f093

Please sign in to comment.