Beispiel #1
0
    def __setup_pipeline(self, name):
        """
        Sets up a pipeline/tail object for a collector based on "filename".

        :param name: Str
        :return: Pipeline
        """
        tail = None
        try:
            if name.startswith('syslog'):
                address_bucket = name.split(',', 1)[0]
                host, port, address = net.ipv4_address(
                    address=address_bucket.split('=')[1],
                    full_format=True,
                    silent=True)
                # Right now we assume AFNET address/port...e.g. no support for unix sockets

                if address in context.listeners:
                    port = int(port)  # socket requires integer port
                    tail = SyslogTail(address=(host, port))
            else:
                tail = FileTail(name)
        except Exception as e:
            context.log.error(
                'failed to initialize pipeline for "%s" due to %s (maybe has no rights?)'
                % (name, e.__class__.__name__))
            context.log.debug('additional info:', exc_info=True)

        return tail
Beispiel #2
0
    def test_ipv4_address(self):
        host, port = net.ipv4_address(address='10.10.10.10:443')
        assert_that(host, equal_to('10.10.10.10'))
        assert_that(port, equal_to('443'))

        host, port = net.ipv4_address(address='443')
        assert_that(host, equal_to('*'))
        assert_that(port, equal_to('443'))

        host, port = net.ipv4_address(address='10.10.10.10')
        assert_that(host, equal_to('10.10.10.10'))
        assert_that(port, equal_to('80'))

        host, port = net.ipv4_address(address='*')
        assert_that(host, equal_to('*'))
        assert_that(port, equal_to('80'))
Beispiel #3
0
    def __setup_pipeline(self, name):
        """
        Sets up a pipeline/tail object for a collector based on "filename".

        :param name: Str
        :return: Pipeline
        """
        tail = None
        try:
            if name.startswith('syslog'):
                address_bucket = name.split(',', 1)[0]
                host, port, address = net.ipv4_address(
                    address=address_bucket.split('=')[1], full_format=True, silent=True
                )
                # Right now we assume AFNET address/port...e.g. no support for unix sockets

                if address in context.listeners:
                    port = int(port)  # socket requires integer port
                    tail = SyslogTail(address=(host, port))
            else:
                tail = FileTail(name)
        except Exception as e:
            context.log.error(
                'failed to initialize pipeline for "%s" due to %s (maybe has no rights?)' % (name, e.__class__.__name__)
            )
            context.log.debug('additional info:', exc_info=True)

        return tail
Beispiel #4
0
    def _setup_app_listeners(self):
        from amplify.agent.common.util import net
        self.listeners = set()

        # get a list of listener names
        names = self.app_config.get('listeners', {}).get('keys', '').split(',')

        # for each listener...
        for name in names:
            # ...try to find the definition...
            listener_definition = self.app_config.get('listener_%s' % name)
            # ...if there is a definition...
            if listener_definition:
                # ...try to find the address...
                listener_address = listener_definition.get('address')
                # ...if there is an address...
                if listener_address is not None:
                    # ...try to format and save the ipv4 address into the context store.
                    try:
                        _, _, formatted_address = net.ipv4_address(address=listener_address, full_format=True)
                        self.listeners.add(formatted_address)
                    except:
                        pass  # just ignore bad ipv4 definitions for now
    def _setup_app_listeners(self):
        from amplify.agent.common.util import net
        self.listeners = set()

        # get a list of listener names
        names = self.app_config.get('listeners', {}).get('keys', '').split(',')

        # for each listener...
        for name in names:
            # ...try to find the definition...
            listener_definition = self.app_config.get('listener_%s' % name)
            # ...if there is a definition...
            if listener_definition:
                # ...try to find the address...
                listener_address = listener_definition.get('address')
                # ...if there is an address...
                if listener_address is not None:
                    # ...try to format and save the ipv4 address into the context store.
                    try:
                        _, _, formatted_address = net.ipv4_address(address=listener_address, full_format=True)
                        self.listeners.add(formatted_address)
                    except:
                        pass  # just ignore bad ipv4 definitions for now