Exemplo n.º 1
0
    def get_alive_stub_status_url(self):
        """
        Tries to get alive stub_status url
        Records some events about it
        :return:
        """
        urls_to_check = self.config.stub_status_urls

        if 'stub_status' in context.app_config.get('nginx', {}):
            predefined_uri = context.app_config['nginx']['stub_status']
            urls_to_check.append(http.resolve_uri(predefined_uri))

        stub_status_url = self.__get_alive_status(urls_to_check)
        if stub_status_url:
            # Send stub detected event
            self.eventd.event(
                level=INFO,
                message='nginx stub_status detected, %s' % stub_status_url
            )
        else:
            self.eventd.event(
                level=INFO,
                message='nginx stub_status not found in nginx config'
            )
        return stub_status_url
Exemplo n.º 2
0
    def get_alive_api_urls(self):
        """
        Tries to get alive api urls
        There are two types of api urls: internal and external
        - internal are for the agent and usually they have the localhost ip in address
        - external are for the browsers and usually they have a normal server name

        Returns a tuple of str or Nones - (external_url, internal_url)

        Even if external api url is not responding (cannot be accesible from the host)
        we should return it to show in our UI

        :return: (str or None, str or None)
        """
        internal_urls = self.config.api_internal_urls
        external_urls = self.config.api_external_urls

        if 'api' in context.app_config.get('nginx', {}):
            predefined_uri = context.app_config['nginx']['api']
            internal_urls.append(http.resolve_uri(predefined_uri))

        internal_api_url = self.__get_alive_status(internal_urls,
                                                   json=True,
                                                   what='api internal')
        if internal_api_url:
            self.eventd.event(level=INFO,
                              message='nginx internal api detected, %s' %
                              internal_api_url)

        external_api_url = self.__get_alive_status(external_urls,
                                                   json=True,
                                                   what='api external')
        if len(self.config.api_external_urls) > 0:
            if not external_api_url:
                external_api_url = self.config.api_external_urls[0]

            self.eventd.event(level=INFO,
                              message='nginx external api detected, %s' %
                              external_api_url)

        return external_api_url, internal_api_url
Exemplo n.º 3
0
    def get_alive_plus_status_urls(self):
        """
        Tries to get alive plus urls
        There are two types of plus status urls: internal and external
        - internal are for the agent and usually they have the localhost ip in address
        - external are for the browsers and usually they have a normal server name

        Returns a tuple of str or Nones - (external_url, internal_url)

        Even if external status url is not responding (cannot be accesible from the host)
        we should return it to show in our UI

        :return: (str or None, str or None)
        """
        internal_urls = self.config.plus_status_internal_urls
        external_urls = self.config.plus_status_external_urls

        if 'plus_status' in context.app_config.get('nginx', {}):
            predefined_uri = context.app_config['nginx']['plus_status']
            internal_urls.append(http.resolve_uri(predefined_uri))

        internal_status_url = self.__get_alive_status(internal_urls, json=True)
        if internal_status_url:
            self.eventd.event(
                level=INFO,
                message='nginx internal plus_status detected, %s' % internal_status_url
            )

        external_status_url = self.__get_alive_status(external_urls, json=True)
        if len(self.config.plus_status_external_urls) > 0:
            if not external_status_url:
                external_status_url = 'http://%s' % self.config.plus_status_external_urls[0]

            self.eventd.event(
                level=INFO,
                message='nginx external plus_status detected, %s' % external_status_url
            )

        return external_status_url, internal_status_url