Skip to content

Commit

Permalink
v1.2.1: Fix handling of server_to and improve error messages.
Browse files Browse the repository at this point in the history
Converted server_to to string in network checks and updated its type in the model. Enhanced JS error handling by parsing JSON and showing warnings. Fixed removal of single quotes in check names.
  • Loading branch information
Aidaho12 committed Nov 15, 2024
1 parent 3922fb9 commit 5b0a779
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/modules/roxywi/class_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class CheckGroup(BaseModel):

class NettoolsRequest(BaseModel):
server_from: Optional[EscapedString] = None
server_to: Optional[EscapedString] = None
server_to: Optional[Union[IPvAnyAddress, DomainName]] = None
port: Optional[Annotated[int, Gt(1), Le(65535)]] = None
action: Optional[Literal['ping', 'trace']] = None
dns_name: Optional[DomainName] = None
Expand Down
4 changes: 2 additions & 2 deletions app/routes/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ def nettools():
def nettools_check(check, body: NettoolsRequest):
if check == 'icmp':
try:
return nettools_mod.ping_from_server(body.server_from, body.server_to, body.action)
return nettools_mod.ping_from_server(body.server_from, str(body.server_to), body.action)
except Exception as e:
return ErrorResponse(error=f'Cannot ping: {e}').model_dump(mode='json'), 500
elif check == 'tcp':
try:
return nettools_mod.telnet_from_server(body.server_from, body.server_to, body.port)
return nettools_mod.telnet_from_server(body.server_from, str(body.server_to), body.port)
except Exception as e:
return ErrorResponse(error=f'Cannot check port: {e}').model_dump(mode='json'), 500
elif check == 'dns':
Expand Down
9 changes: 7 additions & 2 deletions app/static/js/nettools.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $( function() {
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.status === 'failed') {
toastr.error(data);
toastr.warning(data);
} else {
toastr.clear();
$('#ajax-nettools').html('<div class="ping_pre">' + data + '</div>');
Expand Down Expand Up @@ -94,7 +94,12 @@ $( function() {
contentType: "application/json; charset=utf-8",
xhrFields: {
onprogress: function (e) {
$('#ajax-nettools').html(e.currentTarget.responseText);
try {
data = JSON.parse(e.currentTarget.responseText);
toastr.warning(data.error);
} catch (error) {
$('#ajax-nettools').html(e.currentTarget.responseText);
}
}
},
dataType: 'text',
Expand Down
1 change: 1 addition & 0 deletions app/views/check/checks_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get(self, query: GroupQuery) -> Union[SmonTcpCheck, SmonHttpCheck, SmonDnsCh
smon_id = model_to_dict(check, max_depth=1)
check_json.update(smon_id['smon_id'])
check_json.update(model_to_dict(check, recurse=False))
check_json['name'] = check_json['name'].replace("'", "")
check_json['checks'][i]['smon_id']['name'] = check.smon_id.name.replace("'", "")
if check_json['checks'][i]['smon_id']['check_type'] == 'http':
check_json['checks'][i]['accepted_status_codes'] = int(check_json['checks'][i]['accepted_status_codes'])
Expand Down
1 change: 1 addition & 0 deletions app/views/check/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def get(self, multi_check_id: int, query: GroupQuery) -> object:
smon_id = model_to_dict(check, max_depth=1)
check_json.update(smon_id['smon_id'])
check_json.update(model_to_dict(check, recurse=False))
check_json['name'] = check_json['name'].replace("'", "")
check_json['checks'][i]['smon_id']['name'] = check.smon_id.name.replace("'", "")
if check_json['checks'][i]['smon_id']['check_type'] == 'http':
check_json['checks'][i]['accepted_status_codes'] = int(check_json['checks'][i]['accepted_status_codes'])
Expand Down

0 comments on commit 5b0a779

Please sign in to comment.