add health check
This commit is contained in:
24
SatiAPI.py
24
SatiAPI.py
@@ -16,7 +16,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|||||||
class SatiAPI:
|
class SatiAPI:
|
||||||
"""A API wrapper for Satisfactory dedicated server"""
|
"""A API wrapper for Satisfactory dedicated server"""
|
||||||
__AUTHOR__ = 'anima'
|
__AUTHOR__ = 'anima'
|
||||||
__VERSION__ = '0.1.0'
|
__VERSION__ = '0.2.1'
|
||||||
|
|
||||||
def __init__(self, host: str = None, port: int = 7777, token: str = None, conffile: str = 'conf.yml', logfile: str = 'SatiAPI.log', loglevel: int = 20) -> None:
|
def __init__(self, host: str = None, port: int = 7777, token: str = None, conffile: str = 'conf.yml', logfile: str = 'SatiAPI.log', loglevel: int = 20) -> None:
|
||||||
"""create a wrapper for satisfactory dedicated server
|
"""create a wrapper for satisfactory dedicated server
|
||||||
@@ -165,7 +165,12 @@ class SatiAPI:
|
|||||||
|
|
||||||
response = requests.post(f'https://{self.host}:7777/api/v1', headers=headers, json=payload, verify=False)
|
response = requests.post(f'https://{self.host}:7777/api/v1', headers=headers, json=payload, verify=False)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return json.loads(response.text)['data']
|
json_response = json.loads(response.text)
|
||||||
|
if 'data' in json_response:
|
||||||
|
return json_response
|
||||||
|
else:
|
||||||
|
self._log.error(f'wrong response data {json_response=}')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self._log.error(f'non successfull response {response.content} [{response.status_code}]')
|
self._log.error(f'non successfull response {response.content} [{response.status_code}]')
|
||||||
self._log.debug(f'{response.request.url=}')
|
self._log.debug(f'{response.request.url=}')
|
||||||
@@ -221,7 +226,20 @@ class SatiAPI:
|
|||||||
"""
|
"""
|
||||||
return self.__query('QueryServerState')
|
return self.__query('QueryServerState')
|
||||||
|
|
||||||
|
def get_health(self, ClientCustomData: str = '') -> dict:
|
||||||
|
"""get health check
|
||||||
|
|
||||||
|
:param ClientCustomData: Custom Data passed from the Game Client or Third Party service. Not used by vanilla Dedicated Servers
|
||||||
|
:type ClientCustomData: string
|
||||||
|
:return: full return from server
|
||||||
|
:rtpye: dict
|
||||||
|
"""
|
||||||
|
data = dict()
|
||||||
|
data['ClientCustomData'] = ClientCustomData
|
||||||
|
|
||||||
|
return self.__query('HealthCheck', data)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sati = SatiAPI(loglevel=10)
|
sati = SatiAPI(loglevel=10)
|
||||||
print('Verbundene Spieler: ', sati.get_status()['serverGameState']['numConnectedPlayers'])
|
# print('Verbundene Spieler: ', sati.get_status()['serverGameState']['numConnectedPlayers'])
|
||||||
|
print(sati.health_check())
|
||||||
Reference in New Issue
Block a user