Fix formatting issues in MonitorType.ts,

MonitorCriteriaInstance.ts, ApiMonitor.ts,
CriteriaFilter.tsx, MonitorStep.tsx,
MonitorService.ts, WebsiteMonitor.ts, and
PingMonitor.ts
This commit is contained in:
Simon Larsen 2023-11-22 16:40:19 +00:00
parent b375e8341d
commit 61d3604a9d
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
11 changed files with 87 additions and 86 deletions

View File

@ -156,8 +156,10 @@ export default class MonitorStep extends DatabaseProperty {
return 'Request Type is required';
}
if(monitorType === MonitorType.Port && !value.data.monitorDestinationPort) {
if (
monitorType === MonitorType.Port &&
!value.data.monitorDestinationPort
) {
return 'Port is required';
}
@ -172,7 +174,9 @@ export default class MonitorStep extends DatabaseProperty {
id: this.data.id,
monitorDestination:
this.data?.monitorDestination?.toJSON() || undefined,
monitorDestinationPort: this.data?.monitorDestinationPort?.toJSON() || undefined,
monitorDestinationPort:
this.data?.monitorDestinationPort?.toJSON() ||
undefined,
monitorCriteria: this.data.monitorCriteria.toJSON(),
requestType: this.data.requestType,
requestHeaders: this.data.requestHeaders || undefined,
@ -212,8 +216,6 @@ export default class MonitorStep extends DatabaseProperty {
);
}
if (
json &&
json['monitorDestination'] &&
@ -236,9 +238,11 @@ export default class MonitorStep extends DatabaseProperty {
);
}
const monitorDestinationPort: Port | undefined = json['monitorDestinationPort'] ? Port.fromJSON(json['monitorDestinationPort'] as JSONObject) : undefined;
const monitorDestinationPort: Port | undefined = json[
'monitorDestinationPort'
]
? Port.fromJSON(json['monitorDestinationPort'] as JSONObject)
: undefined;
if (!json['monitorCriteria']) {
throw new BadDataException('Invalid monitor criteria');

View File

@ -69,7 +69,7 @@ export class MonitorTypeHelper {
title: 'Port',
description:
'This monitor types lets you monitor any TCP or UDP port.',
}
},
];
return monitorTypeProps;

View File

@ -219,7 +219,7 @@ const MonitorStepElement: FunctionComponent<ComponentProps> = (
<Input
initialValue={monitorStep?.data?.monitorDestinationPort?.toString()}
onChange={(value: string) => {
const port = new Port(value);
const port: Port = new Port(value);
monitorStep.setPort(port);
setMonitorStep(
MonitorStep.clone(monitorStep)

View File

@ -104,7 +104,7 @@ const MonitorStepElement: FunctionComponent<ComponentProps> = (
'Port of the resource you would like us to ping.',
fieldType: FieldType.Port,
placeholder: 'No port entered',
}
},
];
} else if (props.monitorType === MonitorType.IP) {
fields = [

View File

@ -95,12 +95,11 @@ export default class ApiMonitor {
isOnlineCheckRequest?: boolean | undefined;
}
): Promise<APIResponse | null> {
if(!options){
if (!options) {
options = {};
}
if(options?.currentRetryCount === undefined){
if (options?.currentRetryCount === undefined) {
options.currentRetryCount = 1;
}

View File

@ -77,12 +77,11 @@ export default class PingMonitor {
host: Hostname | IPv4 | IPv6 | URL,
pingOptions?: PingOptions
): Promise<PingResponse | null> {
if(!pingOptions){
if (!pingOptions) {
pingOptions = {};
}
if(pingOptions?.currentRetryCount === undefined){
if (pingOptions?.currentRetryCount === undefined) {
pingOptions.currentRetryCount = 1;
}

View File

@ -99,7 +99,6 @@ export default class PortMonitor {
port: Port,
pingOptions?: PingOptions
): Promise<PortMonitorResponse | null> {
if (!pingOptions) {
pingOptions = {};
}
@ -130,19 +129,22 @@ export default class PortMonitor {
}
logger.info(
`Pinging host: ${pingOptions?.monitorId?.toString()} ${hostAddress}:${port.toString()} - Retry: ${pingOptions?.currentRetryCount
`Pinging host: ${pingOptions?.monitorId?.toString()} ${hostAddress}:${port.toString()} - Retry: ${
pingOptions?.currentRetryCount
}`
);
try {
// Ping a host with port
const promiseResult = new Promise((resolve, reject) => {
const promiseResult: Promise<PositiveNumber> = new Promise(
(resolve: Function, reject: Function) => {
const startTime: [number, number] = process.hrtime();
const socket = new net.Socket();
const socket: net.Socket = new net.Socket();
const timeout: number = pingOptions?.timeout?.toNumber() || 5000;
const timeout: number =
pingOptions?.timeout?.toNumber() || 5000;
socket.setTimeout(timeout);
@ -150,14 +152,13 @@ export default class PortMonitor {
throw new BadDataException('Port is not specified');
}
let hasPromiseResolved: boolean = false;
socket.connect(port.toNumber(), hostAddress, () => {
const endTime: [number, number] = process.hrtime(startTime);
const responseTimeInMS: PositiveNumber = new PositiveNumber(
const endTime: [number, number] =
process.hrtime(startTime);
const responseTimeInMS: PositiveNumber =
new PositiveNumber(
(endTime[0] * 1000000000 + endTime[1]) / 1000000
);
@ -172,26 +173,25 @@ export default class PortMonitor {
hasPromiseResolved = true;
return;
});
socket.on('timeout', () => {
socket.destroy();
logger.info('Ping timeout');
if (!hasPromiseResolved) {
reject(new UnableToReachServer('Ping timeout'));
}
hasPromiseResolved = true;
return;
});
socket.on('error', error => {
socket.on('error', (error: Error) => {
socket.destroy();
logger.info('Could not connect to: ' + host + ':' + port);
logger.info(
'Could not connect to: ' + host + ':' + port
);
if (!hasPromiseResolved) {
reject(error);
@ -200,7 +200,8 @@ export default class PortMonitor {
hasPromiseResolved = true;
return;
});
});
}
);
const responseTimeInMS: PositiveNumber =
(await promiseResult) as PositiveNumber;

View File

@ -97,16 +97,14 @@ export default class WebsiteMonitor {
isOnlineCheckRequest?: boolean | undefined;
}
): Promise<ProbeWebsiteResponse | null> {
if(!options){
if (!options) {
options = {};
}
if(options?.currentRetryCount === undefined){
if (options?.currentRetryCount === undefined) {
options.currentRetryCount = 1;
}
let requestType: HTTPMethod = HTTPMethod.GET;
if (options.isHeadRequest) {