Ejemplo n.º 1
0
    def __init__(self, **kwargs):
        super(NginxObject, self).__init__(**kwargs)

        # Have to override intervals here because new container sub objects.
        self.intervals = context.app_config['containers'].get('nginx', {}).get(
            'poll_intervals', {'default': 10})

        self.root_uuid = self.data.get('root_uuid') or getattr(
            context.objects.root_object, 'uuid', None)
        self._local_id = self.data['local_id']  # Assigned by manager
        self.pid = self.data['pid']
        self.version = self.data['version']
        self.workers = self.data['workers']
        self.prefix = self.data['prefix']
        self.bin_path = self.data['bin_path']
        self.conf_path = self.data['conf_path']
        self.name = self.version

        # agent config
        default_config = context.app_config['containers']['nginx']
        self.upload_config = self.data.get(
            'upload_config') or default_config.get('upload_config', False)
        self.run_config_test = self.data.get('run_test') or default_config.get(
            'run_test', False)
        self.upload_ssl = self.data.get('upload_ssl') or default_config.get(
            'upload_ssl', False)

        # nginx -V data
        self.parsed_v = nginx_v(self.bin_path)

        # filters
        self.filters = [
            Filter(**raw_filter)
            for raw_filter in self.data.get('filters') or []
        ]

        # nginx config
        if 'config_data' in self.data:
            self._restore_config_collector(
                self.data['config_data']['previous'])
        else:
            self._setup_config_collector()

        # plus status
        self.plus_status_external_url, self.plus_status_internal_url = self.get_alive_plus_status_urls(
        )
        self.plus_status_enabled = True if (
            self.plus_status_external_url
            or self.plus_status_internal_url) else False

        # stub status
        self.stub_status_url = self.get_alive_stub_status_url()
        self.stub_status_enabled = True if self.stub_status_url else False

        self.processes = []

        self._setup_meta_collector()
        self._setup_metrics_collector()
        self._setup_access_logs()
        self._setup_error_logs()
Ejemplo n.º 2
0
 def nginx_minus_v(self, meta):
     """ call -V and parse """
     parsed_v = nginx_v(self.object.bin_path)
     meta['ssl'] = parsed_v['ssl']
     meta['version'] = parsed_v['version']
     meta['plus'] = parsed_v['plus']
     meta['configure'] = parsed_v['configure']
Ejemplo n.º 3
0
 def add_configured_variable_logs(self):
     """
     Get logs configured through nginx -V options and try to find access and error logs
     This happens only if nginx access and error logs are not configured in nginx.conf
     """
     if self.binary is not None and (len(self.access_logs) < 1
                                     or len(self.error_logs) < 1):
         try:
             v_options = nginx_v(self.binary)
             configure = v_options['configure']
             # adding access or error logs from options only if they are empty
             if len(self.access_logs) < 1:
                 access_log_path = configure.get('http-log-path')
                 if os.path.isfile(
                         access_log_path) and access_log_path is not None:
                     self.access_logs[access_log_path] = {
                         'log_format': None
                     }
             if len(self.error_logs) < 1:
                 error_log_path = configure.get('error-log-path')
                 if os.path.isfile(
                         error_log_path) and error_log_path is not None:
                     self.error_logs[error_log_path] = {
                         'log_level': 'error'
                     }
         except Exception as e:
             exception_name = e.__class__.__name__
             context.log.error(
                 'failed to get configured variables from %s -V due to %s' %
                 (self.binary, exception_name))
             context.log.debug('additional info:', exc_info=True)
Ejemplo n.º 4
0
 def nginx_minus_v(self, meta):
     """ call -V and parse """
     parsed_v = nginx_v(self.object.bin_path)
     meta['ssl'] = parsed_v['ssl']
     meta['version'] = parsed_v['version']
     meta['plus'] = parsed_v['plus']
     meta['configure'] = parsed_v['configure']
Ejemplo n.º 5
0
    def __init__(self, **kwargs):
        super(NginxObject, self).__init__(**kwargs)

        # Have to override intervals here because new container sub objects.
        self.intervals = context.app_config['containers'].get('nginx', {}).get('poll_intervals', {'default': 10})

        self.root_uuid = self.data.get(
            'root_uuid') or context.objects.root_object.uuid if context.objects.root_object else None
        self.local_id_cache = self.data['local_id']  # Assigned by manager
        self.pid = self.data['pid']
        self.version = self.data['version']
        self.workers = self.data['workers']
        self.prefix = self.data['prefix']
        self.bin_path = self.data['bin_path']
        self.conf_path = self.data['conf_path']

        # agent config
        default_config = context.app_config['containers']['nginx']
        self.upload_config = self.data.get('upload_config') or default_config.get('upload_config', False)
        self.run_config_test = self.data.get('run_test') or default_config.get('run_test', False)
        self.upload_ssl = self.data.get('upload_ssl') or default_config.get('upload_ssl', False)

        # nginx -V data
        self.parsed_v = nginx_v(self.bin_path)

        # filters
        self.filters = [Filter(**raw_filter) for raw_filter in self.data.get('filters') or []]

        # nginx config
        if 'config_data' in self.data:
            self.config = self.data['config_data']['config']
            self._restore_config_collector(self.data['config_data']['previous'])
        else:
            self.config = NginxConfig(self.conf_path, prefix=self.prefix, binary=self.bin_path)
            self._setup_config_collector()

        # plus status
        self.plus_status_external_url, self.plus_status_internal_url = self.get_alive_plus_status_urls()
        self.plus_status_enabled = True if (self.plus_status_external_url or self.plus_status_internal_url) else False

        # stub status
        self.stub_status_url = self.get_alive_stub_status_url()
        self.stub_status_enabled = True if self.stub_status_url else False

        self.processes = []

        self._setup_meta_collector()
        self._setup_metrics_collector()
        self._setup_access_logs()
        self._setup_error_logs()
Ejemplo n.º 6
0
 def test_1_11_8_libressl(self):
     self.push_subp_result(
         stdout_lines=[],
         stderr_lines=[
             'nginx version: nginx/1.11.8',
             'built by gcc 6.3.0 20161229 (Debian 6.3.0-2)',
             'built with LibreSSL 2.5.0', 'TLS SNI support enabled'
         ])
     assert_that(
         nginx_v('foo'),
         has_entries(version='1.11.8',
                     ssl=has_entries(built=contains('LibreSSL', '2.5.0',
                                                    None),
                                     run=contains('LibreSSL', '2.5.0',
                                                  None)),
                     plus=has_entries(enabled=False, release=None),
                     configure=empty()))
Ejemplo n.º 7
0
 def test_1_10_1_openssl_oss(self):
     self.push_subp_result(stdout_lines=[],
                           stderr_lines=[
                               'nginx version: nginx/1.10.1',
                               'built by clang 7.0.2 (clang-700.1.81)',
                               'built with OpenSSL 1.0.2h  3 May 2016',
                               'TLS SNI support enabled'
                           ])
     assert_that(
         nginx_v('xyz'),
         has_entries(version='1.10.1',
                     ssl=has_entries(built=contains('OpenSSL', '1.0.2h',
                                                    '3 May 2016'),
                                     run=contains('OpenSSL', '1.0.2h',
                                                  '3 May 2016')),
                     plus=has_entries(enabled=False, release=None),
                     configure=empty()))
Ejemplo n.º 8
0
 def test_1_11_3_openssl_plus(self):
     self.push_subp_result(
         stdout_lines=[],
         stderr_lines=[
             'nginx version: nginx/1.11.3 (nginx-plus-r10)',
             'built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)',
             'built with OpenSSL 1.0.2g-fips 1 Mar 2016 (running with OpenSSL 1.0.2g 1 Mar 2016)',
             'TLS SNI support enabled'
         ])
     assert_that(
         nginx_v('xyz'),
         has_entries(version='1.11.3',
                     ssl=has_entries(built=contains('OpenSSL',
                                                    '1.0.2g-fips',
                                                    '1 Mar 2016'),
                                     run=contains('OpenSSL', '1.0.2g',
                                                  '1 Mar 2016')),
                     plus=has_entries(enabled=True,
                                      release='nginx-plus-r10'),
                     configure=empty()))
Ejemplo n.º 9
0
 def test_1_11_2_open_resty(self):
     self.push_subp_result(
         stdout_lines=[],
         stderr_lines=[
             'nginx version: openresty/1.11.2.2',
             'built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)',
             'built with OpenSSL 1.0.2j  26 Sep 2016',
             'TLS SNI support enabled', "configure arguments: " +
             ("--prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -I/usr/local/openresty/zlib/include "
              "-I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl/include' "
              "--add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 "
              "--add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 "
              "--add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 "
              "--add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 "
              "--add-module=../ngx_lua-0.10.7 --add-module=../ngx_lua_upstream-0.06 "
              "--add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 "
              "--add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 "
              "--add-module=../redis-nginx-module-0.3.7 --with-ld-opt='-Wl,-rpath,"
              "/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib "
              "-L/usr/local/openresty/openssl/lib -Wl,-rpath,"
              "/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib' "
              "--with-pcre-jit --with-ipv6 --with-stream --with-stream_ssl_module --with-http_v2_module "
              "--without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module "
              "--with-http_stub_status_module --with-http_realip_module --with-http_addition_module "
              "--with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module "
              "--with-http_gzip_static_module --with-http_sub_module --with-http_dav_module "
              "--with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads "
              "--with-file-aio --with-dtrace-probes --with-http_ssl_module")
         ])
     assert_that(
         nginx_v('foo'),
         has_entries({
             'version':
             '1.11.2.2',
             'ssl':
             has_entries({
                 'built':
                 contains('OpenSSL', '1.0.2j', '26 Sep 2016'),
                 'run':
                 contains('OpenSSL', '1.0.2j', '26 Sep 2016')
             }),
             'plus':
             has_entries({
                 'enabled': False,
                 'release': none()
             }),
             'configure':
             has_entries({
                 'prefix':
                 '/usr/local/openresty/nginx',
                 'with-cc-opt':
                 ("'-O2 -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include "
                  "-I/usr/local/openresty/openssl/include'"),
                 'with-ld-opt':
                 ("'-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib "
                  "-L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl/lib "
                  "-Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib'"
                  ),
                 'add-module':
                 contains(
                     '../ngx_devel_kit-0.3.0', '../echo-nginx-module-0.60',
                     '../xss-nginx-module-0.05', '../ngx_coolkit-0.2rc3',
                     '../set-misc-nginx-module-0.31',
                     '../form-input-nginx-module-0.12',
                     '../encrypted-session-nginx-module-0.06',
                     '../srcache-nginx-module-0.31', '../ngx_lua-0.10.7',
                     '../ngx_lua_upstream-0.06',
                     '../headers-more-nginx-module-0.32',
                     '../array-var-nginx-module-0.05',
                     '../memc-nginx-module-0.17',
                     '../redis2-nginx-module-0.13',
                     '../redis-nginx-module-0.3.7')
             })
         }))
Ejemplo n.º 10
0
    def __init__(self, **kwargs):
        super(NginxObject, self).__init__(**kwargs)

        # Have to override intervals here because new container sub objects.
        self.intervals = context.app_config['containers'].get('nginx', {}).get(
            'poll_intervals', {'default': 10})

        self.root_uuid = context.uuid
        self._local_id = self.data['local_id']  # Assigned by manager
        self.pid = self.data['pid']
        self.version = self.data['version']
        self.workers = self.data['workers']
        self.prefix = self.data['prefix']
        self.bin_path = self.data['bin_path']
        self.conf_path = self.data['conf_path']
        self.name = self.version

        # agent config
        default_config = context.app_config['containers']['nginx']
        self.upload_config = self.data.get(
            'upload_config') or default_config.get('upload_config', False)
        self.run_config_test = self.data.get('run_test') or default_config.get(
            'run_test', False)
        self.upload_ssl = self.data.get('upload_ssl') or default_config.get(
            'upload_ssl', False)

        # nginx -V data
        self.parsed_v = nginx_v(self.bin_path)

        # filters
        self.filters = [
            Filter(**raw_filter)
            for raw_filter in self.data.get('filters') or []
        ]

        # nginx config
        if 'config_data' in self.data:
            self._restore_config_collector(
                self.data['config_data']['previous'])
        else:
            self._setup_config_collector()

        # api
        self.api_endpoints_to_skip = self.get_api_endpoints_to_skip()
        self.api_external_url, self.api_internal_url = self.get_alive_api_urls(
        )
        self.api_enabled = True if (self.api_external_url
                                    or self.api_internal_url) else False
        api_url = self.api_internal_url if self.api_internal_url is not None else self.api_external_url
        if self.api_enabled and plus.get_latest_supported_api(api_url) is None:
            context.log.debug(
                "API directive was specified but no supported API was found.")
            self.api_enabled = False

        # plus status
        self.plus_status_external_url, self.plus_status_internal_url = self.get_alive_plus_status_urls(
        )
        self.plus_status_enabled = True if (
            self.plus_status_external_url
            or self.plus_status_internal_url) else False

        # stub status
        self.stub_status_url = self.get_alive_stub_status_url()
        self.stub_status_enabled = True if self.stub_status_url else False

        self.processes = []

        self.reloads = self.data.get('reloads', 0)

        self._setup_meta_collector()
        self._setup_metrics_collector()
        self._setup_access_logs()
        self._setup_error_logs()

        # publish events for old object
        for error in self.config.parser_errors:
            self.eventd.event(level=WARNING, message=error)