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

Alert manager addition to dolphin framework #8

Merged

Conversation

sushanthakumar
Copy link
Collaborator

What this PR does / why we need it:
This PR is to add alert manager skeleton to dolphin framework

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:
Test report

Trap receiver is up and listening
V2 and V3 traps are received and processed
image

Release note:

# Load all the mibs
self._mib_builder(LOAD_MIB_MODULE)

self._configure_snmp_userpara()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user opts v1/V2 traps ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently one community (V1/V2) and usm user(v3) are internally configured, this will be replaced once config code is added

return

def start_trap_receiver(self):
snmpEngine = engine.SnmpEngine()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

engine is the the device who send trap , right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

engine is like a server context at receiver side, everything is attached to this engine



config.addV3User(
self.snmpEngine, userName=constants.SNMP_USM_USER,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This user info is the USM user info hat is going to be sending the trap.? How do we achieve hetrogenioty here? Do we start one trap reciever instance for each device registered?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the usm user,there is remote engine id which is unique for device. For v2, there is a way to configure comunity string along with device ip. Will update code for V2 part

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is, is config.addV3User is to add a backend device SNMP user info? if so how do we map different device user info ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.addV3User is to add snmp user info to snmp engine(not to backened). Here prerequisite is snmp user info at device side is configured. remote engine id field uniquely identifies the device which sends V3 trap. so snmp engine can differentiate between various devices and their corresponding user configurations

@sushanthakumar sushanthakumar changed the title [WIP] Alert manager addition to dolphin framework Alert manager addition to dolphin framework Apr 20, 2020
@sushanthakumar sushanthakumar force-pushed the alert-manager-addition branch from 238fde5 to 7f2c38e Compare April 20, 2020 19:16
@@ -0,0 +1,31 @@
# Copyright 2018 The OpenSDS Authors.
#
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2020 The SODA Authors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any part of the code which is taken from some other place? If yes, then maybe it's not a good idea to change the copyright..We need to be careful here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright updated. Does not contain copied code

@@ -0,0 +1,132 @@
# Copyright 2018 The OpenSDS Authors.
#
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

class TrapReceiver(object):

"""Trap receiver functions"""
def __init__(self, mibViewController=None, snmpEngine=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz follow python code style

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

# Callback function to process the incoming trap
def _cbFun(self, stateReference, contextEngineId, contextName,
varBinds, cbCtx):
LOG.info("####################### NEW Notification #######################")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change info to debug, or remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

# Add transport info(ip, port) and start the listener
self._add_transport()

snmpEngine.transportDispatcher.jobStarted(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's is 1 here? or it can be configure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


def start(self):
"""Trigger trap receiver creation"""
self.manager.start_trap_receiver()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/start_trap_receiver()/start()/g

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

SNMP_ENGINE_ID="800000d30300000e112245"

# Temporary mib lod dir. This mechanism to be changed later
MIB_DIR_PATH = '/usr/local/lib/python3.6/dist-packages/pysnmp/smi/mibs'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following 4 parameters should be configurable in your PR.

# Default values for trap receiver ip address and port
DEF_TRAP_RECV_ADDR = "0.0.0.0"
DEF_TRAP_RECV_PORT = 162
TRAP_RECEIVER_CLASS = "dolphin.alert_manager.trap_receiver.TrapReceiver"
MIB_DIR_PATH = '/usr/local/lib/python3.6/dist-packages/pysnmp/smi/mibs'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -0,0 +1,31 @@
# Copyright 2018 The OpenSDS Authors.
#
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any part of the code which is taken from some other place? If yes, then maybe it's not a good idea to change the copyright..We need to be careful here

# limitations under the License.


# Default values for trap receiver ip address and port
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are different groups of constants, it's better to make them class constants. For example, all MIB constants in class MIB and all Trap constants in class Trap. Advantage is the code readability and flow.
access them like MIB.MIB_DIR_PATH

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not moved to class currently

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason?

TRAP_RECEIVER_CLASS = "dolphin.alert_manager.trap_receiver.TrapReceiver"

# Temporary snmp community and user configurations
SNMP_COMMUNITY_STR="public"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One optimisation, if it's constant then better to use single quotes rather than double quotes. This will avoid interpolation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

try:
self.mibViewController = view.MibViewController(mibBuilder)

mib_list = MIB_LOAD_LIST
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this extra copying required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

if (len(mib_list) > 0):
mibBuilder.loadModules_new(*mib_list)

except error.MibNotFoundError as excep:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to log the excep.error()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


# Stops the snmp trap receiver
def stop_trap_receiver(self):
if self.snmpEngine:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception handling required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed as it is shutdown flow

LOG.info("Trap Listener started .....")
snmpEngine.transportDispatcher.runDispatcher()
except:
snmpEngine.transportDispatcher.closeDispatcher()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error log that cannot start

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -63,6 +65,12 @@
default=False,
help='Wraps the socket in a SSL context if True is set. '
'A certificate file and key file must be specified.'),
cfg.HostAddressOpt('trap_receiver_addr',
default="0.0.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are already defined as constants then why hard code as "0.0.0.0" and "162" here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

self.manager = manager_class()

def start(self):
"""Trigger trap receiver creation"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these comments or doc strings? usually doc strings are put under """

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc strings for each functions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


def start(self):
"""Trigger trap receiver creation"""
self.manager.start_trap_receiver()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not catching exception here but had raised it in the function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

SNMP_MIB_PATH = '/usr/local/lib/python3.6/dist-packages/pysnmp/smi/mibs'

# SNMP dispatcher job id (static identifier)
SNMP_DISPATCHER_JOB_ID = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dispatcher job id is static here?


from oslo_log import log

from pysnmp.entity import engine, config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should pysnmp be added to requirements.txt, and what kind of license it used?

mib_builder.setMibSources(*mib_path)
if len(MIB_LOAD_LIST) > 0:
mib_builder.loadModules(*MIB_LOAD_LIST)
except error.MibNotFoundError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this exception need to be throw out to the upper level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, updated

udp.domainName,
udp.UdpTransport().openServerMode((self.trap_receiver_address, int(self.trap_receiver_port)))
)
except Exception:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, updated

Copy link
Collaborator

@wisererik wisererik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add pysnmp==4.4.11 in to requirements.txt

@wisererik wisererik merged commit 246b417 into sodafoundation:master Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants