availcheck.configs

  1# -*- coding: utf-8 -*-
  2# Copyright (C) 2024-2025 TU Dresden
  3# ralf.klammer@tu-dresden.de
  4import logging
  5
  6import os
  7
  8log = logging.getLogger(__name__)
  9
 10
 11class CheckerConfigs:
 12    # status_on_error is related to checkmk
 13    # 1 -> warning | 2 -> critical -> 2
 14    onestop4all = {
 15        "id": "onestop4all",
 16        "checks": {
 17            "main_page": {
 18                "instances": ["prod", "test"],
 19                "status_on_error": 2,
 20                "description": "Check if the main page is loaded correctly.",
 21            },
 22            "number_of_entities": {
 23                "instances": ["prod"],
 24                "status_on_error": 2,
 25                "description": "Check if the number of entities is same as expected.",
 26            },
 27            "involvement": {
 28                "instances": ["prod", "test"],
 29                "status_on_error": 2,
 30                "description": "Check if the involvement section is loaded correctly.",
 31            },
 32            "support_form": {
 33                "instances": ["prod", "test"],
 34                "status_on_error": 2,
 35                "description": "Check if the support form is loaded correctly.",
 36            },
 37            "captcha_in_support_form": {
 38                "instances": ["prod", "test"],
 39                "status_on_error": 2,
 40                "description": "Check if the CAPTCHA is executable.",
 41            },
 42            "solr": {
 43                "instances": ["prod", "test"],
 44                "status_on_error": 2,
 45                "description": "Check if the Solr login page is loaded correctly",
 46            },
 47        },
 48        "urls": {
 49            "prod": os.getenv(
 50                "O4A_PROD_URL",
 51                default="https://onestop4all.nfdi4earth.de",
 52            ),
 53            "test": os.getenv(
 54                "O4A_TEST_URL",
 55                default="https://onestop4all.test.n4e.geo.tu-dresden.de",
 56            ),
 57        },
 58    }
 59
 60    edutrain = {
 61        "id": "edutrain",
 62        "checks": {
 63            "openedx_lms": {
 64                "instances": ["prod", "test"],
 65                "status_on_error": 2,
 66                "description": "Check if the openedx LMS is loaded correctly.",
 67            },
 68            "openedx_cms": {
 69                "instances": ["prod", "test"],
 70                "status_on_error": 2,
 71                "description": "Check if the openedx CMS is loaded correctly.",
 72            },
 73            "authentication": {
 74                "instances": ["prod", "test"],
 75                "status_on_error": 2,
 76                "description": "Check if the openedx authentication is initialized correctly and button to academic id redirects correclty.",
 77            },
 78        },
 79        "urls": {
 80            "test": os.getenv(
 81                "EDU_TEST_URL",
 82                default="https://edutrain.test.n4e.geo.tu-dresden.de",
 83            ),
 84            "prod": os.getenv(
 85                "EDU_PROD_URL", default="https://edutrain.nfdi4earth.de"
 86            ),
 87        },
 88    }
 89
 90    supportapps = {
 91        "id": "supportapps",
 92        "checks": {
 93            "jupyterhub": {
 94                "instances": ["prod"],
 95                "status_on_error": 2,
 96                "description": "Check if the JupyterHub is loaded correctly.",
 97            }
 98        },
 99        "urls": {
100            "prod": os.getenv(
101                "SUPPORT_APPS_URL",
102                default="https://support-apps.n4e.geo.tu-dresden.de/",
103            )
104        },
105    }
106
107    knowledgehub = {
108        "id": "knowledgehub",
109        "checks": {
110            "sparql": {
111                "instances": ["prod", "test"],
112                "status_on_error": 2,
113                "description": "Check if the SPARQL endpoint is loaded correctly.",
114            },
115            "cordra": {
116                "instances": ["prod", "test"],
117                "status_on_error": 2,
118                "description": "Check if cordra is available",
119            },
120            "landing_page_knowledgehub": {
121                "instances": ["prod", "test"],
122                "status_on_error": 2,
123                "description": "Check if the SPARQL endpoint is loaded correctly.",
124            },
125            "more_examples_loaded": {
126                "instances": ["prod", "test"],
127                "status_on_error": 2,
128                "description": "Check if the SPARQL endpoint is loaded correctly.",
129            },
130            "table_is_displayed": {
131                "instances": ["prod", "test"],
132                "status_on_error": 2,
133                "description": "Check if the SPARQL endpoint is loaded correctly.",
134            },
135            "check_button_endpoints": {
136                "instances": ["prod", "test"],
137                "status_on_error": 2,
138                "description": "Checks if anker hrefs working",
139            },
140        },
141        "urls": {
142            "prod": os.getenv(
143                "KNOWLEDGEHUB_PROD_URL",
144                default="https://knowledgehub.nfdi4earth.de/",
145            ),
146            "test": os.getenv(
147                "KNOWLEDGEHUB_TEST_URL",
148                default="https://knowledgehub.test.n4e.geo.tu-dresden.de/",
149            ),
150        },
151    }
152
153    webapps = {
154        "id": "webapps",
155        "checks": {
156            "landing_page_webapps": {
157                "instances": ["prod"],
158                "status_on_error": 2,
159                "description": "Check if the landing page is loaded correctly.",
160            },
161            "visual_search_engine": {
162                "instances": ["prod"],
163                "status_on_error": 2,
164                "description": "Checks if the Graph Based Visual Search Engine is available",
165            },
166        },
167        "urls": {
168            "prod": os.getenv(
169                "WEBAPPS_PROD_URL", default="https://webapps.nfdi4earth.de/"
170            )
171        },
172    }
173
174    def __init__(self, service):
175        self.service = service
176        self._service_config = None
177
178    def get_checks(self, as_list=False):
179        """
180        Get the checks for a specific service.
181        """
182        if self.service_config is None:
183            return None
184        if as_list:
185            return self.service_config["checks"].keys()
186        return self.service_config["checks"]
187
188    def get_url(self, instance):
189        """
190        Get the URL for a specific instance of a service.
191        """
192        if self.service_config is None:
193            log.error(f"Service {self.service} not found.")
194        elif "urls" not in self.service_config:
195            log.error(f"Service {self.service} has no urls.")
196        elif instance not in self.service_config["urls"]:
197            log.error(f"Instance {instance} not found in {self.service} urls.")
198        else:
199            return self.service_config["urls"][instance]
200
201    @property
202    def service_config(self):
203        """
204        Get the service.
205        """
206        if self._service_config is None:
207            if self.service is None:
208                log.error(f"Service {self.service} not found.")
209            elif not getattr(self, self.service):
210                log.error(f"ServiceConfig {self.service} not found.")
211            else:
212                self._service_config = getattr(self, self.service)
213
214        return self._service_config
215
216    @property
217    def id(self):
218        """
219        Get the ID of a service.
220        """
221        return self.service_config["id"]
log = <Logger availcheck.configs (WARNING)>
class CheckerConfigs:
 12class CheckerConfigs:
 13    # status_on_error is related to checkmk
 14    # 1 -> warning | 2 -> critical -> 2
 15    onestop4all = {
 16        "id": "onestop4all",
 17        "checks": {
 18            "main_page": {
 19                "instances": ["prod", "test"],
 20                "status_on_error": 2,
 21                "description": "Check if the main page is loaded correctly.",
 22            },
 23            "number_of_entities": {
 24                "instances": ["prod"],
 25                "status_on_error": 2,
 26                "description": "Check if the number of entities is same as expected.",
 27            },
 28            "involvement": {
 29                "instances": ["prod", "test"],
 30                "status_on_error": 2,
 31                "description": "Check if the involvement section is loaded correctly.",
 32            },
 33            "support_form": {
 34                "instances": ["prod", "test"],
 35                "status_on_error": 2,
 36                "description": "Check if the support form is loaded correctly.",
 37            },
 38            "captcha_in_support_form": {
 39                "instances": ["prod", "test"],
 40                "status_on_error": 2,
 41                "description": "Check if the CAPTCHA is executable.",
 42            },
 43            "solr": {
 44                "instances": ["prod", "test"],
 45                "status_on_error": 2,
 46                "description": "Check if the Solr login page is loaded correctly",
 47            },
 48        },
 49        "urls": {
 50            "prod": os.getenv(
 51                "O4A_PROD_URL",
 52                default="https://onestop4all.nfdi4earth.de",
 53            ),
 54            "test": os.getenv(
 55                "O4A_TEST_URL",
 56                default="https://onestop4all.test.n4e.geo.tu-dresden.de",
 57            ),
 58        },
 59    }
 60
 61    edutrain = {
 62        "id": "edutrain",
 63        "checks": {
 64            "openedx_lms": {
 65                "instances": ["prod", "test"],
 66                "status_on_error": 2,
 67                "description": "Check if the openedx LMS is loaded correctly.",
 68            },
 69            "openedx_cms": {
 70                "instances": ["prod", "test"],
 71                "status_on_error": 2,
 72                "description": "Check if the openedx CMS is loaded correctly.",
 73            },
 74            "authentication": {
 75                "instances": ["prod", "test"],
 76                "status_on_error": 2,
 77                "description": "Check if the openedx authentication is initialized correctly and button to academic id redirects correclty.",
 78            },
 79        },
 80        "urls": {
 81            "test": os.getenv(
 82                "EDU_TEST_URL",
 83                default="https://edutrain.test.n4e.geo.tu-dresden.de",
 84            ),
 85            "prod": os.getenv(
 86                "EDU_PROD_URL", default="https://edutrain.nfdi4earth.de"
 87            ),
 88        },
 89    }
 90
 91    supportapps = {
 92        "id": "supportapps",
 93        "checks": {
 94            "jupyterhub": {
 95                "instances": ["prod"],
 96                "status_on_error": 2,
 97                "description": "Check if the JupyterHub is loaded correctly.",
 98            }
 99        },
100        "urls": {
101            "prod": os.getenv(
102                "SUPPORT_APPS_URL",
103                default="https://support-apps.n4e.geo.tu-dresden.de/",
104            )
105        },
106    }
107
108    knowledgehub = {
109        "id": "knowledgehub",
110        "checks": {
111            "sparql": {
112                "instances": ["prod", "test"],
113                "status_on_error": 2,
114                "description": "Check if the SPARQL endpoint is loaded correctly.",
115            },
116            "cordra": {
117                "instances": ["prod", "test"],
118                "status_on_error": 2,
119                "description": "Check if cordra is available",
120            },
121            "landing_page_knowledgehub": {
122                "instances": ["prod", "test"],
123                "status_on_error": 2,
124                "description": "Check if the SPARQL endpoint is loaded correctly.",
125            },
126            "more_examples_loaded": {
127                "instances": ["prod", "test"],
128                "status_on_error": 2,
129                "description": "Check if the SPARQL endpoint is loaded correctly.",
130            },
131            "table_is_displayed": {
132                "instances": ["prod", "test"],
133                "status_on_error": 2,
134                "description": "Check if the SPARQL endpoint is loaded correctly.",
135            },
136            "check_button_endpoints": {
137                "instances": ["prod", "test"],
138                "status_on_error": 2,
139                "description": "Checks if anker hrefs working",
140            },
141        },
142        "urls": {
143            "prod": os.getenv(
144                "KNOWLEDGEHUB_PROD_URL",
145                default="https://knowledgehub.nfdi4earth.de/",
146            ),
147            "test": os.getenv(
148                "KNOWLEDGEHUB_TEST_URL",
149                default="https://knowledgehub.test.n4e.geo.tu-dresden.de/",
150            ),
151        },
152    }
153
154    webapps = {
155        "id": "webapps",
156        "checks": {
157            "landing_page_webapps": {
158                "instances": ["prod"],
159                "status_on_error": 2,
160                "description": "Check if the landing page is loaded correctly.",
161            },
162            "visual_search_engine": {
163                "instances": ["prod"],
164                "status_on_error": 2,
165                "description": "Checks if the Graph Based Visual Search Engine is available",
166            },
167        },
168        "urls": {
169            "prod": os.getenv(
170                "WEBAPPS_PROD_URL", default="https://webapps.nfdi4earth.de/"
171            )
172        },
173    }
174
175    def __init__(self, service):
176        self.service = service
177        self._service_config = None
178
179    def get_checks(self, as_list=False):
180        """
181        Get the checks for a specific service.
182        """
183        if self.service_config is None:
184            return None
185        if as_list:
186            return self.service_config["checks"].keys()
187        return self.service_config["checks"]
188
189    def get_url(self, instance):
190        """
191        Get the URL for a specific instance of a service.
192        """
193        if self.service_config is None:
194            log.error(f"Service {self.service} not found.")
195        elif "urls" not in self.service_config:
196            log.error(f"Service {self.service} has no urls.")
197        elif instance not in self.service_config["urls"]:
198            log.error(f"Instance {instance} not found in {self.service} urls.")
199        else:
200            return self.service_config["urls"][instance]
201
202    @property
203    def service_config(self):
204        """
205        Get the service.
206        """
207        if self._service_config is None:
208            if self.service is None:
209                log.error(f"Service {self.service} not found.")
210            elif not getattr(self, self.service):
211                log.error(f"ServiceConfig {self.service} not found.")
212            else:
213                self._service_config = getattr(self, self.service)
214
215        return self._service_config
216
217    @property
218    def id(self):
219        """
220        Get the ID of a service.
221        """
222        return self.service_config["id"]
CheckerConfigs(service)
175    def __init__(self, service):
176        self.service = service
177        self._service_config = None
onestop4all = {'id': 'onestop4all', 'checks': {'main_page': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the main page is loaded correctly.'}, 'number_of_entities': {'instances': ['prod'], 'status_on_error': 2, 'description': 'Check if the number of entities is same as expected.'}, 'involvement': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the involvement section is loaded correctly.'}, 'support_form': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the support form is loaded correctly.'}, 'captcha_in_support_form': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the CAPTCHA is executable.'}, 'solr': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the Solr login page is loaded correctly'}}, 'urls': {'prod': 'https://onestop4all.nfdi4earth.de', 'test': 'https://onestop4all.test.n4e.geo.tu-dresden.de'}}
edutrain = {'id': 'edutrain', 'checks': {'openedx_lms': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the openedx LMS is loaded correctly.'}, 'openedx_cms': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the openedx CMS is loaded correctly.'}, 'authentication': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the openedx authentication is initialized correctly and button to academic id redirects correclty.'}}, 'urls': {'test': 'https://edutrain.test.n4e.geo.tu-dresden.de', 'prod': 'https://edutrain.nfdi4earth.de'}}
supportapps = {'id': 'supportapps', 'checks': {'jupyterhub': {'instances': ['prod'], 'status_on_error': 2, 'description': 'Check if the JupyterHub is loaded correctly.'}}, 'urls': {'prod': 'https://support-apps.n4e.geo.tu-dresden.de/'}}
knowledgehub = {'id': 'knowledgehub', 'checks': {'sparql': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the SPARQL endpoint is loaded correctly.'}, 'cordra': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if cordra is available'}, 'landing_page_knowledgehub': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the SPARQL endpoint is loaded correctly.'}, 'more_examples_loaded': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the SPARQL endpoint is loaded correctly.'}, 'table_is_displayed': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Check if the SPARQL endpoint is loaded correctly.'}, 'check_button_endpoints': {'instances': ['prod', 'test'], 'status_on_error': 2, 'description': 'Checks if anker hrefs working'}}, 'urls': {'prod': 'https://knowledgehub.nfdi4earth.de/', 'test': 'https://knowledgehub.test.n4e.geo.tu-dresden.de/'}}
webapps = {'id': 'webapps', 'checks': {'landing_page_webapps': {'instances': ['prod'], 'status_on_error': 2, 'description': 'Check if the landing page is loaded correctly.'}, 'visual_search_engine': {'instances': ['prod'], 'status_on_error': 2, 'description': 'Checks if the Graph Based Visual Search Engine is available'}}, 'urls': {'prod': 'https://webapps.nfdi4earth.de/'}}
service
def get_checks(self, as_list=False):
179    def get_checks(self, as_list=False):
180        """
181        Get the checks for a specific service.
182        """
183        if self.service_config is None:
184            return None
185        if as_list:
186            return self.service_config["checks"].keys()
187        return self.service_config["checks"]

Get the checks for a specific service.

def get_url(self, instance):
189    def get_url(self, instance):
190        """
191        Get the URL for a specific instance of a service.
192        """
193        if self.service_config is None:
194            log.error(f"Service {self.service} not found.")
195        elif "urls" not in self.service_config:
196            log.error(f"Service {self.service} has no urls.")
197        elif instance not in self.service_config["urls"]:
198            log.error(f"Instance {instance} not found in {self.service} urls.")
199        else:
200            return self.service_config["urls"][instance]

Get the URL for a specific instance of a service.

service_config
202    @property
203    def service_config(self):
204        """
205        Get the service.
206        """
207        if self._service_config is None:
208            if self.service is None:
209                log.error(f"Service {self.service} not found.")
210            elif not getattr(self, self.service):
211                log.error(f"ServiceConfig {self.service} not found.")
212            else:
213                self._service_config = getattr(self, self.service)
214
215        return self._service_config

Get the service.

id
217    @property
218    def id(self):
219        """
220        Get the ID of a service.
221        """
222        return self.service_config["id"]

Get the ID of a service.