Exemplo n.º 1
0
def watch_sources():
    """runloop to parse events from sources and dispatch alerts"""
    sources_info = '\n' + get_sources_info()
    first_line = True
    for source, line in get_new_lines():
        if first_line:
            first_line = False
            notify(sources_info, 'Started Watching Sources')

        # parse the fetched lines, if not alert-worthy, alert_type will be None
        alert_type, title, content = parse_line(line, source)

        if alert_type == 'notify':
            notify(content, title)

        if alert_type == 'alert':
            alert(content, title)
Exemplo n.º 2
0
def watch_sources():
    """runloop to parse events from sources and dispatch alerts"""
    sources_info = '\n' + get_sources_info()
    first_line = True
    for source, line in get_new_lines():
        if first_line:
            first_line = False
            notify(sources_info, 'Started Watching Sources')

        # parse the fetched lines, if not alert-worthy, alert_type will be None
        alert_type, title, content = parse_line(line, source)

        if alert_type == 'notify':
            notify(content, title)

        if alert_type == 'alert':
            alert(content, title)
Exemplo n.º 3
0
def quit_handler(signo, _stack_frame=None):
    notify('Quit by user: got signal #%s' % signo,
           title='Stopped Watching Sources')
    raise SystemExit(0)
Exemplo n.º 4
0
        # parse the fetched lines, if not alert-worthy, alert_type will be None
        alert_type, title, content = parse_line(line, source)

        if alert_type == 'notify':
            notify(content, title)

        if alert_type == 'alert':
            alert(content, title)


def quit_handler(signo, _stack_frame=None):
    notify('Quit by user: got signal #%s' % signo,
           title='Stopped Watching Sources')
    raise SystemExit(0)


if __name__ == "__main__":
    signal.signal(signal.SIGTERM, quit_handler)
    try:
        watch_sources()
    except KeyboardInterrupt:
        quit_handler('CTRL-C')
    except SystemExit:
        raise
    except BaseException as e:
        # notify user protection has stopped at all costs, even if error is a SyntaxError
        notify(traceback.format_exc(),
               title='Stopped Watching Sources: %s' % type(e).__name__)
        raise
Exemplo n.º 5
0
def quit_handler(signo, _stack_frame=None):
    notify('Quit by user: got signal #%s' % signo, title='Stopped Watching Sources')
    raise SystemExit(0)
Exemplo n.º 6
0
            first_line = False
            notify(sources_info, 'Started Watching Sources')

        # parse the fetched lines, if not alert-worthy, alert_type will be None
        alert_type, title, content = parse_line(line, source)

        if alert_type == 'notify':
            notify(content, title)

        if alert_type == 'alert':
            alert(content, title)


def quit_handler(signo, _stack_frame=None):
    notify('Quit by user: got signal #%s' % signo, title='Stopped Watching Sources')
    raise SystemExit(0)


if __name__ == "__main__":
    signal.signal(signal.SIGTERM, quit_handler)
    try:
        watch_sources()
    except KeyboardInterrupt:
        quit_handler('CTRL-C')
    except SystemExit:
        raise
    except BaseException as e:
        # notify user protection has stopped at all costs, even if error is a SyntaxError
        notify(traceback.format_exc(), title='Stopped Watching Sources: %s' % type(e).__name__)
        raise
Exemplo n.º 7
0
from sources import get_new_lines
from parsers import parse_line, get_sources_info
from loggers import notify, alert

def watch_sources():
    """runloop to parse events from sources and dispatch alerts"""
    sources_info = '\n' + get_sources_info()
    first_line = True
    for source, line in get_new_lines():
        if first_line:
            first_line = False
            notify(sources_info, 'Started Watching Sources')

        # parse the fetched lines, if not alert-worthy, alert_type will be None
        alert_type, title, content = parse_line(line, source)

        if alert_type == 'notify':
            notify(content, title)

        if alert_type == 'alert':
            alert(content, title)

if __name__ == "__main__":
    try:
        watch_sources()
    except BaseException as e:
        notify(type(e).__name__, 'Stopped Watching Sources')
        if isinstance(e, Exception):
            traceback.print_exc()