Exemplo n.º 1
0
    def check_time_series(self):
        """
        Check if time_series service is available.

        :rtype: ServiceState
        """
        dbs = [d['name'] for d in self.ts_client.get_list_database()]
        if self.CHECK_TS_DB not in dbs:
            msg = 'Missing database {}'.format(self.CHECK_TS_DB)
            return ServiceState(message=msg)

        measurements = self.ts_client.get_list_measurements()
        if measurements is None:
            msg = 'Cannot read measurements'
            return ServiceState(message=msg)

        return ServiceState()
Exemplo n.º 2
0
    def check_cache(self):
        """
        Check if cache service is available.

        :rtype: ServiceState
        """
        message = "import this"
        try:
            response = self.cache_store.echo(message)
        except Exception as exc:
            msg = 'Cache service crash on echo: {}'.format(exc)
            return ServiceState(message=msg)

        if response != message:
            return ServiceState(message='Failed to validate echo')

        return ServiceState()
Exemplo n.º 3
0
    def check_engines(self):
        """
        Check if engines are available.

        :rtype: ServiceState
        """
        if not check_checkable(name=self.SYSTEMCTL_ENGINE_PREFIX):
            msg = 'Dockerised environment. Engines Not Checked.'
            ss = ServiceState(message=msg)
            ss.state = True
            return ss

        if not check_process_status(name=self.CHECK_WEBSERVER):
            return ServiceState(message='Webserver is not running')  # Derp

        for engine in self.CHECK_ENGINES:
            if not check_engine_status(name=engine):
                msg = 'Engine {} is not running'.format(engine)  # f-strings
                return ServiceState(message=msg)

        return ServiceState()
Exemplo n.º 4
0
    def check_db(self):
        """
        Check if database service is available.

        :rtype: ServiceState
        """
        existing_cols = self.db_store.client.collection_names()
        for collection_name in self.CHECK_COLLECTIONS:
            # Existence test
            if collection_name not in existing_cols:
                msg = 'Missing collection {}'.format(collection_name)
                return ServiceState(message=msg)

            # Read test
            collection = self.db_store.get_collection(name=collection_name)
            mongo_collection = MongoCollection(collection)
            try:
                mongo_collection.find({}, limit=1)
            except Exception as exc:
                return ServiceState(message='Find error: {}'.format(exc))

        return ServiceState()
Exemplo n.º 5
0
    def check_amqp(self):
        """
        Check if amqp service is available.

        :rtype: ServiceState
        """
        try:
            with AmqpConnection(self.amqp_url) as amqp_conn:
                channel = amqp_conn._channel
                try:
                    channel.basic_publish(self.amqp_exchange, '', 'test')
                except Exception as exc:
                    msg = 'Failed to publish: {}'.format(exc)
                    return ServiceState(message=msg)

                if not amqp_conn._connection.is_open:
                    return ServiceState(message='Connection is not opened')
                if not channel.is_open:
                    return ServiceState(message='Channel is not opened')

        except ConnectionClosed as exc:
            return ServiceState(message='Failed to connect: {}'.format(exc))

        return self._check_rabbitmq_state()
Exemplo n.º 6
0
    def _check_rabbitmq_state(self):
        """
        Check amqp service state (consumers, queues).

        :rtype: ServiceState
        """
        # Check consumer presence on amqp queues
        r = self._check_rabbitmq_api('consumers')
        if r.status_code != requests.codes.ok:
            return ServiceState(message='Cannot read consumers on API')

        consumed_queues = [q['queue']['name'] for q in r.json()]
        for queue in self.CHECK_AMQP_QUEUES:
            if queue not in consumed_queues:
                msg = 'No consumer for queue {}'.format(queue)
                return ServiceState(message=msg)

        # Check queues state
        r = self._check_rabbitmq_api('queues')
        if r.status_code != requests.codes.ok:
            return ServiceState(message='Cannot read queues on API')

        queues = {q['name']: q for q in r.json()}
        for queue in self.CHECK_AMQP_QUEUES:
            if queue not in queues.keys():
                msg = 'Missing queue {}'.format(queue)
                return ServiceState(message=msg)

            if queues[queue]['state'] != 'running':
                msg = 'Queue {} is not running'.format(queue)
                return ServiceState(message=msg)

            length = queues[queue]['backing_queue_status']['len']
            if length > self.CHECK_AMQP_LIMIT_SIZE:
                msg = ('Queue {} is overloaded ({} ready messages)'.format(
                    queue, length))
                return ServiceState(message=msg)

        return ServiceState()
Exemplo n.º 7
0
    def check_engines(self):
        """
        Check if engines are available.

        :rtype: ServiceState
        """
        if not check_checkable(name=self.SYSTEMCTL_ENGINE_PREFIX):
            msg = 'Dockerised environment. Engines Not Checked.'
            ss = ServiceState(message=msg)
            ss.state = True
            return ss

        if not check_process_status(name=self.CHECK_WEBSERVER):
            return ServiceState(message='Webserver is not running')  # Derp

        for engine in self.CHECK_ENGINES:
            if not check_engine_status(name=engine):
                msg = 'Engine {} is not running'.format(engine)  # f-strings
                return ServiceState(message=msg)

        return ServiceState()
Exemplo n.º 8
0
    def check_engines(self):
        """
        Check if engines are available.

        :rtype: ServiceState
        """
        if not check_checkable(name=self.systemctl_engine_prefix):
            msg = 'Dockerised environment. Engines Not Checked.'
            ss = ServiceState(message=msg)
            ss.state = True
            return ss

        if not check_process_status(name=self.check_webserver):
            return ServiceState(message='Webserver is not running')  # Derp

        for engine in self.check_engines_list:
            if not check_engine_status(name=engine):
                msg = 'Engine {} is not running'.format(engine)  # f-strings
                return ServiceState(message=msg)

        return ServiceState()