mirror of https://github.com/interlegis/sapl.git
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							49 lines
						
					
					
						
							1.1 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							49 lines
						
					
					
						
							1.1 KiB
						
					
					
				| from flask import Flask | |
| import requests | |
| import psycopg2 | |
| import json | |
| from sapl.settings import DATABASES, USE_SOLR, SOLR_URL | |
| 
 | |
| 
 | |
| app = Flask(__name__) | |
| 
 | |
| 
 | |
| @app.route('/health') | |
| def health(): | |
|     try: | |
|         db = DATABASES['default'] | |
|         conn = psycopg2.connect(host=db['HOST'], | |
|                                 user=db['USER'], | |
|                                 password=db['PASSWORD'], | |
|                                 database=db['NAME'], | |
|                                 port=db['PORT']) | |
|         cursor = conn.cursor() | |
|         cursor.execute("SELECT 1;") | |
|         resp = {'DATABASE': 'OK'} | |
|     except Exception as e: | |
|         resp = {'DATABASE': 'ERROR'} | |
|     finally: | |
|         if cursor: | |
|             cursor.close() | |
|             conn.close() | |
| 
 | |
|     if USE_SOLR: | |
|         r = requests.get(SOLR_URL) | |
|         if r.ok: | |
|             resp.update({'SEARCH_ENGINE': 'OK'}) | |
|         else: | |
|             resp.update({'SEARCH_ENGINE': 'ERROR'}) | |
| 
 | |
|     else: | |
|         resp.update({'SEARCH_ENGINE': 'NOT_ENABLED'}) | |
| 
 | |
|     return json.dumps(resp) | |
| 
 | |
| 
 | |
| @app.route('/ping') | |
| def ping(): | |
|     return "pong" | |
| 
 | |
| 
 | |
| if __name__ == '__main__': | |
|     app.run() |