-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[collector] Cluster transport for Saltstack
Signed-off-by: Trevor Benson <[email protected]>
- Loading branch information
1 parent
af139c4
commit c459d85
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright Red Hat 2022, Trevor Benson <[email protected]> | ||
|
||
# This file is part of the sos project: https://github.com/sosreport/sos | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# version 2 of the GNU General Public License. | ||
# | ||
# See the LICENSE file in the source distribution for further information. | ||
|
||
import json | ||
from shlex import quote | ||
from sos.collector.clusters import Cluster | ||
|
||
|
||
class saltstack(Cluster): | ||
""" | ||
The saltstack cluster profile is intended to be used on saltstack | ||
clusters (Salt Project). | ||
""" | ||
|
||
cluster_name = "Saltstack" | ||
packages = ("salt-master",) | ||
sos_plugins = ["saltmaster"] | ||
|
||
cmd = "salt" | ||
|
||
strict_node_list = True | ||
|
||
option_list = [ | ||
("compound", "", "Filter node list to those matching compound"), | ||
("glob", "", "Filter node list to those matching glob pattern"), | ||
("grain", "", "Filter node list to those with matching grain"), | ||
("list", "", "Filter node list to those matching list"), | ||
("pillar", "", "Filter node list to those with matching pillar"), | ||
("regex", "", "Filter node list to those matching regex"), | ||
("subnet", "", "Filter node list to those in subnet"), | ||
] | ||
|
||
def get_nodes(self): | ||
if self.get_option("compound"): | ||
self.cmd += f" -C {quote(self.get_option('compound'))} " | ||
elif self.get_option("glob"): | ||
self.cmd += f" {quote(self.get_option('glob'))} " | ||
elif self.get_option("grain"): | ||
self.cmd += f" -G {quote(self.get_option('grain'))} " | ||
elif self.get_option("list"): | ||
self.cmd += f" -L {quote(self.get_option('list'))} " | ||
elif self.get_option("pillar"): | ||
self.cmd += f" -I {quote(self.get_option('pillar'))} " | ||
elif self.get_option("regex"): | ||
self.cmd += f" -E {quote(self.get_option('regex'))} " | ||
elif self.get_option("subnet"): | ||
self.cmd += f" -S {quote(self.get_option('subnet'))} " | ||
else: | ||
self.cmd += " '*'" | ||
self.cmd += " --out=pprint test.ping" | ||
res = self.exec_primary_cmd(self.cmd) | ||
if res["status"] != 0: | ||
raise Exception("Node enumeration did not return usable output") | ||
nodes = [] | ||
for line in res["output"].splitlines(): | ||
ping_test = json.loads( | ||
line.replace("'", '"').replace("True", "true") | ||
) | ||
nodes.extend(key for key, value in ping_test.items() if value) | ||
return nodes | ||
|
||
|
||
# vim: set et ts=4 sw=4 : |