PK œqhYî¶J‚ßF ßF ) nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/
Dir : /proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/ |
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 IP: 209.182.202.254 |
Dir : //proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/munin.py |
""" Run munin plugins/checks from salt and format the output as data. """ import os import stat import salt.utils.files import salt.utils.stringutils PLUGINDIR = "/etc/munin/plugins/" def __virtual__(): """ Only load the module if munin-node is installed """ if os.path.exists("/etc/munin/munin-node.conf"): return "munin" return ( False, "The munin execution module cannot be loaded: munin-node is not installed.", ) def _get_conf(fname="/etc/munin/munin-node.cfg"): with salt.utils.files.fopen(fname, "r") as fp_: return salt.utils.stringutils.to_unicode(fp_.read()) def run(plugins): """ Run one or more named munin plugins CLI Example: .. code-block:: bash salt '*' munin.run uptime salt '*' munin.run uptime,cpu,load,memory """ all_plugins = list_plugins() if isinstance(plugins, str): plugins = plugins.split(",") data = {} for plugin in plugins: if plugin not in all_plugins: continue data[plugin] = {} muninout = __salt__["cmd.run"](f"munin-run {plugin}", python_shell=False) for line in muninout.split("\n"): if "value" in line: # This skips multigraph lines, etc key, val = line.split(" ") key = key.split(".")[0] try: # We only want numbers if "." in val: val = float(val) else: val = int(val) data[plugin][key] = val except ValueError: pass return data def run_all(): """ Run all the munin plugins CLI Example: .. code-block:: bash salt '*' munin.run_all """ plugins = list_plugins() ret = {} for plugin in plugins: ret.update(run(plugin)) return ret def list_plugins(): """ List all the munin plugins CLI Example: .. code-block:: bash salt '*' munin.list_plugins """ pluginlist = os.listdir(PLUGINDIR) ret = [] for plugin in pluginlist: # Check if execute bit statf = os.path.join(PLUGINDIR, plugin) try: executebit = stat.S_IXUSR & os.stat(statf)[stat.ST_MODE] except OSError: pass if executebit: ret.append(plugin) return ret