Example #1
0
def register_subs():
    try:
        sock.get_sock().subscribe("config/request/rss", rss_config)
        sock.get_sock().subscribe("input/http/rss", rss_receiver)
    except:
        print("Failed to register subscriptions")
        traceback.print_exc(None)
Example #2
0
 def command_runner(dummy):
     global cid
     cid += 1
     my_cid = cid
     body = { 'cid': my_cid, 'target': target, 'instruction': instruction, 'cmd_arg': cmd_arg }
     asc = AsyncCall()
     tracker[my_cid] = asc
     sock.get_sock().send_multipart('MSG', 'output/salt/run', json.dumps(body).encode('utf-8'))
     raise asc
Example #3
0
def poll_feed(tag, url, period=10 * 60):
    global feeds, callbacks
    if tag not in feeds:
        feeds[tag] = {"feed": url, "period": period}
        sock.get_sock().send_multipart("MSG", "config/service/rss", json.dumps(feeds))
    if tag not in callbacks:
        callbacks[tag] = []
    c = Chain()
    callbacks[tag].append(c)
    return c
Example #4
0
def register_salt_macros():
    try:
        sock.get_sock().chain('input/salt/run') >> receiver
        from config import salt
        # salt = {
        #     'macros': {
        #         'test': {'target': '*', 'instruction': 'test.ping', 'cmd_arg': ()}
        #     }
        # }
        macros = salt.get('macros', {})
        def salt_macro(body):
            # {'match': match, 'user': user, 'instruction': instruction, 'body': body, 'send_reply': send_reply}
            macro_name = body['match'].group(1)
            if not macro_name:
                return "Known macros: {}".format(", ".join(macros.keys()))
            macro = macros.get(macro_name.strip(), None)
            if not macro:
                return "Unknown macro"
            run_command(**macro)({})
        command_registry.getRegistry().registerInstruction(re.compile(r'salt macro( .*)?'), salt_macro, ("salt macro [name] - Run specified macro, omit name to get a list of macros",))
    except:
        print("Failed to register macros")
        traceback.print_exc(None)
Example #5
0
 def send_reply(message):
     return_body['message'] = message
     sock.get_sock().send_multipart('MSG', return_target, json.dumps(return_body))
Example #6
0
 def baked_send_to_channel(message):
     ircmsg = {"server": server, "channel": channel, "message": message}
     sock.get_sock().send_multipart("MSG", "output/irc/msg", json.dumps(ircmsg))
Example #7
0
    event = event_map.get(channel, None)
    if not event:
        return
    callbacks = proj_tracking[event].get(body["project"]["path_with_namespace"], None)
    if callbacks:
        cb = Chain() >> callbacks
        cb(body)
    if all_tracking[event]:
        cb = Chain() >> all_tracking[event]
        cb(body)


for k, v in event_map.items():
    all_tracking[v] = []
    proj_tracking[v] = {}
    sock.get_sock().subscribe(k, gitlab_receiver)

# Tag push


# 'tag_push': 'input/http/commit/tag_push',
# 'issue': 'input/http/commit/issue',
# 'note': 'input/http/commit/note',
# 'merge_request': 'input/http/commit/merge_request',
# 'pipeline': 'input/http/commit/pipeline'
# 'project_create': 'input/http/gitlab_admin/project',
# 'project_destroy': 'input/http/gitlab_admin/project',
# 'project_rename': 'input/http/gitlab_admin/project',
# 'project_transferred': 'input/http/gitlab_admin/project',
# 'user_add_to_team': 'input/http/gitlab_admin/team',
# 'user_remove_from_team': 'input/http/gitlab_admin/team',
Example #8
0
def rss_config(cmd, channel, body):
    global feeds
    sock.get_sock().send_multipart("MSG", body["requesting"], json.dumps(feeds))