403Webshell
Server IP : 198.38.94.13  /  Your IP : 216.73.217.33
Web Server : Apache
System : Linux d4744.dxb1.stableserver.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : revivere ( 1140)
PHP Version : 8.2.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /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

Youez - 2016 - github.com/yon3zu
LinuXploit