fix bug undefined dest for snmp traps

Change-Id: I6983fc4ded11cc75fe62a36e9d043b521ebfdd4a
This commit is contained in:
Anna Reznikov 2017-05-11 15:05:36 +00:00
parent 391967f1be
commit 3c8b5e186c

View File

@ -21,6 +21,7 @@ from pysnmp.hlapi.context import ContextData
from pysnmp.proto.rfc1902 import OctetString
from pysnmp.smi.rfc1902 import NotificationType
from pysnmp.smi.rfc1902 import ObjectIdentity
import re
from vitrage.common.constants import VertexProperties as VProps
from vitrage.notifier.plugins.snmp.base import SnmpSenderBase
@ -37,6 +38,8 @@ NEXT = 'next'
WITH_VALS = 'with_values'
SEVERITY = 'SEVERITY'
ALARM_OID = 'ALARM_OID'
IP_PAT = re.compile('\d+\.\d+\.\d+\.\d+')
PORT_PAT = re.compile('\d+')
class SnmpSender(SnmpSenderBase):
@ -165,10 +168,15 @@ class SnmpSender(SnmpSenderBase):
host_details = host['host']
send_to = str(host_details['send_to'])
send_to = str(host_details.get('send_to'))
port = str(host_details.get('port', 162))
community_str = host_details.get('community', 'public')
if not (send_to and IP_PAT.match(send_to) and PORT_PAT.match(port)):
LOG.info("Vitrage snmp Info: an SNMP target host was not"
" configured correctly")
return
LOG.debug("Vitrage snmp Debug: Trap parameters: send_to: %s, "
"port: %s, community string: %s" %
(send_to, port, community_str))