ssl
This commit is contained in:
1 parent
ee04ac2b98
commit
686b96d4b3
5 files changed
+50
-6
No files matched your search
@@ -69,6 +69,7 @@ const UptimeDetailsPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const stats = response?.data?.stats || null;
|
const stats = response?.data?.stats || null;
|
||||||
|
console.log(stats);
|
||||||
const avgResponseTime = stats?.avgResponseTime || 0;
|
const avgResponseTime = stats?.avgResponseTime || 0;
|
||||||
const maxResponseTime = stats?.maxResponseTime || 0;
|
const maxResponseTime = stats?.maxResponseTime || 0;
|
||||||
|
|
||||||
@@ -132,6 +133,14 @@ const UptimeDetailsPage = () => {
|
|||||||
stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"
|
stats?.lastResponseTime ? `${stats?.lastResponseTime} ms` : "N/A"
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<StatBox
|
||||||
|
title="Certificate Expiry"
|
||||||
|
subtitle={
|
||||||
|
stats?.certificateExpiry
|
||||||
|
? new Date(stats.certificateExpiry).toLocaleString()
|
||||||
|
: "N/A"
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<HeaderRange
|
<HeaderRange
|
||||||
loading={isValidating || upIsValidating || downIsValidating}
|
loading={isValidating || upIsValidating || downIsValidating}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export interface IMonitorStats {
|
|||||||
currentStreak: number;
|
currentStreak: number;
|
||||||
currentStreakStatus: MonitorStatus;
|
currentStreakStatus: MonitorStatus;
|
||||||
currentStreakStartedAt: number;
|
currentStreakStartedAt: number;
|
||||||
|
certificateExpiry?: Date | null;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ export interface IMonitorStats extends mongoose.Document {
|
|||||||
currentStreakStartedAt: number;
|
currentStreakStartedAt: number;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
certificateExpiry?: Date | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MonitorStatsSchema = new Schema<IMonitorStats>(
|
const MonitorStatsSchema = new Schema<IMonitorStats>(
|
||||||
@@ -70,6 +71,7 @@ const MonitorStatsSchema = new Schema<IMonitorStats>(
|
|||||||
enum: MonitorStatuses,
|
enum: MonitorStatuses,
|
||||||
},
|
},
|
||||||
currentStreakStartedAt: { type: Number, required: false },
|
currentStreakStartedAt: { type: Number, required: false },
|
||||||
|
certificateExpiry: { type: Date, required: false },
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import type {
|
|||||||
ICaptureInfo,
|
ICaptureInfo,
|
||||||
ILighthouseResult,
|
ILighthouseResult,
|
||||||
} from "@/db/models/index.js";
|
} from "@/db/models/index.js";
|
||||||
|
import type { TLSSocket, DetailedPeerCertificate } from "node:tls";
|
||||||
|
import type { ClientRequest } from "node:http";
|
||||||
import { MonitorType, MonitorStatus } from "@/db/models/monitors/Monitor.js";
|
import { MonitorType, MonitorStatus } from "@/db/models/monitors/Monitor.js";
|
||||||
import ApiError from "@/utils/ApiError.js";
|
import ApiError from "@/utils/ApiError.js";
|
||||||
import { config } from "@/config/index.js";
|
import { config } from "@/config/index.js";
|
||||||
@@ -44,6 +46,7 @@ export interface StatusResponse<TPayload = unknown> {
|
|||||||
responseTime: number;
|
responseTime: number;
|
||||||
timings?: GotTimings;
|
timings?: GotTimings;
|
||||||
payload?: TPayload;
|
payload?: TPayload;
|
||||||
|
certificateExpiry?: Date | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NetworkService implements INetworkService {
|
class NetworkService implements INetworkService {
|
||||||
@@ -68,6 +71,7 @@ class NetworkService implements INetworkService {
|
|||||||
private buildStatusResponse = <T>(
|
private buildStatusResponse = <T>(
|
||||||
monitor: IMonitor,
|
monitor: IMonitor,
|
||||||
response: Response<T> | null,
|
response: Response<T> | null,
|
||||||
|
certificateExpiry: Date | null,
|
||||||
error: any | null
|
error: any | null
|
||||||
): StatusResponse<T> => {
|
): StatusResponse<T> => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -80,6 +84,7 @@ class NetworkService implements INetworkService {
|
|||||||
message: error.message || "Network error",
|
message: error.message || "Network error",
|
||||||
responseTime: 0,
|
responseTime: 0,
|
||||||
timings: { phases: {} } as GotTimings,
|
timings: { phases: {} } as GotTimings,
|
||||||
|
certificateExpiry,
|
||||||
};
|
};
|
||||||
if (error instanceof HTTPError) {
|
if (error instanceof HTTPError) {
|
||||||
statusResponse.code = error?.response?.statusCode || this.NETWORK_ERROR;
|
statusResponse.code = error?.response?.statusCode || this.NETWORK_ERROR;
|
||||||
@@ -99,6 +104,7 @@ class NetworkService implements INetworkService {
|
|||||||
message: response?.statusMessage || "",
|
message: response?.statusMessage || "",
|
||||||
responseTime: response?.timings?.phases?.total || 0,
|
responseTime: response?.timings?.phases?.total || 0,
|
||||||
timings: response?.timings || ({ phases: {} } as GotTimings),
|
timings: response?.timings || ({ phases: {} } as GotTimings),
|
||||||
|
certificateExpiry,
|
||||||
};
|
};
|
||||||
|
|
||||||
return statusResponse;
|
return statusResponse;
|
||||||
@@ -111,11 +117,35 @@ class NetworkService implements INetworkService {
|
|||||||
throw new Error("No URL provided");
|
throw new Error("No URL provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let certificateExpiry: Date | null = null;
|
||||||
try {
|
try {
|
||||||
const response: Response = await this.client(url);
|
const req: any = this.client(url);
|
||||||
return this.buildStatusResponse(monitor, response, null);
|
req.on("request", (nodeReq: ClientRequest) => {
|
||||||
|
nodeReq.on("socket", (socket: TLSSocket) => {
|
||||||
|
const capture = () => {
|
||||||
|
const cert = socket.getPeerCertificate(true);
|
||||||
|
if (cert && cert.valid_to) {
|
||||||
|
certificateExpiry = new Date(cert.valid_to);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
capture();
|
||||||
|
socket.once("secureConnect", capture);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const response: Response = await req;
|
||||||
|
return this.buildStatusResponse(
|
||||||
|
monitor,
|
||||||
|
response,
|
||||||
|
certificateExpiry,
|
||||||
|
null
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.buildStatusResponse(monitor, null, error);
|
return this.buildStatusResponse(
|
||||||
|
monitor,
|
||||||
|
null,
|
||||||
|
certificateExpiry,
|
||||||
|
error
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -142,7 +172,7 @@ class NetworkService implements INetworkService {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
statusResponse = this.buildStatusResponse(monitor, response, null);
|
statusResponse = this.buildStatusResponse(monitor, response, null, null);
|
||||||
if (!response?.body) {
|
if (!response?.body) {
|
||||||
throw new ApiError(
|
throw new ApiError(
|
||||||
"No payload received from infrastructure monitor",
|
"No payload received from infrastructure monitor",
|
||||||
@@ -152,7 +182,7 @@ class NetworkService implements INetworkService {
|
|||||||
statusResponse.payload = response?.body;
|
statusResponse.payload = response?.body;
|
||||||
return statusResponse;
|
return statusResponse;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
statusResponse = this.buildStatusResponse(monitor, null, error);
|
statusResponse = this.buildStatusResponse(monitor, null, null, error);
|
||||||
}
|
}
|
||||||
return statusResponse;
|
return statusResponse;
|
||||||
};
|
};
|
||||||
@@ -174,10 +204,11 @@ class NetworkService implements INetworkService {
|
|||||||
statusResponse = this.buildStatusResponse(
|
statusResponse = this.buildStatusResponse(
|
||||||
monitor,
|
monitor,
|
||||||
response,
|
response,
|
||||||
|
null,
|
||||||
null
|
null
|
||||||
) as StatusResponse<ILighthousePayload>;
|
) as StatusResponse<ILighthousePayload>;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
statusResponse = this.buildStatusResponse(monitor, null, error);
|
statusResponse = this.buildStatusResponse(monitor, null, null, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pagespeedUrl = `https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?url=${url}&category=seo&category=accessibility&category=best-practices&category=performance&key=${apiKey}`;
|
const pagespeedUrl = `https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?url=${url}&category=seo&category=accessibility&category=best-practices&category=performance&key=${apiKey}`;
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ class StatusService implements IStatusService {
|
|||||||
stats.maxResponseTime,
|
stats.maxResponseTime,
|
||||||
statusResponse.responseTime
|
statusResponse.responseTime
|
||||||
);
|
);
|
||||||
|
stats.certificateExpiry = statusResponse.certificateExpiry || null;
|
||||||
|
|
||||||
return await stats.save();
|
return await stats.save();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user