Skip to content

Commit

Permalink
Restrict events
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Apr 24, 2024
1 parent c274b22 commit 61243ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/check/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from urllib.parse import quote


MAX_ITEMS = 2000
IGNORE_KEYS = (
'EVT_WU_Connected',
'EVT_WU_Disconnected',
Expand All @@ -27,13 +28,21 @@ async def check_event(
resp.raise_for_status()
data = await resp.json()

# Each event is translated to an item. InfraSonar does not support more
# than 2000 items per type, therefore we need to truncate the result
# and only return the newest events. This only happens on relatively
# large sites with many events.
data = list(data['data'])
data.sort(key=lambda i: i.get('time') or 0)
data = data[-MAX_ITEMS:]

event = [{
'name': d['_id'],
'key': d['key'],
'msg': d.get('msg'),
'subsystem': d.get('subsystem'),
'time': int(d.get('time') / 1000) if d.get('time') else None,
} for d in data['data'] if d['key'] not in IGNORE_KEYS]
'time': int(d['time'] / 1000) if d.get('time') else None,
} for d in data if d['key'] not in IGNORE_KEYS]
return {
'event': event
}
2 changes: 1 addition & 1 deletion lib/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version string. Examples:
# '3.0.0'
# '3.0.0-alpha9'
__version__ = '3.0.1'
__version__ = '3.0.2-alpha0'
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
aiohttp==3.9.3
aiohttp==3.9.5
libprobe==0.2.36

0 comments on commit 61243ea

Please sign in to comment.