Merge "Add snmp_parsing service"

This commit is contained in:
Zuul 2017-12-17 14:59:59 +00:00 committed by Gerrit Code Review
commit 18d9f12195
5 changed files with 131 additions and 0 deletions

View File

@ -32,6 +32,7 @@ console_scripts =
vitrage-persistor = vitrage.cli.persistor:main
vitrage-ml = vitrage.cli.machine_learning:main
vitrage-dbsync = vitrage.cli.storage:dbsync
vitrage-snmp-parsing = vitrage.cli.snmp_parsing:main
vitrage.entity_graph =
networkx = vitrage.graph.driver.networkx_graph:NXGraph

View 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())

View File

@ -30,6 +30,7 @@ import vitrage.notifier.plugins.snmp
import vitrage.os_clients
import vitrage.persistor
import vitrage.rpc
import vitrage.snmp_parsing
import vitrage.storage
LOG = log.getLogger(__name__)
@ -55,6 +56,7 @@ def list_opts():
('jaccard_correlation',
vitrage.machine_learning.plugins.jaccard_correlation.OPTS),
('snmp', vitrage.notifier.plugins.snmp.OPTS),
('snmp_parsing', vitrage.snmp_parsing.OPTS),
('DEFAULT', itertools.chain(
vitrage.os_clients.OPTS,
vitrage.rpc.OPTS,

View 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'),
]

View 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