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 }, 136 "urls": { 137 "prod": os.getenv( 138 "KNOWLEDGEHUB_PROD_URL", 139 default="https://knowledgehub.nfdi4earth.de/", 140 ), 141 "test": os.getenv( 142 "KNOWLEDGEHUB_TEST_URL", 143 default="https://knowledgehub.test.n4e.geo.tu-dresden.de/", 144 ), 145 }, 146 } 147 148 webapps = { 149 "id": "webapps", 150 "checks": { 151 "landing_page_webapps": { 152 "instances": ["prod"], 153 "status_on_error": 2, 154 "description": "Check if the landing page is loaded correctly.", 155 }, 156 "visual_search_engine": { 157 "instances": ["prod"], 158 "status_on_error": 2, 159 "description": "Checks if the Graph Based Visual Search Engine is available", 160 }, 161 }, 162 "urls": { 163 "prod": os.getenv( 164 "WEBAPPS_PROD_URL", default="https://webapps.nfdi4earth.de/" 165 ) 166 }, 167 } 168 169 def __init__(self, service): 170 self.service = service 171 self._service_config = None 172 173 def get_checks(self, as_list=False): 174 """ 175 Get the checks for a specific service. 176 """ 177 if self.service_config is None: 178 return None 179 if as_list: 180 return self.service_config["checks"].keys() 181 return self.service_config["checks"] 182 183 def get_url(self, instance): 184 """ 185 Get the URL for a specific instance of a service. 186 """ 187 if self.service_config is None: 188 log.error(f"Service {self.service} not found.") 189 elif "urls" not in self.service_config: 190 log.error(f"Service {self.service} has no urls.") 191 elif instance not in self.service_config["urls"]: 192 log.error(f"Instance {instance} not found in {self.service} urls.") 193 else: 194 return self.service_config["urls"][instance] 195 196 @property 197 def service_config(self): 198 """ 199 Get the service. 200 """ 201 if self._service_config is None: 202 if self.service is None: 203 log.error(f"Service {self.service} not found.") 204 elif not getattr(self, self.service): 205 log.error(f"ServiceConfig {self.service} not found.") 206 else: 207 self._service_config = getattr(self, self.service) 208 209 return self._service_config 210 211 @property 212 def id(self): 213 """ 214 Get the ID of a service. 215 """ 216 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 }, 137 "urls": { 138 "prod": os.getenv( 139 "KNOWLEDGEHUB_PROD_URL", 140 default="https://knowledgehub.nfdi4earth.de/", 141 ), 142 "test": os.getenv( 143 "KNOWLEDGEHUB_TEST_URL", 144 default="https://knowledgehub.test.n4e.geo.tu-dresden.de/", 145 ), 146 }, 147 } 148 149 webapps = { 150 "id": "webapps", 151 "checks": { 152 "landing_page_webapps": { 153 "instances": ["prod"], 154 "status_on_error": 2, 155 "description": "Check if the landing page is loaded correctly.", 156 }, 157 "visual_search_engine": { 158 "instances": ["prod"], 159 "status_on_error": 2, 160 "description": "Checks if the Graph Based Visual Search Engine is available", 161 }, 162 }, 163 "urls": { 164 "prod": os.getenv( 165 "WEBAPPS_PROD_URL", default="https://webapps.nfdi4earth.de/" 166 ) 167 }, 168 } 169 170 def __init__(self, service): 171 self.service = service 172 self._service_config = None 173 174 def get_checks(self, as_list=False): 175 """ 176 Get the checks for a specific service. 177 """ 178 if self.service_config is None: 179 return None 180 if as_list: 181 return self.service_config["checks"].keys() 182 return self.service_config["checks"] 183 184 def get_url(self, instance): 185 """ 186 Get the URL for a specific instance of a service. 187 """ 188 if self.service_config is None: 189 log.error(f"Service {self.service} not found.") 190 elif "urls" not in self.service_config: 191 log.error(f"Service {self.service} has no urls.") 192 elif instance not in self.service_config["urls"]: 193 log.error(f"Instance {instance} not found in {self.service} urls.") 194 else: 195 return self.service_config["urls"][instance] 196 197 @property 198 def service_config(self): 199 """ 200 Get the service. 201 """ 202 if self._service_config is None: 203 if self.service is None: 204 log.error(f"Service {self.service} not found.") 205 elif not getattr(self, self.service): 206 log.error(f"ServiceConfig {self.service} not found.") 207 else: 208 self._service_config = getattr(self, self.service) 209 210 return self._service_config 211 212 @property 213 def id(self): 214 """ 215 Get the ID of a service. 216 """ 217 return self.service_config["id"]
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.'}}, '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/'}}
def
get_checks(self, as_list=False):
174 def get_checks(self, as_list=False): 175 """ 176 Get the checks for a specific service. 177 """ 178 if self.service_config is None: 179 return None 180 if as_list: 181 return self.service_config["checks"].keys() 182 return self.service_config["checks"]
Get the checks for a specific service.
def
get_url(self, instance):
184 def get_url(self, instance): 185 """ 186 Get the URL for a specific instance of a service. 187 """ 188 if self.service_config is None: 189 log.error(f"Service {self.service} not found.") 190 elif "urls" not in self.service_config: 191 log.error(f"Service {self.service} has no urls.") 192 elif instance not in self.service_config["urls"]: 193 log.error(f"Instance {instance} not found in {self.service} urls.") 194 else: 195 return self.service_config["urls"][instance]
Get the URL for a specific instance of a service.
service_config
197 @property 198 def service_config(self): 199 """ 200 Get the service. 201 """ 202 if self._service_config is None: 203 if self.service is None: 204 log.error(f"Service {self.service} not found.") 205 elif not getattr(self, self.service): 206 log.error(f"ServiceConfig {self.service} not found.") 207 else: 208 self._service_config = getattr(self, self.service) 209 210 return self._service_config
Get the service.