Skip to content

Commit

Permalink
pybind/mgr/alerts: flake8 cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Feb 7, 2021
1 parent af3f49d commit 51ee392
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/pybind/mgr/alerts/module.py
Expand Up @@ -127,8 +127,8 @@ def _diff(self, last: Dict[str, Any], new: Dict[str, Any]) -> Dict[str, Any]:
if 'new' not in d:
d['new'] = {}
d['new'][code] = alert
elif alert['summary'].get('count', 0) > \
last['checks'][code]['summary'].get('count', 0):
elif (alert['summary'].get('count', 0) >
last['checks'][code]['summary'].get('count', 0)):
if 'updated' not in d:
d['updated'] = {}
d['updated'][code] = alert
Expand Down Expand Up @@ -172,7 +172,7 @@ def serve(self) -> None:
last_status = new_status

self.log.debug('Sleeping for %s seconds', self.interval)
ret = self.event.wait(self.interval or 60)
self.event.wait(self.interval or 60)
self.event.clear()

def shutdown(self) -> None:
Expand All @@ -195,7 +195,9 @@ def _smtp_format_alert(self, code: str, alert: Dict[str, Any]) -> str:
message=detail['message'])
return r

def _send_alert_smtp(self, status: Dict[str, Any], diff: Dict[str, Any]) -> Optional[Dict[str, Any]]:
def _send_alert_smtp(self,
status: Dict[str, Any],
diff: Dict[str, Any]) -> Optional[Dict[str, Any]]:
# message
self.log.debug('_send_alert_smtp')
message = ('From: {from_name} <{sender}>\n'
Expand Down Expand Up @@ -224,13 +226,14 @@ def _send_alert_smtp(self, status: Dict[str, Any], diff: Dict[str, Any]) -> Opti
message += ('\n\n=== Full health status ===\n')
for code, alert in status['checks'].items():
message += self._smtp_format_alert(code, alert)

self.log.debug('message: %s' % message)

# send
try:
if self.smtp_ssl:
server: Union[smtplib.SMTP_SSL, smtplib.SMTP] = smtplib.SMTP_SSL(self.smtp_host, self.smtp_port)
server: Union[smtplib.SMTP_SSL, smtplib.SMTP] = \
smtplib.SMTP_SSL(self.smtp_host, self.smtp_port)
else:
server = smtplib.SMTP(self.smtp_host, self.smtp_port)
if self.smtp_password:
Expand All @@ -243,7 +246,7 @@ def _send_alert_smtp(self, status: Dict[str, Any], diff: Dict[str, Any]) -> Opti
'severity': 'warning',
'summary': 'unable to send alert email',
'count': 1,
'detail': [ str(e) ]
'detail': [str(e)]
}
}
self.log.debug('Sent email to %s' % self.smtp_destination)
Expand Down
1 change: 1 addition & 0 deletions src/pybind/mgr/tox.ini
Expand Up @@ -89,6 +89,7 @@ basepython = python3
deps =
autopep8
modules =
alerts
cephadm
crash
devicehealth
Expand Down

0 comments on commit 51ee392

Please sign in to comment.