Skip to content

Commit

Permalink
Defer creating the event client and queue.
Browse files Browse the repository at this point in the history
The event queue initializer looks up event transformers too early so
defer creating the queue until after connecting to ZenHub.

ZEN-35073
  • Loading branch information
jpeacock-zenoss committed Sep 27, 2024
1 parent f1cc3e0 commit 08a03e7
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 210 deletions.
3 changes: 1 addition & 2 deletions Products/ZenEvents/zentrap/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TrapDaemon(PBDaemon):
def __init__(self, *args, **kwargs):
super(TrapDaemon, self).__init__(*args, **kwargs)

self.configCycleInterval = 20 * 60 # seconds
self.configCycleInterval = 2 * 60 # seconds
self.cycleInterval = 5 * 60 # seconds

self.__lastCounterEventTime = time.time()
Expand Down Expand Up @@ -233,7 +233,6 @@ def _start_receiver(self):
reactor.addSystemEventTrigger(
"before", "shutdown", self._receiver.stop
)

reactor.addSystemEventTrigger(
"after", "shutdown", self._displayStatistics
)
Expand Down
34 changes: 18 additions & 16 deletions Products/ZenEvents/zentrap/filterspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update_from_string(self, trapFilters, reset=True):
self._filtersDefined = 0 != numFiltersDefined
if self._filtersDefined:
log.debug(
"Finished reading filter configuration. Lines parsed:%s, "
"finished reading filter configuration. Lines parsed:%s, "
"Filters defined:%s [v1Traps:%d, v1Filters:%d, "
"v2Filters:%d]",
lineNumber,
Expand All @@ -110,13 +110,13 @@ def update_from_string(self, trapFilters, reset=True):
len(self._v2Filters),
)
else:
log.warn("No zentrap filters defined.")
log.warn("no zentrap filters defined.")
return events

def _reset(self):
self._v1Traps = {}
self._v1Filters = {}
self._v2Filters = {}
self._v1Traps.clear()
self._v1Filters.clear()
self._v2Filters.clear()
self._filtersDefined = False

def _parseFilterDefinition(self, line, lineNumber):
Expand Down Expand Up @@ -165,7 +165,7 @@ def _parseFilterDefinition(self, line, lineNumber):
return None
except Exception:
errorMessage = (
"Could not compile collector expression {!r} on "
"could not compile collector expression {!r} on "
"line {}".format(collectorRegex, lineNumber)
)
log.error(errorMessage)
Expand Down Expand Up @@ -439,13 +439,14 @@ def __init__(
self.genericTrap = genericTrap

def __eq__(self, other):
if isinstance(other, GenericTrapFilterDefinition):
return self.genericTrap == other.genericTrap
else:
return False
if not isinstance(other, GenericTrapFilterDefinition):
return NotImplemented
return self.genericTrap == other.genericTrap

def __ne__(self, other):
return not self.__eq__(other)
if not isinstance(other, GenericTrapFilterDefinition):
return NotImplemented
return self.genericTrap != other.genericTrap

def __hash__(self):
return hash(self.genericTrap)
Expand All @@ -462,13 +463,14 @@ def levels(self):
return countOidLevels(self.oid)

def __eq__(self, other):
if isinstance(other, OIDBasedFilterDefinition):
return self.oid == other.oid
else:
return False
if not isinstance(other, OIDBasedFilterDefinition):
return NotImplemented
return self.oid == other.oid

def __ne__(self, other):
return not self.__eq__(other)
if not isinstance(other, OIDBasedFilterDefinition):
return NotImplemented
return self.oid != other.oid

def __hash__(self):
return hash(self.oid)
Expand Down
7 changes: 3 additions & 4 deletions Products/ZenEvents/zentrap/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ def __call__(self, addr, pdu, starttime):
)

result["zenoss.trap_source_ip"] = addr[0]
community = self.getCommunity(pdu)
self.sendTrapEvent(result, community, eventType, starttime)
log.debug(
"asyncHandleTrap: eventType=%s oid=%s snmpVersion=%s",
"handled trap event-type=%s oid=%s snmp-version=%s",
eventType,
result["oid"],
result["snmpVersion"],
)

community = self.getCommunity(pdu)
self.sendTrapEvent(result, community, eventType, starttime)

def sendTrapEvent(self, result, community, eventType, starttime):
summary = "snmp trap %s" % eventType
log.debug(summary)
Expand Down
2 changes: 1 addition & 1 deletion Products/ZenEvents/zentrap/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
sockaddr_in6,
)

log = logging.getLogger("zen.zentrap.server")
log = logging.getLogger("zen.zentrap.receiver")


class Receiver(object):
Expand Down
Loading

0 comments on commit 08a03e7

Please sign in to comment.