Skip to content

Commit

Permalink
adds config option to specify ceph.conf and client
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Jul 25, 2023
1 parent bc01569 commit b86be40
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 12 deletions.
16 changes: 15 additions & 1 deletion ceph/agents/plugins/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@ def command_osd(self, osdid, cmd):
def command_pg(self, pgid, cmd):
return self.pg_command(pgid, json.dumps({'prefix': cmd, 'format': 'json'}), b'', timeout=5)

cluster = RadosCMD(conffile='/etc/ceph/ceph.conf')
ceph_config='/etc/ceph/ceph.conf'
ceph_client='client.admin'
try:
with open(os.path.join(os.environ['MK_CONFDIR'], 'ceph.cfg'), 'r') as config:
for line in config.readlines():
if '=' in line:
key, value = line.strip().split('=')
if key == 'CONFIG':
ceph_config = value
if key == 'CLIENT':
ceph_client = value
except FileNotFoundError:
pass

cluster = RadosCMD(conffile=ceph_config, name=ceph_client)
cluster.connect()

hostname = socket.gethostname().split('.', 1)[0]
Expand Down
16 changes: 15 additions & 1 deletion ceph/agents/plugins/ceph_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@ def command_osd(self, osdid, cmd):
def command_pg(self, pgid, cmd):
return self.pg_command(pgid, json.dumps({'prefix': cmd, 'format': 'json'}), b'', timeout=5)

cluster = RadosCMD(conffile='/etc/ceph/ceph.conf')
ceph_config='/etc/ceph/ceph.conf'
ceph_client='client.admin'
try:
with open(os.path.join(os.environ['MK_CONFDIR'], 'ceph.cfg'), 'r') as config:
for line in config.readlines():
if '=' in line:
key, value = line.strip().split('=')
if key == 'CONFIG':
ceph_config = value
if key == 'CLIENT':
ceph_client = value
except FileNotFoundError:
pass

cluster = RadosCMD(conffile=ceph_config, name=ceph_client)
cluster.connect()

hostname = socket.gethostname().split('.', 1)[0]
Expand Down
Binary file removed ceph/ceph-11.19.0.mkp
Binary file not shown.
Binary file added ceph/ceph-11.19.1.mkp
Binary file not shown.
14 changes: 12 additions & 2 deletions ceph/lib/python3/cmk/base/cee/plugins/bakery/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@
from pathlib import Path
from typing import Any, Dict

from .bakery_api.v1 import FileGenerator, OS, Plugin, register
from .bakery_api.v1 import FileGenerator, OS, Plugin, PluginConfig, register

def get_ceph_files(conf: Dict[str, Any]) -> FileGenerator:
yield Plugin(base_os=OS.LINUX,
source=Path("ceph.py"),
interval=58)
interval=conf['interval'])
config_lines = []
if 'config' in conf:
config_lines.append('CONFIG=%s' % conf['config'])
if 'client' in conf:
config_lines.append('CLIENT=%s' % conf['client'])
if config_lines:
yield PluginConfig(base_os=OS.LINUX,
lines=config_lines,
target=Path("ceph.cfg"),
include_header=True)

register.bakery_plugin(
name="ceph",
Expand Down
52 changes: 44 additions & 8 deletions ceph/web/plugins/wato/ceph_cee.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,53 @@
)
from cmk.gui.cee.plugins.wato.agent_bakery.rulespecs.utils import RulespecGroupMonitoringAgentsAgentPlugins
from cmk.gui.valuespec import (
DropdownChoice,
Alternative,
Dictionary,
Filename,
TextInput,
Transform,
)

def _transform_agent_config_ceph(p):
if isinstance(p, bool):
if p:
return {'interval': 58}
return None
return p

def _valuespec_agent_config_ceph():
return DropdownChoice(
title = _("Ceph Status (Linux)"),
help = _("This will deploy the agent plugin <tt>ceph</tt> for monitoring the status of Ceph. This plugin will be run asynchronously in the background."),
choices = [
( True, _("Deploy plugin for Ceph") ),
( None, _("Do not deploy plugin for Ceph") ),
]
return Transform(
Alternative(
title = _("Ceph Status (Linux)"),
help = _("This will deploy the agent plugin <tt>ceph</tt> for monitoring the status of Ceph. This plugin will be run asynchronously in the background."),
style = "dropdown",
elements = [
Dictionary(
title = _("Deploy plugin for Ceph"),
elements = [
( "interval",
Age(
title = _("Run asynchronously"),
label = _("Interval for collecting data from Ceph"),
default_value = 58,
)),
( "config",
Filename(
title = _("Path to ceph.conf"),
default_value = "/etc/ceph/ceph.conf",
)),
( "client",
TextInput(
title = _("Client name"),
default_value = "client.admin",
)),
],
optional_keys = ['config', 'client'],
),
FixedValue( None, title = _("Do not deploy plugin for Ceph"), totext = _('(disabled)') ),
],
),
forth=_transform_agent_config_ceph,
)

rulespec_registry.register(
Expand Down

0 comments on commit b86be40

Please sign in to comment.