Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option ssh_user in the configuration file #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conf/samples/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions lib/MilkCheck/Engine/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions lib/MilkCheck/Engine/BaseEntity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
Expand Down