Last active
July 17, 2018 17:25
-
-
Save idlethreat/18cc12b0a3f98ddad79509233c289760 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
## | |
# stop.py (short for Salt TOP) | |
# A quick and dirty way to check out running Salt-master processes without having to dig through a bunch of JSON | |
# Seems to work OK with Python 3 | |
# | |
# Example Output: | |
# | |
# Start_Time, Key, Running, Arguments, KillString | |
# 2018, Jul 17 08:24:39.379270 , 20180717082439379270 , SERVER1.local , state.apply , [], KILL_STRING: salt 'SERVER1.local' saltutil.kill_job 20180717082439379270 | |
# Start_Time, Key, Running, Arguments, KillString | |
# 2018, Jul 17 08:23:57.667766 , 20180717082357667766 , SERVER2.local , state.apply , [], KILL_STRING: salt 'SERVER2.local' saltutil.kill_job 20180717082357667766 | |
# | |
## | |
import json | |
import os | |
try: | |
os.remove('/tmp/run.json') | |
except: | |
pass | |
os.system('salt-run jobs.active --out json >> /tmp/run.json') | |
with open('/tmp/run.json') as f: | |
data = json.load(f) | |
for key, value in data.items(): | |
myKey = key | |
myTarget = value['Target'] | |
myFunction = value['Function'] | |
myRunning = value['Running'][0] | |
myStartTime = value['StartTime'] | |
keyMyArguments = value['Arguments'] | |
try: | |
keyMyArguments = keyMyArguments[0] | |
except: | |
pass | |
for keyMyRunning, valueMyRunning in myRunning.items(): | |
keyMyRunning = keyMyRunning | |
myKillString = "KILL_STRING: salt '{}' saltutil.kill_job {}".format(keyMyRunning, myKey) | |
print("Start_Time, Key, Running, Arguments, KillString") | |
print("{} , {} , {} , {} , {}, {}").format(myStartTime, myKey, keyMyRunning, myFunction, keyMyArguments, myKillString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment