forked from sodafoundation/delfin
-
Notifications
You must be signed in to change notification settings - Fork 7
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 #27 from liuxiaohuan-ghca/emc_vplex
Emc vplex
- Loading branch information
Showing
7 changed files
with
815 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,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) |
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,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' |
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,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 |
Oops, something went wrong.