summaryrefslogtreecommitdiffstats
path: root/app/monitoring
diff options
context:
space:
mode:
authoryayogev <yaronyogev@gmail.com>2018-02-27 17:00:05 +0200
committeryayogev <yaronyogev@gmail.com>2018-02-27 17:00:05 +0200
commit648a394f7a318443dfd82f790f83a79616c26905 (patch)
tree719508e9d99771c3de056a9c2914d461c35fb967 /app/monitoring
parent100add41cfe2b987524b190c1c92771a3c4f1d5f (diff)
US3541 merge various fixes to OPNFV branch
timestamp of last commit tt was merged: 26-Jan-2018 16:25. Change-Id: I7b0bf7885d7d0badb81c794a52c480b905d78459 Signed-off-by: yayogev <yaronyogev@gmail.com>
Diffstat (limited to 'app/monitoring')
-rw-r--r--app/monitoring/checks/check_instance_communictions.py4
-rwxr-xr-xapp/monitoring/checks/check_ping.py2
-rwxr-xr-xapp/monitoring/checks/check_pnic_ovs.py4
-rwxr-xr-xapp/monitoring/checks/check_pnic_vpp.py2
-rw-r--r--app/monitoring/checks/check_vconnector.py2
-rwxr-xr-xapp/monitoring/checks/check_vedge_ovs.py2
-rwxr-xr-xapp/monitoring/checks/check_vedge_vpp.py2
-rwxr-xr-xapp/monitoring/checks/check_vnic_vconnector.py2
-rwxr-xr-xapp/monitoring/checks/check_vnic_vpp.py2
-rw-r--r--app/monitoring/checks/check_vservice.py2
-rw-r--r--app/monitoring/handlers/handle_otep.py2
-rw-r--r--app/monitoring/handlers/monitoring_check_handler.py32
-rw-r--r--app/monitoring/setup/monitoring_handler.py27
13 files changed, 61 insertions, 24 deletions
diff --git a/app/monitoring/checks/check_instance_communictions.py b/app/monitoring/checks/check_instance_communictions.py
index d3a94b7..4ce5165 100644
--- a/app/monitoring/checks/check_instance_communictions.py
+++ b/app/monitoring/checks/check_instance_communictions.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
@@ -31,7 +31,7 @@ arp_mac_pos = arp_headers.index('HWaddress')
arp_flags_pos = arp_headers.index('Flags')
-def check_vnic_tuple(vnic_and_service: str):
+def check_vnic_tuple(vnic_and_service):
tuple_parts = vnic_and_service.split(',')
local_service_id = tuple_parts[0]
mac_address = tuple_parts[1]
diff --git a/app/monitoring/checks/check_ping.py b/app/monitoring/checks/check_ping.py
index 35e7234..fbf1304 100755
--- a/app/monitoring/checks/check_ping.py
+++ b/app/monitoring/checks/check_ping.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/checks/check_pnic_ovs.py b/app/monitoring/checks/check_pnic_ovs.py
index c26e42f..7cfa699 100755
--- a/app/monitoring/checks/check_pnic_ovs.py
+++ b/app/monitoring/checks/check_pnic_ovs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
@@ -15,7 +15,7 @@ import subprocess
from binary_converter import binary2str
-def nic_not_found(name: str, output: str):
+def nic_not_found(name, output):
print("Error finding NIC {}{}{}\n".format(name, ': ' if output else '',
output))
return 2
diff --git a/app/monitoring/checks/check_pnic_vpp.py b/app/monitoring/checks/check_pnic_vpp.py
index 942fdc2..3db4e49 100755
--- a/app/monitoring/checks/check_pnic_vpp.py
+++ b/app/monitoring/checks/check_pnic_vpp.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/checks/check_vconnector.py b/app/monitoring/checks/check_vconnector.py
index 237a195..961d7ad 100644
--- a/app/monitoring/checks/check_vconnector.py
+++ b/app/monitoring/checks/check_vconnector.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/checks/check_vedge_ovs.py b/app/monitoring/checks/check_vedge_ovs.py
index 849af66..33d3f71 100755
--- a/app/monitoring/checks/check_vedge_ovs.py
+++ b/app/monitoring/checks/check_vedge_ovs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/checks/check_vedge_vpp.py b/app/monitoring/checks/check_vedge_vpp.py
index 346feae..94d5977 100755
--- a/app/monitoring/checks/check_vedge_vpp.py
+++ b/app/monitoring/checks/check_vedge_vpp.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/checks/check_vnic_vconnector.py b/app/monitoring/checks/check_vnic_vconnector.py
index 76efd0b..fc8721f 100755
--- a/app/monitoring/checks/check_vnic_vconnector.py
+++ b/app/monitoring/checks/check_vnic_vconnector.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/checks/check_vnic_vpp.py b/app/monitoring/checks/check_vnic_vpp.py
index 0f77ddd..22cc31d 100755
--- a/app/monitoring/checks/check_vnic_vpp.py
+++ b/app/monitoring/checks/check_vnic_vpp.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/checks/check_vservice.py b/app/monitoring/checks/check_vservice.py
index a95a46a..2a30a53 100644
--- a/app/monitoring/checks/check_vservice.py
+++ b/app/monitoring/checks/check_vservice.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
# and others #
diff --git a/app/monitoring/handlers/handle_otep.py b/app/monitoring/handlers/handle_otep.py
index 0189625..b19baab 100644
--- a/app/monitoring/handlers/handle_otep.py
+++ b/app/monitoring/handlers/handle_otep.py
@@ -29,7 +29,7 @@ class HandleOtep(MonitoringCheckHandler):
self.log.error('Port not found: ' + port_id)
return 1
status = check_result['status']
- port['status'] = self.STATUS_LABEL[status]
+ port['status'] = self.get_label_for_status(status)
port['status_value'] = status
port['status_text'] = check_result['output']
diff --git a/app/monitoring/handlers/monitoring_check_handler.py b/app/monitoring/handlers/monitoring_check_handler.py
index c1f70fb..4902c3c 100644
--- a/app/monitoring/handlers/monitoring_check_handler.py
+++ b/app/monitoring/handlers/monitoring_check_handler.py
@@ -19,14 +19,13 @@ from messages.message import Message
from utils.inventory_mgr import InventoryMgr
from utils.logging.full_logger import FullLogger
from utils.special_char_converter import SpecialCharConverter
-from utils.string_utils import stringify_datetime
SOURCE_SYSTEM = 'Sensu'
ERROR_LEVEL = ['info', 'warn', 'error']
class MonitoringCheckHandler(SpecialCharConverter):
- STATUS_LABEL = ['OK', 'Warning', 'Error']
+ status_labels = {}
TIME_FORMAT = '%Y-%m-%d %H:%M:%S %Z'
def __init__(self, args):
@@ -39,9 +38,30 @@ class MonitoringCheckHandler(SpecialCharConverter):
self.inv = InventoryMgr()
self.inv.log.set_loglevel(args.loglevel)
self.inv.set_collections(args.inventory)
+ self.status_labels = self.get_status_labels()
except FileNotFoundError:
sys.exit(1)
+ def get_status_labels(self):
+ statuses_name_search = {'name': 'monitoring_check_statuses'}
+ labels_data = self.inv.find_one(search=statuses_name_search,
+ collection='constants')
+ if not isinstance(labels_data, dict) or 'data' not in labels_data:
+ return ''
+ labels = {}
+ for status_data in labels_data['data']:
+ if not isinstance(status_data, dict):
+ continue
+ val = int(status_data['value'])
+ label = status_data['label']
+ labels[val] = label
+ return labels
+
+ def get_label_for_status(self, status: int) -> str:
+ if status not in self.status_labels.keys():
+ return ''
+ return self.status_labels.get(status, '')
+
def doc_by_id(self, object_id):
doc = self.inv.get_by_id(self.env, object_id)
if not doc:
@@ -57,7 +77,10 @@ class MonitoringCheckHandler(SpecialCharConverter):
return doc
def set_doc_status(self, doc, status, status_text, timestamp):
- doc['status'] = self.STATUS_LABEL[status] if isinstance(status, int) \
+ doc['status_value'] = status if isinstance(status, int) \
+ else status
+ doc['status'] = self.get_label_for_status(status) \
+ if isinstance(status, int) \
else status
if status_text:
doc['status_text'] = status_text
@@ -83,7 +106,8 @@ class MonitoringCheckHandler(SpecialCharConverter):
obj_id = 'link_{}_{}'.format(doc['source_id'], doc['target_id']) \
if is_link \
else doc['id']
- obj_type = 'link_{}'.format(doc['link_type']) if is_link else doc['type']
+ obj_type = 'link_{}'.format(doc['link_type']) if is_link else \
+ doc['type']
display_context = obj_id if is_link \
else doc['network_id'] if doc['type'] == 'port' else doc['id']
level = error_level if error_level\
diff --git a/app/monitoring/setup/monitoring_handler.py b/app/monitoring/setup/monitoring_handler.py
index 903b8d8..0eeb668 100644
--- a/app/monitoring/setup/monitoring_handler.py
+++ b/app/monitoring/setup/monitoring_handler.py
@@ -105,13 +105,25 @@ class MonitoringHandler(MongoAccess, CliAccess, BinaryConverter):
if 'condition' not in doc:
return True
condition = doc['condition']
- if 'mechanism_drivers' not in condition:
- return True
- required_mechanism_drivers = condition['mechanism_drivers']
- if not isinstance(required_mechanism_drivers, list):
- required_mechanism_drivers = [required_mechanism_drivers]
- intersection = [val for val in required_mechanism_drivers
- if val in self.mechanism_drivers]
+ if not isinstance(condition, dict):
+ self.log.error('incorrect condition in monitoring ({}): '
+ 'condition must be a dict'
+ .format(doc.get(doc.get('type'), '')))
+ return False
+ for key, required_value in condition.items():
+ if not self.check_env_config(key, required_value):
+ return False
+ return True
+
+ def check_env_config(self, config_name, required_config_value):
+ required_config_values = required_config_value \
+ if isinstance(required_config_value, list) \
+ else [required_config_value]
+ conf_values = self.configuration.environment.get(config_name, [])
+ conf_values = conf_values if isinstance(conf_values, list) \
+ else [conf_values]
+ intersection = [val for val in required_config_values
+ if val in conf_values]
return bool(intersection)
def content_replace(self, content):
@@ -435,6 +447,7 @@ class MonitoringHandler(MongoAccess, CliAccess, BinaryConverter):
if '/*' in local_dir else local_dir
if local_dir_base.strip('/*') == remote_path.strip('/*'):
return # same directory - nothing to do
+ self.make_remote_dir(host, remote_path)
cmd = 'cp {} {}'.format(what_to_copy, remote_path)
self.run(cmd, ssh=ssh)
return