Skip to content

Commit 269ae9d

Browse files
committed
fix: nil-check start_time element in _set_recheck (#1174)
Return a clear Result error when the start_time element is missing (insufficient role permissions) instead of crashing with AttributeError on NoneType.attrs. Signed-off-by: SAY-5 <say.apm35@gmail.com>
1 parent 99f152f commit 269ae9d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Nagstamon/servers/Generic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,12 @@ def _set_recheck(self, host, service):
449449
# get start time from Nagios as HTML to use same timezone setting like the locally installed Nagios
450450
result = self.fetch_url(
451451
self.monitor_cgi_url + '/cmd.cgi?' + urllib.parse.urlencode({'cmd_typ': '96', 'host': host}))
452-
self.start_time = dict(result.result.find(attrs={'name': 'start_time'}).attrs)['value']
452+
start_time_element = result.result.find(attrs={'name': 'start_time'})
453+
if start_time_element is None:
454+
# element missing usually means the user lacks permission to schedule rechecks
455+
return Result(result='Recheck not permitted: missing start_time element (insufficient role permissions?)',
456+
error='start_time element not found')
457+
self.start_time = dict(start_time_element.attrs)['value']
453458
# decision about host or service - they have different URLs
454459
if service == '':
455460
# host

0 commit comments

Comments
 (0)