Exemplo n.º 1
0
def tmpdir():
    path = mkdtemp(prefix='arx.')
    try:
        log.debug('Temporary directory is: %s', path)
        yield path
    finally:
        rm('-rf', path)
Exemplo n.º 2
0
    def listen(self):
        client = docker.APIClient(base_url=self.url,
                                  version=docker_client_version)

        # the 'since' flag is to start reading from a particular event.
        # see the docker SDK docs:
        # https://docker-py.readthedocs.io/en/stable/client.html#docker.client.DockerClient.events
        for event in client.events(decode=True, since=self.since):
            for k in ['time', 'Time']:
                if k in event:
                    event[k] = datetime.fromtimestamp(event[k])
            log.debug('Event: %s', event)
            data = {}
            i = get_id(event)
            if i is not None:
                try:
                    if 'from' in event or 'From' in event:
                        data = client.inspect_container(i)
                    else:
                        data = client.inspect_image(i)
                    self.data[i] = data
                except docker.errors.NotFound:
                    data = self.data[i]
            self.handle(event, data)
            # mark the last event seen so we can restart this listener
            # without dropping events. the caller must be responsible for
            # ensuring that handlers do not drop events, because they are
            # fire-and-forget from this point.
            self.since = get_time_nano(event)
Exemplo n.º 3
0
def run(runnable):
    p = Process(target=direct, args=(runnable,))
    p.start()
    log.debug('Started %s in: pid=%s', runnable, p.pid)
    p.join()
    log.debug('Finished %s: pid=%s exit=%s', runnable, p.pid, p.exitcode)
    if p.exitcode != 0:
        raise Failed()
Exemplo n.º 4
0
 def default(event, data):
     """The default handler prints basic event info."""
     messages = defaultdict(lambda: 'Avast:')
     messages['start'] = 'Thar she blows!'
     messages['tag'] = 'Thar she blows!'
     messages['stop'] = 'Away into the depths:'
     messages['destroy'] = 'Away into the depths:'
     messages['delete'] = 'Away into the depths:'
     status = get_status(event)
     message = messages[status] + ' %s/%s'
     log.info(message, status, get_id(event))
     log.debug('"data": %s', form_json(data))
Exemplo n.º 5
0
 def __call__(self, source):
     if isinstance(source, Source):
         log.debug('Not reinterpreting source: %r', source)
         return source
     if isinstance(source, Mapping):
         log.debug('Treating as map: %s', source)
         if len(source) != 1:
             raise BadSourceFormat('Dictionary sources must be 1 element.')
         kind, data = list(source.items())[0]
         return Interpreter.apply_handlers(kind, data, self.data_handlers)
     if isinstance(source, six.string_types):
         source = uritools.urisplit(source)
     if isinstance(source, uritools.SplitResult):
         log.debug('Treating as URL: %s', uridisplay(source))
         kind = source.scheme
         return Interpreter.apply_handlers(kind, source, self.uri_handlers)
     raise BadSourceFormat('Please pass either a string or a dictionary.')
Exemplo n.º 6
0
 def __call__(self, source):
     if isinstance(source, Source):
         log.debug('Not reinterpreting source: %r', source)
         return source
     if isinstance(source, Mapping):
         log.debug('Treating as map: %s', source)
         if len(source) != 1:
             raise BadSourceFormat('Dictionary sources must be 1 element.')
         kind, data = list(source.items())[0]
         return Interpreter.apply_handlers(kind, data, self.data_handlers)
     if isinstance(source, six.string_types):
         source = uritools.urisplit(source)
     if isinstance(source, uritools.SplitResult):
         log.debug('Treating as URL: %s', uridisplay(source))
         kind = source.scheme
         return Interpreter.apply_handlers(kind, source, self.uri_handlers)
     raise BadSourceFormat('Please pass either a string or a dictionary.')
Exemplo n.º 7
0
 def logEvent(self, event, event_type):
     if 'Actor' in event:
         actor = event['Actor']
     else:
         actor = ''
     log.debug('{} {}: {}'.format(event['Action'], event_type, actor))