@ -12,15 +12,17 @@ import app.modules.db.service as service_sql
import app . modules . db . checker as checker_sql
import app . modules . roxywi . common as roxywi_common
from app . middleware import get_user_params , page_for_admin , check_group , check_services
from app . modules . roxywi . class_models import Checker
from app . modules . roxywi . class_models import Checker , BaseResponse
from app . modules . db . db_model import CheckerSetting
from app . modules . common . common_classes import SupportClass
class CheckerView ( MethodView ) :
methods = [ " GET " , " POST " ]
decorators = [ jwt_required ( ) , get_user_params ( ) , check_services , page_for_admin ( level = 3 ) , check_group ( ) ]
def get ( self , service : Literal [ ' haproxy ' , ' nginx ' , ' apache ' , ' keepalived ' ] , server_id : Union [ int , str ] ) :
@staticmethod
def get ( service : Literal [ ' haproxy ' , ' nginx ' , ' apache ' , ' keepalived ' ] , server_id : Union [ int , str ] ) :
"""
Retrieves the status of specific checker services .
- - -
@ -84,6 +86,11 @@ class CheckerView(MethodView):
"""
service_id = service_sql . select_service_id_by_slug ( service )
try :
server_id = SupportClass ( ) . return_server_ip_or_id ( server_id )
except Exception as e :
return roxywi_common . handler_exceptions_for_json_data ( e , ' ' )
try :
server = server_sql . get_server_by_id ( server_id )
except Exception as e :
@ -107,4 +114,92 @@ class CheckerView(MethodView):
@validate ( body = Checker )
def post ( self , service : Literal [ ' haproxy ' , ' nginx ' , ' apache ' , ' keepalived ' ] , server_id : Union [ int , str ] , body : Checker ) :
. . .
"""
Update the Tools settings of specific service .
- - -
tags :
- Service Tools
parameters :
- in : path
name : service
type : string
required : true
description : The type of service ( haproxy , nginx , apache , keepalived )
- in : path
name : server_id
type : string
required : true
description : The ID or IP of the server
- in : body
required : true
name : body
description : The settings of the checker service
schema :
type : object
properties :
auto_start :
type : ' integer '
description : ' Sets if Auto start tools is enabled for this service '
backend_alert :
type : ' integer '
description : ' Sets the Alert status for backends. Only for HAProxy and Keepalived services '
checker :
type : ' integer '
description : ' Sets if Checker tools is enabled for this service '
email :
type : ' integer '
description : ' Sets the status flag for email notifications '
maxconn_alert :
type : ' integer '
description : ' Sets the Alert status for max connections. Only for HAProxy service '
metrics :
type : ' integer '
description : ' Sets if Metrics tools is enabled for this service '
mm_id :
type : ' integer '
description : ' Sets the Identifier for Mattermost notifications '
pd_id :
type : ' integer '
description : ' Sets the Identifier for PagerDuty notifications '
service_alert :
type : ' integer '
description : ' Sets the Alert status for services '
slack_id :
type : ' integer '
description : ' Sets the Identifier for Slack notifications '
telegram_id :
type : ' integer '
description : ' Sets the Identifier for Telegram notifications '
responses :
201 :
description : Successful operation , settings updated
default :
description : Unexpected error
"""
service_id = service_sql . select_service_id_by_slug ( service )
try :
server_id = SupportClass ( ) . return_server_ip_or_id ( server_id )
except Exception as e :
return roxywi_common . handler_exceptions_for_json_data ( e , ' ' )
try :
server = server_sql . get_server_by_id ( server_id )
except Exception as e :
return roxywi_common . handler_exceptions_for_json_data ( e , ' Cannot find server ' )
try :
roxywi_common . is_user_has_access_to_group ( g . user_params [ ' user_id ' ] , server . group_id )
except Exception as e :
return roxywi_common . handler_exceptions_for_json_data ( e , ' ' )
kwargs = body . model_dump ( mode = ' json ' , exclude = { ' metrics ' , ' auto_start ' , ' checker ' } )
try :
checker_sql . update_checker_setting_for_server ( service_id , server_id , * * kwargs )
except Exception as e :
return roxywi_common . handler_exceptions_for_json_data ( e , ' Cannot update Checker settings ' )
try :
service_sql . update_hapwi_server ( server_id , body . checker , body . metrics , body . auto_start , service )
except Exception as e :
return roxywi_common . handler_exceptions_for_json_data ( e , ' Cannot update Service settings ' )
return BaseResponse ( ) . model_dump ( ) , 201