Exemplo n.º 1
0
def zabbix_callback(room, event):
    """Callback function for the !zabbix matches.

    :param room: reference to the room
    :type room: room thingie
    :param event: the message, essentially
    :type event: event
    """
    try:
        room_id, zabbix_config = _room_init(room)
        if room_id is None:
            return

        args = event['content']['body'].split()
        args.pop(0)
        messages = []
        if len(args) == 0:
            messages = _zabbix_unacked_triggers(zabbix_config)

        elif len(args) == 1:
            arg = args[0]
            if arg == 'all':
                messages = _zabbix_all_triggers(zabbix_config)

            elif arg == 'acked':
                messages = _zabbix_acked_triggers(zabbix_config)

            elif arg == 'unacked':
                messages = _zabbix_unacked_triggers(zabbix_config)

        #     elif arg == 'hosts':
        #         hosts = zabbix.hosts(zabbix_config)

            else:
                messages = _zabbix_help()

        elif len(args) == 2:
            if args[0] == 'ack':
                trigger_id = args[1]
                messages = _zabbix_acknowledge_trigger(zabbix_config,
                                                       trigger_id)

            else:
                messages = _zabbix_help()

        else:
            messages = _zabbix_help()

        if len(messages) == 0:
            messages = 'Nothing to notify'

        matrix_config['message'] = messages
        matrix.send_message(matrix_config, room)

    except Exception as error:  # Keep running!
        return _error(matrix_config, room, error)
Exemplo n.º 2
0
def _error(matrix_config, room, error):
    """Error handling function. Prints a traceback to the log and the
    title of the error is returned to matrix.

    :param matrix_config: the matrix configuration
    :type matrix_config: dict
    :param room: matrix room reference
    :type room: matrix room object
    :param error: reference to the exception
    :type error: exception
    """
    logging.error(error, exc_info=True)
    message = "{0}<br /><br />Please see my log.".format(str(error))
    matrix_config['message'] = message
    matrix.send_message(matrix_config, room)
Exemplo n.º 3
0
def dnsjedi_callback(room, event):
    """Callback function for the !dnsjedi matches.

    :param room: reference to the room
    :type room: room thingie
    :param event: the message, essentially
    :type event: event
    """
    try:
        room_id, zabbix_config = _room_init(room)
        if room_id is None:
            return

        if room_id not in ['!OUZabccnPEwNGbzecZ', '!OTdomlClomfOdIOdOa']:
            return

        args = event['content']['body'].split()
        args.pop(0)

        if len(args) == 0:
            messages = _dnsjedi_chunks_summary(zabbix_config)

        elif len(args) == 1:
            arg = args[0]
            if arg == 'left':
                messages = _dnsjedi_chunks_left(zabbix_config)

            elif arg == 'forecast':
                messages = _dnsjedi_chunks_forecast(zabbix_config)

            else:
                messages = _dnsjedi_help()

        matrix_config['message'] = messages
        matrix.send_message(matrix_config, room)

    except Exception as error:  # Keep running!
        return _error(matrix_config, room, error)
Exemplo n.º 4
0
def send_message(room, message):
    config = matrix.read_config('/etc/matrix.conf')
    config['message'] = message  # .replace('\n', '<br />')
    config['room'] = room
    client, room = matrix.setup(config)
    matrix.send_message(config, room)
Exemplo n.º 5
0
    args = matrix.flags()
    args['message'] = " ".join(args['message'])
    if args['debug'] is True:
        matrix.set_log_level('DEBUG')

    else:
        matrix.set_log_level()

    try:
        config = matrix.merge_config(args, matrix.read_config(args['config']))
        config['matrix'] = matrix.merge_config(args, config['matrix'])

    except FileNotFoundError:
        config = args
        if None in [config['username'], config['password'], config['room']]:
            raise

    color_config = {}
    for key, value in config['colors'].items():
        if key.startswith('zabbix'):
            key = key.replace('zabbix_', '')
            color_config[key] = value

    logging.debug(color_config)
    config['matrix']['message'] = colorize(color_config, config['message'])
    client, room = matrix.setup(config['matrix'])
    matrix.send_message(config['matrix'], room)
    if 'token' not in config['matrix']:
        print('logging out')
        #client.logout()
Exemplo n.º 6
0
def process():
    mod_actions = reddit.new_mod_actions()
    for ma in mod_actions:
        md = reddit.format_mod_action_md(ma)
        html = reddit.format_mod_action_html(ma)
        matrix.send_message(md, html)