Analysis ******** The monitored services are represented by instances of :mod:`django:django.apps`. Hence, per type of monitored service a :class:`~django:django.apps.AppConfig` has to be implemented. For the Happyface project the :class:`~Happyface4.app_configs.AnalysisConfig` is provided, basing on the :class:`~django:django.apps.AppConfig` class. It provides convenient methods to create analyses (and their instances) and is described in the following. .. tip:: We *really* recommend using :class:`~Happyface4.app_configs.AnalysisConfig` as a base class for every new module. .. _analysis-config: The :class:`~Happyface4.app_configs.AnalysisConfig` class ========================================================= The preferred way of writing a new analysis is by inheriting from :class:`~Happyface4.app_configs.AnalysisConfig`. This class provides the general structure for all analyses and should be used for all new or rewrites of modules. An analysis inheriting from this class is expected to implement the following methods: - :meth:`~Happyface4.app_configs.AnalysisConfig.extract_data_from_url` This method should implement the retrieval of the data from the external source. It could e.g. get data from an elasticsearch index (:meth:`~Happyface4.helpers.get_data_from_elasticsearch`). The method is expected to return a :class:`dict`, a list of :class:`dicts ` or a :class:`list` containing the data. Analyses that are purely trigger-based (e.g. ``cms_siteconf_status``, ``vobox_cert_validity``) may simply return a truthy value. - :meth:`~Happyface4.app_configs.AnalysisConfig.save_data_to_db` This method receives the data from :meth:`~Happyface4.app_configs.AnalysisConfig.extract_data_from_url`, possibly processes it and saves it to the :doc:`database `. For this, the analysis has to implement the :doc:`database ` models as :mod:`django:django.db.models`. The method is expected to return a tuple of :ref:`instance status` and a :class:`~datetime.datetime` object. - :meth:`~Happyface4.app_configs.AnalysisConfig.retrieve_data_from_db` This method retrieves the data from the :doc:`database `. It returns a :class:`dict` or a :class:`~django.db.models.query.QuerySet` containing the data already prepared for use within the :ref:`template