From db39aba626c566d64fdd090f0e84031b62a0a058 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 31 Jan 2021 17:48:31 +0800 Subject: [PATCH] pybind/mgr/alerts: use CLIReadCommand to define commands Signed-off-by: Kefu Chai --- src/pybind/mgr/alerts/module.py | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/pybind/mgr/alerts/module.py b/src/pybind/mgr/alerts/module.py index d30b2537dcf5..9804ba187e78 100644 --- a/src/pybind/mgr/alerts/module.py +++ b/src/pybind/mgr/alerts/module.py @@ -3,21 +3,13 @@ A simple cluster health alerting module. """ -from mgr_module import MgrModule, HandleCommandResult +from mgr_module import CLIReadCommand, MgrModule, HandleCommandResult from threading import Event from typing import Any, Optional, Dict, List, TYPE_CHECKING, Union import json import smtplib class Alerts(MgrModule): - COMMANDS = [ - { - "cmd": "alerts send", - "desc": "(re)send alerts immediately", - "perm": "r" - }, - ] - # ´# type: ignore` due to the introduction of the Option type. MODULE_OPTIONS: List[Dict[str, Any]] = [ # type: ignore { @@ -127,17 +119,14 @@ class Alerts(MgrModule): self.get_ceph_option(opt)) self.log.debug(' native option %s = %s', opt, getattr(self, opt)) - def handle_command(self, inbuf: Optional[str], cmd: Dict[str, Any]) -> HandleCommandResult: - ret = 0 - out = '' - err = '' - if cmd['prefix'] == 'alerts send': - status = json.loads(self.get('health')['json']) - self._send_alert(status, {}) - return HandleCommandResult( - retval=ret, # exit code - stdout=out, # stdout - stderr=err) + @CLIReadCommand('alerts send') + def send(self) -> HandleCommandResult: + """ + (re)send alerts immediately + """ + status = json.loads(self.get('health')['json']) + self._send_alert(status, {}) + return HandleCommandResult() def _diff(self, last: Dict[str, Any], new: Dict[str, Any]) -> Dict[str, Any]: d: Dict[str, Any] = {} -- 2.47.3