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 #28 from ARGOeu/devel
Version 0.1.6-4
- Loading branch information
Showing
6 changed files
with
406 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
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) | ||
|
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,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() |
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,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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
Oops, something went wrong.