summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/zabbix
diff options
context:
space:
mode:
authorKefu Chai <kchai@redhat.com>2021-01-27 06:43:36 +0100
committerKefu Chai <kchai@redhat.com>2021-01-27 12:22:05 +0100
commit43802146b070e2d5dddc59b32fba549f14afa375 (patch)
treeef3b9072af777029765d1158cb9e5d466bcf4421 /src/pybind/mgr/zabbix
parentmgr/zabbix: do not catch exception with name (diff)
downloadceph-43802146b070e2d5dddc59b32fba549f14afa375.tar.xz
ceph-43802146b070e2d5dddc59b32fba549f14afa375.zip
mgr/zabbix: use CLICommand for command handling
Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/pybind/mgr/zabbix')
-rw-r--r--src/pybind/mgr/zabbix/module.py57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/pybind/mgr/zabbix/module.py b/src/pybind/mgr/zabbix/module.py
index b586de5e7b4..b3b27c78490 100644
--- a/src/pybind/mgr/zabbix/module.py
+++ b/src/pybind/mgr/zabbix/module.py
@@ -10,7 +10,7 @@ import errno
import re
from subprocess import Popen, PIPE
from threading import Event
-from mgr_module import MgrModule, Option, OptionValue
+from mgr_module import CLIReadCommand, CLIWriteCommand, MgrModule, Option, OptionValue
from typing import cast, Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union
@@ -403,41 +403,38 @@ class Module(MgrModule):
}
return bool(self.send(data))
- def handle_command(self, inbuf: str, command: Dict[str, Any]) -> Tuple[int, str, str]:
- if command['prefix'] == 'zabbix config-show':
- return 0, json.dumps(self.config, indent=4, sort_keys=True), ''
- elif command['prefix'] == 'zabbix config-set':
- key = command['key']
- value = command['value']
- if not value:
- return -errno.EINVAL, '', 'Value should not be empty or None'
-
- self.log.debug('Setting configuration option %s to %s', key, value)
- if self.set_config_option(key, value):
- self.set_module_option(key, value)
- if key == 'zabbix_host' or key == 'zabbix_port':
- self._parse_zabbix_hosts()
- return 0, 'Configuration option {0} updated'.format(key), ''
+ @CLIReadCommand('zabbix config-show')
+ def config_show(self) -> Tuple[int, str, str]:
+ return 0, json.dumps(self.config, indent=4, sort_keys=True), ''
- return 1,\
- 'Failed to update configuration option {0}'.format(key), ''
+ @CLIWriteCommand('zabbix config-set')
+ def config_set(self, key: str, value: str) -> Tuple[int, str, str]:
+ if not value:
+ return -errno.EINVAL, '', 'Value should not be empty or None'
- elif command['prefix'] == 'zabbix send':
- data = self.get_data()
- if self.send(data):
- return 0, 'Sending data to Zabbix', ''
+ self.log.debug('Setting configuration option %s to %s', key, value)
+ if self.set_config_option(key, value):
+ self.set_module_option(key, value)
+ if key == 'zabbix_host' or key == 'zabbix_port':
+ self._parse_zabbix_hosts()
+ return 0, 'Configuration option {0} updated'.format(key), ''
+ return 1,\
+ 'Failed to update configuration option {0}'.format(key), ''
- return 1, 'Failed to send data to Zabbix', ''
+ @CLIReadCommand('zabbix send')
+ def do_send(self) -> Tuple[int, str, str]:
+ data = self.get_data()
+ if self.send(data):
+ return 0, 'Sending data to Zabbix', ''
- elif command['prefix'] == 'zabbix discovery':
- if self.discovery():
- return 0, 'Sending discovery data to Zabbix', ''
+ return 1, 'Failed to send data to Zabbix', ''
- return 1, 'Failed to send discovery data to Zabbix', ''
+ @CLIReadCommand('zabbix discovery')
+ def do_discovery(self) -> Tuple[int, str, str]:
+ if self.discovery():
+ return 0, 'Sending discovery data to Zabbix', ''
- else:
- return (-errno.EINVAL, '',
- "Command not found '{0}'".format(command['prefix']))
+ return 1, 'Failed to send discovery data to Zabbix', ''
def shutdown(self) -> None:
self.log.info('Stopping zabbix')