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/apcups.py |
""" Module for apcupsd """ import logging import salt.utils.decorators as decorators import salt.utils.path log = logging.getLogger(__name__) # Define the module's virtual name __virtualname__ = "apcups" @decorators.memoize def _check_apcaccess(): """ Looks to see if apcaccess is present on the system """ return salt.utils.path.which("apcaccess") def __virtual__(): """ Provides apcupsd only if apcaccess is present """ if _check_apcaccess(): return __virtualname__ return ( False, "{} module can only be loaded on when apcupsd is installed".format( __virtualname__ ), ) def status(): """ Return apcaccess output CLI Example: .. code-block:: bash salt '*' apcups.status """ ret = {} apcaccess = _check_apcaccess() res = __salt__["cmd.run_all"](apcaccess) retcode = res["retcode"] if retcode != 0: ret["Error"] = "Something with wrong executing apcaccess, is apcupsd running?" return ret for line in res["stdout"].splitlines(): line = line.split(":") ret[line[0].strip()] = line[1].strip() return ret def status_load(): """ Return load CLI Example: .. code-block:: bash salt '*' apcups.status_load """ data = status() if "LOADPCT" in data: load = data["LOADPCT"].split() if load[1].lower() == "percent": return float(load[0]) return {"Error": "Load not available."} def status_charge(): """ Return battery charge CLI Example: .. code-block:: bash salt '*' apcups.status_charge """ data = status() if "BCHARGE" in data: charge = data["BCHARGE"].split() if charge[1].lower() == "percent": return float(charge[0]) return {"Error": "Load not available."} def status_battery(): """ Return true if running on battery power CLI Example: .. code-block:: bash salt '*' apcups.status_battery """ data = status() if "TONBATT" in data: return not data["TONBATT"] == "0 Seconds" return {"Error": "Battery status not available."}