-
Notifications
You must be signed in to change notification settings - Fork 354
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
Alert manager addition to dolphin framework #8
Conversation
# Load all the mibs | ||
self._mib_builder(LOAD_MIB_MODULE) | ||
|
||
self._configure_snmp_userpara() |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
238fde5
to
7f2c38e
Compare
@@ -0,0 +1,31 @@ | |||
# Copyright 2018 The OpenSDS Authors. | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2020 The SODA Authors.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 #######################") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
dolphin/service.py
Outdated
|
||
def start(self): | ||
"""Trigger trap receiver creation""" | ||
self.manager.start_trap_receiver() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
dolphin/alert_manager/constants.py
Outdated
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' |
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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. | |||
# |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason?
dolphin/alert_manager/constants.py
Outdated
TRAP_RECEIVER_CLASS = "dolphin.alert_manager.trap_receiver.TrapReceiver" | ||
|
||
# Temporary snmp community and user configurations | ||
SNMP_COMMUNITY_STR="public" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception handling required?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
dolphin/service.py
Outdated
@@ -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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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""" |
There was a problem hiding this comment.
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 """
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
dolphin/service.py
Outdated
|
||
def start(self): | ||
"""Trigger trap receiver creation""" | ||
self.manager.start_trap_receiver() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, updated
There was a problem hiding this 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
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
Release note: