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

Documentation Spelling corrected #990

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
52 changes: 26 additions & 26 deletions delfin/alert_manager/snmp_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def __init__(self):
self.snmp_error_flag = {}

def validate(self, ctxt, alert_source):
alert_source = dict(alert_source)
engine_id = alert_source.get('engine_id')
try:
alert_source = self.validate_connectivity(alert_source)
Expand All @@ -46,7 +45,6 @@ def validate(self, ctxt, alert_source):
# engine id if engine id is empty. Therefore, engine id
# should be saved in database.
if not engine_id and alert_source.get('engine_id'):

alert_source_dict = {
'engine_id': alert_source.get('engine_id')}
db.alert_source_update(ctxt,
Expand Down Expand Up @@ -82,23 +80,33 @@ def validate_connectivity(alert_source):

cmd_gen = cmdgen.CommandGenerator()

# Register engine observer to get engineId,
# Code reference from: http://snmplabs.com/pysnmp/
observer_context = {}
cmd_gen.snmpEngine.observer.registerObserver(
lambda e, p, v, c: c.update(
securityEngineId=v['securityEngineId']),
'rfc3412.prepareDataElements:internal',
cbCtx=observer_context
)

version = alert_source.get('version')

# Connect to alert source through snmp get to check the configuration
try:
target = cmdgen.UdpTransportTarget((alert_source['host'],
alert_source['port']),
timeout=alert_source[
'expiration'],
retries=alert_source[
'retry_num'])
target.setLocalAddress((CONF.my_ip, 0))
if version.lower() == 'snmpv3':
auth_key = cryptor.decode(alert_source['auth_key'])
privacy_key = cryptor.decode(alert_source['privacy_key'])
# Register engine observer to get engineId,
# Code reference from: http://snmplabs.com/pysnmp/
observer_context = {}
cmd_gen.snmpEngine.observer.registerObserver(
lambda e, p, v, c: c.update(
securityEngineId=v['securityEngineId']),
'rfc3412.prepareDataElements:internal',
cbCtx=observer_context
)
auth_key = None
if alert_source['auth_key']:
auth_key = cryptor.decode(alert_source['auth_key'])
privacy_key = None
if alert_source['privacy_key']:
privacy_key = cryptor.decode(alert_source['privacy_key'])
auth_protocol = None
privacy_protocol = None
if alert_source['auth_protocol']:
Expand All @@ -118,12 +126,7 @@ def validate_connectivity(alert_source):
authProtocol=auth_protocol,
privProtocol=privacy_protocol,
securityEngineId=engine_id),
cmdgen.UdpTransportTarget((alert_source['host'],
alert_source['port']),
timeout=alert_source[
'expiration'],
retries=alert_source[
'retry_num']),
target,
constants.SNMP_QUERY_OID,
)

Expand All @@ -138,15 +141,12 @@ def validate_connectivity(alert_source):
cmdgen.CommunityData(
community_string,
contextName=alert_source['context_name']),
cmdgen.UdpTransportTarget((alert_source['host'],
alert_source['port']),
timeout=alert_source[
'expiration'],
retries=alert_source[
'retry_num']),
target,
constants.SNMP_QUERY_OID,
)

cmd_gen.snmpEngine.transportDispatcher.closeDispatcher()

if not error_indication:
return alert_source

Expand Down
32 changes: 31 additions & 1 deletion delfin/api/schemas/access_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@
'required': ['host', 'port', 'username'],
'additionalProperties': False
},
'cli': {
'type': 'object',
'properties': {
'host': parameter_types.hostname_or_ip_address,
'port': parameter_types.tcp_udp_port,
'username': {'type': 'string', 'minLength': 1,
'maxLength': 255},
'password': {'type': 'string', 'minLength': 1,
'maxLength': 255}
},
'required': ['host', 'username', 'password'],
'additionalProperties': False
},
'smis': {
'type': 'object',
'properties': {
'host': parameter_types.hostname_or_ip_address,
'port': parameter_types.tcp_udp_port,
'username': {'type': 'string', 'minLength': 1,
'maxLength': 255},
'password': {'type': 'string', 'minLength': 1,
'maxLength': 255},
'namespace': {'type': 'string', 'minLength': 1,
'maxLength': 255}
},
'required': ['host', 'username', 'password'],
'additionalProperties': False
},
'extra_attributes': {
'type': 'object',
'patternProperties': {
Expand All @@ -57,7 +85,9 @@
},
'anyOf': [
{'required': ['rest']},
{'required': ['ssh']}
{'required': ['ssh']},
{'required': ['cli']},
{'required': ['smis']}
],
'additionalProperties': False
}
32 changes: 31 additions & 1 deletion delfin/api/schemas/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@
'required': ['host', 'port', 'username', 'password', 'pub_key'],
'additionalProperties': False
},
'cli': {
'type': 'object',
'properties': {
'host': parameter_types.hostname_or_ip_address,
'port': parameter_types.tcp_udp_port,
'username': {'type': 'string', 'minLength': 1,
'maxLength': 255},
'password': {'type': 'string', 'minLength': 1,
'maxLength': 255}
},
'required': ['host', 'username', 'password'],
'additionalProperties': False
},
'smis': {
'type': 'object',
'properties': {
'host': parameter_types.hostname_or_ip_address,
'port': parameter_types.tcp_udp_port,
'username': {'type': 'string', 'minLength': 1,
'maxLength': 255},
'password': {'type': 'string', 'minLength': 1,
'maxLength': 255},
'namespace': {'type': 'string', 'minLength': 1,
'maxLength': 255}
},
'required': ['host', 'username', 'password'],
'additionalProperties': False
},
'extra_attributes': {
'type': 'object',
'patternProperties': {
Expand All @@ -60,7 +88,9 @@
'required': ['vendor', 'model'],
'anyOf': [
{'required': ['rest']},
{'required': ['ssh']}
{'required': ['ssh']},
{'required': ['cli']},
{'required': ['smis']}
],
'additionalProperties': False
}
1 change: 1 addition & 0 deletions delfin/api/v1/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,5 @@ def _set_synced_if_ok(context, storage_id, resource_count):
storage['sync_status'] > 0:
raise exception.StorageIsSyncing(storage['id'])
storage['sync_status'] = resource_count * constants.ResourceSync.START
storage['updated_at'] = current_time
db.storage_update(context, storage['id'], storage)
2 changes: 1 addition & 1 deletion delfin/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
DB_MAX_INT = 0x7FFFFFFF

# Valid access type supported currently.
ACCESS_TYPE = ['rest', 'ssh']
ACCESS_TYPE = ['rest', 'ssh', 'cli', 'smis']


# Custom fields for Delfin objects
Expand Down
2 changes: 2 additions & 0 deletions delfin/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class AccessInfo(BASE, DelfinBase):
model = Column(String(255))
rest = Column(JsonEncodedDict)
ssh = Column(JsonEncodedDict)
cli = Column(JsonEncodedDict)
smis = Column(JsonEncodedDict)
extra_attributes = Column(JsonEncodedDict)


Expand Down
7 changes: 4 additions & 3 deletions delfin/drivers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def discover_storage(self, context, access_info):
access_info = db.access_info_create(context, access_info)
storage['id'] = access_info['storage_id']
storage = db.storage_create(context, storage)
self.driver_manager.update_driver(storage['id'], driver)

LOG.info("Storage found successfully.")
return storage
Expand All @@ -63,7 +62,6 @@ def update_access_info(self, context, access_info):
helper.check_storage_consistency(context, storage_id, storage_new)
access_info = db.access_info_update(context, storage_id, access_info)
db.storage_update(context, storage_id, storage_new)
self.driver_manager.update_driver(storage_id, driver)

LOG.info("Access information updated successfully.")
return access_info
Expand Down Expand Up @@ -97,7 +95,10 @@ def remove_trap_config(self, context, storage_id, trap_config):

def parse_alert(self, context, storage_id, alert):
"""Parse alert data got from snmp trap server."""
driver = self.driver_manager.get_driver(context, storage_id=storage_id)
access_info = db.access_info_get(context, storage_id)
driver = self.driver_manager.get_driver(context,
invoke_on_load=False,
**access_info)
return driver.parse_alert(context, alert)

def clear_alert(self, context, storage_id, sequence_number):
Expand Down
Empty file.
135 changes: 135 additions & 0 deletions delfin/drivers/dell_emc/unity/alert_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Copyright 2020 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 time

import six
from oslo_log import log

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

LOG = log.getLogger(__name__)


class AlertHandler(object):

TIME_PATTERN = "%Y-%m-%dT%H:%M:%S.%fZ"

OID_SEVERITY = '1.3.6.1.6.3.1.1.4.1.0'
OID_NODE = '1.3.6.1.4.1.1139.103.1.18.1.1'
OID_COMPONENT = '1.3.6.1.4.1.1139.103.1.18.1.2'
OID_SYMPTOMID = '1.3.6.1.4.1.1139.103.1.18.1.3'
OID_SYMPTOMTEXT = '1.3.6.1.4.1.1139.103.1.18.1.4'
OID_TIMESTAMP = '1.3.6.1.4.1.1139.103.1.18.1.5'

ALERT_LEVEL_MAP = {0: constants.Severity.CRITICAL,
1: constants.Severity.CRITICAL,
2: constants.Severity.CRITICAL,
3: constants.Severity.MAJOR,
4: constants.Severity.WARNING,
5: constants.Severity.FATAL,
6: constants.Severity.INFORMATIONAL,
7: constants.Severity.NOT_SPECIFIED
}

TRAP_LEVEL_MAP = {'1.3.6.1.4.1.1139.103.1.18.2.0':
constants.Severity.CRITICAL,
'1.3.6.1.4.1.1139.103.1.18.2.1':
constants.Severity.CRITICAL,
'1.3.6.1.4.1.1139.103.1.18.2.2':
constants.Severity.CRITICAL,
'1.3.6.1.4.1.1139.103.1.18.2.3':
constants.Severity.MAJOR,
'1.3.6.1.4.1.1139.103.1.18.2.4':
constants.Severity.WARNING,
'1.3.6.1.4.1.1139.103.1.18.2.5':
constants.Severity.FATAL,
'1.3.6.1.4.1.1139.103.1.18.2.6':
constants.Severity.INFORMATIONAL,
'1.3.6.1.4.1.1139.103.1.18.2.7':
constants.Severity.NOT_SPECIFIED
}
SECONDS_TO_MS = 1000

@staticmethod
def parse_alert(context, alert):
try:
alert_model = dict()
alert_model['alert_id'] = alert.get(AlertHandler.OID_SYMPTOMID)
alert_model['alert_name'] = alert.get(AlertHandler.OID_COMPONENT)
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'] = alert.get(
AlertHandler.OID_SYMPTOMTEXT)
alert_model['resource_type'] = constants.DEFAULT_RESOURCE_TYPE
alert_model['location'] = alert.get(AlertHandler.OID_NODE)

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)

def parse_queried_alerts(self, alert_model_list, alert_list, query_para):
alerts = alert_list.get('entries')
for alert in alerts:
try:
occur_time = int(time.mktime(time.strptime(
alert.get('content').get('timestamp'),
self.TIME_PATTERN)))
if not alert_util.is_alert_in_time_range(
query_para, int(occur_time *
AlertHandler.SECONDS_TO_MS)):
continue

alert_model = {}
location = ''
resource_type = constants.DEFAULT_RESOURCE_TYPE
if 'component' in alert:
resource_type = alert.get(
'content').get('component').get('resource')
location = alert.get(
'content').get('component').get('id')

alert_model['alert_id'] = alert.get(
'content').get('messageId')
alert_model['alert_name'] = alert.get(
'content').get('message')
alert_model['severity'] = self.ALERT_LEVEL_MAP.get(
alert.get('content').get('severity'),
constants.Severity.INFORMATIONAL)
alert_model['category'] = constants.Category.FAULT
alert_model['type'] = constants.EventType.EQUIPMENT_ALARM
alert_model['sequence_number'] = alert.get('content').get('id')
alert_model['occur_time'] = int(occur_time *
AlertHandler.SECONDS_TO_MS)
alert_model['description'] = alert.get('content').get(
'description')
alert_model['resource_type'] = resource_type
alert_model['location'] = location

alert_model_list.append(alert_model)
except Exception as e:
LOG.error(e)
err_msg = "Failed to build alert model as some attributes " \
"missing in queried alerts: %s" % (six.text_type(e))
raise exception.InvalidResults(err_msg)
18 changes: 18 additions & 0 deletions delfin/drivers/dell_emc/unity/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2020 The SODA Authors.
# All Rights Reserved.
#
# 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
ERROR_SESSION_INVALID_CODE = 403
ERROR_SESSION_IS_BEING_USED_CODE = 409
HEALTH_OK = (5, 7)
Loading