Created
October 28, 2016 13:09
-
-
Save codyaray/22e17b2e9b630001760103454d3f499d to your computer and use it in GitHub Desktop.
StackStorm helper script to find a cron rule by time printed in the logs
This file contains 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 | |
import argparse | |
from pymongo import MongoClient | |
def main(host, day_of_week, day, hour, minute): | |
db = MongoClient("mongodb://%s:27017" % host)['st2'] | |
query = {"type":"core.st2.CronTimer"} | |
if day_of_week: | |
query["parameters.day_of_week"] = day_of_week | |
if day: | |
query["parameters.day"] = day | |
if hour: | |
query["parameters.hour"] = hour | |
if minute: | |
query["parameters.minute"] = minute | |
for trigger in db.trigger_d_b.find(query): | |
for rule in db.rule_d_b.find({"trigger": "core.%s" % trigger['name']}): | |
print rule['uid'] | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(add_help=False) | |
parser.add_argument('host') | |
parser.add_argument('--help', help='show this help message and exit', action='help') | |
parser.add_argument('-D', '--day', help='specify the cron day') | |
parser.add_argument('-h', '--hour', help='specify the cron hour') | |
parser.add_argument('-m', '--minute', help='specify the cron minute') | |
parser.add_argument('-d', '--day-of-week', help='specify the cron day-of-week') | |
args = parser.parse_args() | |
main(args.host, args.day_of_week, args.day, args.hour, args.minute) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment