From e1cca1309806497a84340c7a9087cb54b96d05c5 Mon Sep 17 00:00:00 2001 From: Fabien Archambault Date: Mon, 29 Jul 2024 16:35:45 +0200 Subject: [PATCH] Patch to manage issue #66. This adds the option ssh_user in the configuration file. --- conf/samples/example.yaml | 11 +++++++++++ lib/MilkCheck/Engine/Action.py | 3 +++ lib/MilkCheck/Engine/BaseEntity.py | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/conf/samples/example.yaml b/conf/samples/example.yaml index 89e4708..5c72257 100644 --- a/conf/samples/example.yaml +++ b/conf/samples/example.yaml @@ -351,3 +351,14 @@ services: on_gateway: remote: False cmd: /bin/gw_action + # + # Run a command with a non logged in user + # + # The SSH command will be executed with a specific user + # + non-logged-in-user: + desc: Connect via a non logged in user + ssh_user: "admin" + actions: + status: + cmd: id diff --git a/lib/MilkCheck/Engine/Action.py b/lib/MilkCheck/Engine/Action.py index 68d180a..2c4ceb1 100755 --- a/lib/MilkCheck/Engine/Action.py +++ b/lib/MilkCheck/Engine/Action.py @@ -94,6 +94,9 @@ def perform_action(self, action): if not self.dryrun: command = action.command + if action.ssh_user: + self._master_task.set_info("ssh_user", action.ssh_user) + if action.mode == 'exec': wkr = ExecWorker(nodes=nodes, handler=ActionEventHandler(action), timeout=action.timeout, command=command, diff --git a/lib/MilkCheck/Engine/BaseEntity.py b/lib/MilkCheck/Engine/BaseEntity.py index 7d64250..f15e130 100755 --- a/lib/MilkCheck/Engine/BaseEntity.py +++ b/lib/MilkCheck/Engine/BaseEntity.py @@ -299,6 +299,9 @@ def __init__(self, name, target=None, delay=0): # Tags the entity. The tags set define if the entity should run self.tags = set() + # ssh_user + self.ssh_user = None + def filter_nodes(self, nodes): """ Add error nodes to skip list. @@ -731,6 +734,7 @@ def inherits_from(self, entity): self.delay = self.delay or entity.delay self.maxretry = self.maxretry or entity.maxretry self.tags = self.tags or entity.tags + self.ssh_user = self.ssh_user or entity.ssh_user def fromdict(self, entdict): """Populate entity attributes from dict.""" @@ -758,6 +762,8 @@ def fromdict(self, entdict): self.desc = prop elif item == 'tags': self.tags = set(prop) + elif item == 'ssh_user': + self.ssh_user = prop elif item == 'variables': for varname, value in prop.items(): self.add_var(varname, value)