mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
add filter status to ps module to get a list of processes according to their state
This commit is contained in:
parent
c258121e2c
commit
7662369074
2 changed files with 30 additions and 0 deletions
1
changelog/61420.added
Normal file
1
changelog/61420.added
Normal file
|
@ -0,0 +1 @@
|
|||
add a filter function to ps module to get a list of processes on a minion according to their state.
|
|
@ -772,3 +772,32 @@ def psaux(name):
|
|||
ret = []
|
||||
ret.extend([sanitize_name, found_infos, pid_count])
|
||||
return ret
|
||||
|
||||
|
||||
def status(filter):
|
||||
"""
|
||||
Returns a list of processes according to their states.
|
||||
See https://psutil.readthedocs.io/en/latest/index.html\
|
||||
?highlight=status#process-status-constants
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' ps.status [running, idle, stopped, sleeping, dead, \
|
||||
zombie, ...]
|
||||
"""
|
||||
ret = []
|
||||
if filter is not None and filter != "":
|
||||
sanitize_name = str(filter)
|
||||
try:
|
||||
ret = [
|
||||
proc.info
|
||||
for proc in psutil.process_iter(["pid", "name", "status"])
|
||||
if proc.info["status"] == sanitize_name
|
||||
]
|
||||
except psutil.AccessDenied:
|
||||
pass
|
||||
for i in ret:
|
||||
i.pop("status")
|
||||
return ret
|
||||
|
|
Loading…
Add table
Reference in a new issue