Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dell_emc vplex device information collection #519

Merged
merged 6 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
65 changes: 65 additions & 0 deletions delfin/drivers/dell_emc/vplex/alert_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import hashlib
import time

from oslo_log import log

from delfin import exception
from delfin.common import constants
from delfin.i18n import _

LOG = log.getLogger(__name__)


class AlertHandler(object):
OID_SEVERITY = '1.3.6.1.6.3.1.1.4.1.0'
OID_COMPONENT = '1.3.6.1.4.1.1139.21.1.3.0'
OID_SYMPTOMTEXT = '1.3.6.1.4.1.1139.21.1.5.0'

TRAP_LEVEL_MAP = {'1.3.6.1.4.1.1139.21.0.1': constants.Severity.CRITICAL,
'1.3.6.1.4.1.1139.21.0.2': constants.Severity.MAJOR,
'1.3.6.1.4.1.1139.21.0.3': constants.Severity.WARNING,
'1.3.6.1.4.1.1139.21.0.4':
constants.Severity.INFORMATIONAL
}

SECONDS_TO_MS = 1000

@staticmethod
def parse_alert(context, alert):
try:
description = alert.get(AlertHandler.OID_SYMPTOMTEXT)
alert_model = dict()
alert_model['alert_id'] = alert.get(AlertHandler.OID_COMPONENT)
alert_model['alert_name'] = description
alert_model['severity'] = AlertHandler.TRAP_LEVEL_MAP.get(
alert.get(AlertHandler.OID_SEVERITY),
constants.Severity.INFORMATIONAL)
alert_model['category'] = constants.Category.FAULT
alert_model['type'] = constants.EventType.EQUIPMENT_ALARM
occur_time = int(time.time()) * AlertHandler.SECONDS_TO_MS
alert_model['occur_time'] = occur_time
alert_model['description'] = description
alert_model['resource_type'] = constants.DEFAULT_RESOURCE_TYPE
alert_model['location'] = ''
alert_model['match_key'] = hashlib.md5(description.encode()). \
hexdigest()

return alert_model
except Exception as e:
LOG.error(e)
msg = (_("Failed to build alert model as some attributes missing "
"in alert message."))
raise exception.InvalidResults(msg)
17 changes: 17 additions & 0 deletions delfin/drivers/dell_emc/vplex/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SOCKET_TIMEOUT = 10
BASE_CONTEXT = '/vplex'
REST_AUTH_URL = '/vplex/clusters'
126 changes: 126 additions & 0 deletions delfin/drivers/dell_emc/vplex/rest_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Copyright 2021 The SODA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from oslo_log import log as logging

from delfin import cryptor
from delfin import exception
from delfin.drivers.dell_emc.vplex import consts
from delfin.drivers.utils.rest_client import RestClient

LOG = logging.getLogger(__name__)


class RestHandler(RestClient):

def __init__(self, **kwargs):
super(RestHandler, self).__init__(**kwargs)

def login(self):
try:
data = {}
self.init_http_head()
self.session.headers.update({
"username": self.rest_username,
"password": cryptor.decode(self.rest_password)})
res = self.do_call(consts.REST_AUTH_URL, data, 'GET')
if res.status_code != 200:
LOG.error("Login error. URL: %(url)s\n"
"Reason: %(reason)s.",
{"url": consts.REST_AUTH_URL, "reason": res.text})
if 'User authentication failed' in res.text:
raise exception.InvalidUsernameOrPassword()
else:
raise exception.BadResponse(res.text)
except Exception as e:
LOG.error("Login error: %s", six.text_type(e))
raise e

def get_rest_info(self, url, data=None, method='GET'):
"""Return dict result of the url response."""
result_json = None
res = self.do_call(url, data, method)
if res.status_code == 200:
result_json = res.json().get('response')
return result_json

def get_virtual_volume_by_name_resp(self, cluster_name,
virtual_volume_name):
url = '%s/clusters/%s/virtual-volumes/%s' % \
(consts.BASE_CONTEXT, cluster_name, virtual_volume_name)
response = self.get_rest_info(url)
return response

def get_virtual_volume_resp(self, cluster_name):
url = '%s/clusters/%s/virtual-volumes' % (
consts.BASE_CONTEXT, cluster_name)
response = self.get_rest_info(url)
return response

def get_cluster_resp(self):
uri = '%s/clusters' % consts.BASE_CONTEXT
response = self.get_rest_info(uri)
return response

def get_devcie_resp(self, cluster_name):
url = '%s/clusters/%s/devices' % (consts.BASE_CONTEXT, cluster_name)
response = self.get_rest_info(url)
return response

def get_device_by_name_resp(self, cluster_name, device_name):
url = '%s/clusters/%s/devices/%s' % (
consts.BASE_CONTEXT, cluster_name, device_name)
response = self.get_rest_info(url)
return response

def get_health_check_resp(self):
url = '%s/health-check' % consts.BASE_CONTEXT
data = {"args": "-l"}
response = self.get_rest_info(url, data, method='POST')
return response

def get_cluster_by_name_resp(self, cluster_name):
url = '%s/clusters/%s' % (consts.BASE_CONTEXT, cluster_name)
response = self.get_rest_info(url)
return response

def get_storage_volume_summary_resp(self, cluster_name):
url = '%s/storage-volume+summary' % consts.BASE_CONTEXT
args = '--clusters %s' % cluster_name
data = {"args": args}
response = self.get_rest_info(url, data, method='POST')
return response

def get_device_summary_resp(self, cluster_name):
url = '%s/local-device+summary' % consts.BASE_CONTEXT
args = '--clusters %s' % cluster_name
data = {"args": args}
response = self.get_rest_info(url, data, method='POST')
return response

def get_virtual_volume_summary_resp(self, cluster_name):
url = '%s/virtual-volume+summary' % consts.BASE_CONTEXT
args = '--clusters %s' % cluster_name
data = {"args": args}
response = self.get_rest_info(url, data, method='POST')
return response

def logout(self):
try:
if self.session:
self.session.close()
except Exception as e:
err_msg = "Logout error: %s" % (six.text_type(e))
LOG.error(err_msg)
raise e
Loading