Add snmp_parsing service
Parsing part and devstack deploy part will be added later, with unit tests and tempest tests. Implements: blueprint snmp-support Change-Id: I4c3afd735a8301c215cfc50f970ecde6b2a04c6e Signed-off-by: xupeipei <xu.peipei1@zte.com.cn>
This commit is contained in:
parent
c044180f00
commit
90778cf903
@ -32,6 +32,7 @@ console_scripts =
|
|||||||
vitrage-persistor = vitrage.cli.persistor:main
|
vitrage-persistor = vitrage.cli.persistor:main
|
||||||
vitrage-ml = vitrage.cli.machine_learning:main
|
vitrage-ml = vitrage.cli.machine_learning:main
|
||||||
vitrage-dbsync = vitrage.cli.storage:dbsync
|
vitrage-dbsync = vitrage.cli.storage:dbsync
|
||||||
|
vitrage-snmp-parsing = vitrage.cli.snmp_parsing:main
|
||||||
|
|
||||||
vitrage.entity_graph =
|
vitrage.entity_graph =
|
||||||
networkx = vitrage.graph.driver.networkx_graph:NXGraph
|
networkx = vitrage.graph.driver.networkx_graph:NXGraph
|
||||||
|
32
vitrage/cli/snmp_parsing.py
Normal file
32
vitrage/cli/snmp_parsing.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Copyright 2017 - ZTE
|
||||||
|
#
|
||||||
|
# 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 sys
|
||||||
|
|
||||||
|
from oslo_service import service as os_service
|
||||||
|
from vitrage.cli import VITRAGE_TITLE
|
||||||
|
from vitrage import service
|
||||||
|
from vitrage.snmp_parsing.service import SnmpParsingService
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(VITRAGE_TITLE)
|
||||||
|
conf = service.prepare_service()
|
||||||
|
launcher = os_service.ServiceLauncher(conf)
|
||||||
|
launcher.launch_service(SnmpParsingService(conf))
|
||||||
|
launcher.wait()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
@ -30,6 +30,7 @@ import vitrage.notifier.plugins.snmp
|
|||||||
import vitrage.os_clients
|
import vitrage.os_clients
|
||||||
import vitrage.persistor
|
import vitrage.persistor
|
||||||
import vitrage.rpc
|
import vitrage.rpc
|
||||||
|
import vitrage.snmp_parsing
|
||||||
import vitrage.storage
|
import vitrage.storage
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
@ -55,6 +56,7 @@ def list_opts():
|
|||||||
('jaccard_correlation',
|
('jaccard_correlation',
|
||||||
vitrage.machine_learning.plugins.jaccard_correlation.OPTS),
|
vitrage.machine_learning.plugins.jaccard_correlation.OPTS),
|
||||||
('snmp', vitrage.notifier.plugins.snmp.OPTS),
|
('snmp', vitrage.notifier.plugins.snmp.OPTS),
|
||||||
|
('snmp_parsing', vitrage.snmp_parsing.OPTS),
|
||||||
('DEFAULT', itertools.chain(
|
('DEFAULT', itertools.chain(
|
||||||
vitrage.os_clients.OPTS,
|
vitrage.os_clients.OPTS,
|
||||||
vitrage.rpc.OPTS,
|
vitrage.rpc.OPTS,
|
||||||
|
24
vitrage/snmp_parsing/__init__.py
Normal file
24
vitrage/snmp_parsing/__init__.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Copyright 2017 - ZTE
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
OPTS = [
|
||||||
|
cfg.IntOpt('snmp_listening_port',
|
||||||
|
default=8162,
|
||||||
|
help='The listening port of snmp_parsing service'),
|
||||||
|
cfg.StrOpt('oid_mapping',
|
||||||
|
default='/etc/vitrage/snmp_parsing_conf.yaml',
|
||||||
|
help='The default path of oid_mapping yaml file'),
|
||||||
|
]
|
72
vitrage/snmp_parsing/service.py
Normal file
72
vitrage/snmp_parsing/service.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
# Copyright 2017 - ZTE
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from pysnmp.carrier.asyncore.dgram import udp
|
||||||
|
from pysnmp.carrier.asyncore.dgram import udp6
|
||||||
|
from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher
|
||||||
|
|
||||||
|
from oslo_log import log
|
||||||
|
from oslo_service import service as os_service
|
||||||
|
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class SnmpParsingService(os_service.Service):
|
||||||
|
RUN_FORVER = 1
|
||||||
|
|
||||||
|
def __init__(self, conf):
|
||||||
|
super(SnmpParsingService, self).__init__()
|
||||||
|
self.conf = conf
|
||||||
|
self.listening_port = conf.snmp_parsing.snmp_listening_port
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
LOG.info("Vitrage SNMP Parsing Service - Starting...")
|
||||||
|
super(SnmpParsingService, self).start()
|
||||||
|
|
||||||
|
transport_dispatcher = AsyncoreDispatcher()
|
||||||
|
transport_dispatcher.registerRecvCbFun(self.callback_func)
|
||||||
|
|
||||||
|
trans_udp = udp.UdpSocketTransport()
|
||||||
|
udp_transport = \
|
||||||
|
trans_udp.openServerMode(('0.0.0.0', self.listening_port))
|
||||||
|
|
||||||
|
trans_udp6 = udp6.Udp6SocketTransport()
|
||||||
|
udp6_transport = \
|
||||||
|
trans_udp6.openServerMode(('::1', self.listening_port))
|
||||||
|
|
||||||
|
transport_dispatcher.registerTransport(udp.domainName, udp_transport)
|
||||||
|
transport_dispatcher.registerTransport(udp6.domainName, udp6_transport)
|
||||||
|
LOG.info("Vitrage SNMP Parsing Service - Started!")
|
||||||
|
|
||||||
|
transport_dispatcher.jobStarted(self.RUN_FORVER)
|
||||||
|
try:
|
||||||
|
transport_dispatcher.runDispatcher()
|
||||||
|
except Exception:
|
||||||
|
LOG.error("Run transport dispatcher failed.")
|
||||||
|
transport_dispatcher.closeDispatcher()
|
||||||
|
raise
|
||||||
|
|
||||||
|
def stop(self, graceful=False):
|
||||||
|
LOG.info("Vitrage SNMP Parsing Service - Stopping...")
|
||||||
|
|
||||||
|
super(SnmpParsingService, self).stop(graceful)
|
||||||
|
|
||||||
|
LOG.info("Vitrage SNMP Parsing Service - Stopped!")
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
|
def callback_func(self, transport_dispatcher, transport_domain,
|
||||||
|
transport_address, whole_msg):
|
||||||
|
# TODO(peipei): need to parse wholeMsg and send to message queue
|
||||||
|
pass
|
Loading…
Reference in New Issue
Block a user