mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix compile
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -53,4 +53,6 @@ tests/coverage
|
||||
|
||||
settings.json
|
||||
|
||||
GoSDK/tester/
|
||||
GoSDK/tester/
|
||||
|
||||
.gitconfig
|
||||
@@ -1,4 +1,5 @@
|
||||
enum ExceptionCode {
|
||||
NotImplementedException = 0,
|
||||
GeneralException = 1,
|
||||
APIException = 2,
|
||||
BadDataException = 400,
|
||||
|
||||
11
Common/Types/Exception/NotImplementedException.ts
Normal file
11
Common/Types/Exception/NotImplementedException.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import Exception from './Exception';
|
||||
import ExceptionCode from './ExceptionCode';
|
||||
|
||||
export default class BadDataException extends Exception {
|
||||
public constructor() {
|
||||
super(
|
||||
ExceptionCode.NotImplementedException,
|
||||
'This code is not implemented'
|
||||
);
|
||||
}
|
||||
}
|
||||
27
Common/Types/IP/IP.ts
Normal file
27
Common/Types/IP/IP.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import NotImplementedException from '../Exception/NotImplementedException';
|
||||
|
||||
export default class IP {
|
||||
private _ip: string = '';
|
||||
public get ip(): string {
|
||||
return this._ip;
|
||||
}
|
||||
public set ip(v: string) {
|
||||
this._ip = v;
|
||||
}
|
||||
|
||||
public constructor(ip: string) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return this.ip;
|
||||
}
|
||||
|
||||
public isIPv4(): boolean {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public isIPv6(): boolean {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
16
Common/Types/IP/IPv4.ts
Normal file
16
Common/Types/IP/IPv4.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import IP from './IP';
|
||||
|
||||
export default class IPv4 extends IP {
|
||||
public constructor(ip: string) {
|
||||
// TODO: Validate if this is actually ipv4 before calling super()
|
||||
super(ip);
|
||||
}
|
||||
|
||||
public override isIPv4(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override isIPv6(): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
16
Common/Types/IP/IPv6.ts
Normal file
16
Common/Types/IP/IPv6.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import IP from './IP';
|
||||
|
||||
export default class IPv6 extends IP {
|
||||
public constructor(ip: string) {
|
||||
// TODO: Validate if this is actually ipv6 before calling super()
|
||||
super(ip);
|
||||
}
|
||||
|
||||
public override isIPv4(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public override isIPv6(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,15 @@ export default class PositiveNumber {
|
||||
this._positiveNumber = v;
|
||||
}
|
||||
|
||||
public constructor(positiveNumber: number) {
|
||||
public constructor(positiveNumber: number | string) {
|
||||
if (typeof positiveNumber === 'string') {
|
||||
try {
|
||||
positiveNumber = Number.parseInt(positiveNumber, 10);
|
||||
} catch (error) {
|
||||
throw new BadDataException(`Invlaid number: ${positiveNumber}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (positiveNumber < 0) {
|
||||
throw new BadDataException('positiveNumber cannot be less than 0');
|
||||
}
|
||||
|
||||
@@ -22,7 +22,13 @@ export const ClusterKey: ObjectID = new ObjectID(
|
||||
|
||||
export const RealtimeHostname: string = process.env['REALTIME_HOSTNAME'] || '';
|
||||
|
||||
export const BackendHostname: string = process.env['BACKEND_HOSTNAME'] || '';
|
||||
export const DashboardApiHostname: string =
|
||||
process.env['DASHBOARD_API_HOSTNAME'] || '';
|
||||
|
||||
export const ProbeApiHostname: string = process.env['PROBE_API_HOSTNAME'] || '';
|
||||
|
||||
export const DataIngestorHostname: string =
|
||||
process.env['DATA_INGESTOR_HOSTNAME'] || '';
|
||||
|
||||
export const Version: string = process.env['npm_package_version'] || '';
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import packageJson from '../package.json';
|
||||
import ObjectID from 'Common/Types/ObjectID';
|
||||
import PositiveNumber from 'Common/Types/PositiveNumber';
|
||||
|
||||
const COMMAND: $TSFixMe = {
|
||||
export const COMMAND: $TSFixMe = {
|
||||
linux: {
|
||||
load: "top -b -n 2 | egrep --color 'load average|%Cpu'",
|
||||
cpu: "egrep --color 'processor|cores' /proc/cpuinfo",
|
||||
@@ -36,13 +37,10 @@ const COMMAND: $TSFixMe = {
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
COMMAND,
|
||||
serverUrl: process.env['SERVER_URL'],
|
||||
probeName: process.env['PROBE_NAME'],
|
||||
probeKey: process.env['PROBE_KEY'],
|
||||
clusterKey: process.env['CLUSTER_KEY'],
|
||||
probeVersion: packageJson.version,
|
||||
dataIngestorUrl: process.env['DATA_INGESTOR_URL'],
|
||||
probeApiUrl: process.env['PROBE_API_URL'],
|
||||
};
|
||||
export const ProbeName: string = process.env['PROBE_NAME'] || '';
|
||||
|
||||
export const ProbeKey: ObjectID = new ObjectID(process.env['PROBE_KEY'] || '');
|
||||
|
||||
export const ResourcesLimit: PositiveNumber = new PositiveNumber(
|
||||
process.env['RESOURCES_LIMIT'] || ''
|
||||
);
|
||||
@@ -3,8 +3,8 @@ import 'CommonServer/utils/process';
|
||||
|
||||
import asyncSleep from 'await-sleep';
|
||||
|
||||
import Main from './workers/main';
|
||||
import config from './utils/config';
|
||||
import Main from './Workers/Index';
|
||||
import config from './Config';
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
|
||||
const cronMinuteStartTime: $TSFixMe = Math.floor(Math.random() * 50);
|
||||
|
||||
128
Probe/Utils/Api.ts
Executable file → Normal file
128
Probe/Utils/Api.ts
Executable file → Normal file
@@ -1,128 +0,0 @@
|
||||
import axios from 'axios';
|
||||
import config from './config';
|
||||
|
||||
const _this: $TSFixMe = {
|
||||
getHeaders: () => {
|
||||
return {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
probeName: config.probeName,
|
||||
probeKey: config.probeKey,
|
||||
clusterKey: config.clusterKey,
|
||||
probeVersion: config.probeVersion,
|
||||
};
|
||||
},
|
||||
|
||||
post: (url: URL, data: $TSFixMe) => {
|
||||
const headers: $TSFixMe = this.getHeaders();
|
||||
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
/*
|
||||
* Error [ERR_FR_MAX_BODY_LENGTH_EXCEEDED]: Request body larger than maxBodyLength limit
|
||||
* https://stackoverflow.com/questions/58655532/increasing-maxcontentlength-and-maxbodylength-in-axios
|
||||
*/
|
||||
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${config.dataIngestorUrl}/${url}`,
|
||||
headers,
|
||||
data,
|
||||
maxContentLength: Infinity,
|
||||
maxBodyLength: Infinity,
|
||||
})
|
||||
.then((response: $TSFixMe) => {
|
||||
resolve(response.data);
|
||||
})
|
||||
.then((error: Error) => {
|
||||
if (error && error.response && error.response.data) {
|
||||
error = error.response.data;
|
||||
}
|
||||
if (error && error.data) {
|
||||
error = error.data;
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
get: (url: URL, limit: number = 10) => {
|
||||
const headers: $TSFixMe = this.getHeaders();
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${config.probeApiUrl}/${url}?limit=${limit}`,
|
||||
headers,
|
||||
})
|
||||
.then((response: $TSFixMe) => {
|
||||
resolve(response.data);
|
||||
})
|
||||
.then((error: Error) => {
|
||||
if (error && error.response && error.response.data) {
|
||||
error = error.response.data;
|
||||
}
|
||||
if (error && error.data) {
|
||||
error = error.data;
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
put: (url: URL, data: $TSFixMe) => {
|
||||
const headers: $TSFixMe = this.getHeaders();
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
/*
|
||||
* Error [ERR_FR_MAX_BODY_LENGTH_EXCEEDED]: Request body larger than maxBodyLength limit
|
||||
* https://stackoverflow.com/questions/58655532/increasing-maxcontentlength-and-maxbodylength-in-axios
|
||||
*/
|
||||
|
||||
axios({
|
||||
method: 'PUT',
|
||||
url: `${config.dataIngestorUrl}/${url}`,
|
||||
headers,
|
||||
data,
|
||||
maxContentLength: Infinity,
|
||||
maxBodyLength: Infinity,
|
||||
})
|
||||
.then((response: $TSFixMe) => {
|
||||
resolve(response.data);
|
||||
})
|
||||
.then((error: Error) => {
|
||||
if (error && error.response && error.response.data) {
|
||||
error = error.response.data;
|
||||
}
|
||||
if (error && error.data) {
|
||||
error = error.data;
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
delete: (url: URL, data: $TSFixMe) => {
|
||||
const headers: $TSFixMe = this.getHeaders();
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
axios({
|
||||
method: 'DELETE',
|
||||
url: `${config.dataIngestorUrl}/${url}`,
|
||||
headers,
|
||||
data,
|
||||
})
|
||||
.then((response: $TSFixMe) => {
|
||||
resolve(response.data);
|
||||
})
|
||||
.then((error: Error) => {
|
||||
if (error && error.response && error.response.data) {
|
||||
error = error.response.data;
|
||||
}
|
||||
if (error && error.data) {
|
||||
error = error.data;
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default _this;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import BackendAPI from './api';
|
||||
|
||||
export default {
|
||||
scan: async function (security: $TSFixMe): void {
|
||||
return await BackendAPI.post(`probe/scan/docker`, { security });
|
||||
},
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import Path from 'path';
|
||||
import { promisify } from 'util';
|
||||
const readdir: $TSFixMe = promisify(fs.readdir);
|
||||
const rmdir: $TSFixMe = promisify(fs.rmdir);
|
||||
const unlink: $TSFixMe = promisify(fs.unlink);
|
||||
|
||||
/**
|
||||
* @description a promise based utility to read content of a file
|
||||
* @param {string} filePath path to file
|
||||
*/
|
||||
function readFileContent(filePath: $TSFixMe): void {
|
||||
return new Promise((resolve: Function, reject: Function) => {
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.readFile(
|
||||
filePath,
|
||||
{ encoding: 'utf8' },
|
||||
(error: $TSFixMe, data: $TSFixMe): void => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
}
|
||||
resolve(data);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description an asynchronous function to handle deleting a file
|
||||
* @param {string} file path to file
|
||||
*/
|
||||
async function deleteFile(file: $TSFixMe): void {
|
||||
if (fs.existsSync(file)) {
|
||||
await unlink(file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description a promise based utility to handle deleting a folder and it's content
|
||||
* @param {string} dir directory with or without file
|
||||
*/
|
||||
async function deleteFolderRecursive(dir: $TSFixMe): void {
|
||||
if (fs.existsSync(dir)) {
|
||||
const entries: $TSFixMe = await readdir(dir, { withFileTypes: true });
|
||||
await Promise.all(
|
||||
entries.map((entry: $TSFixMe) => {
|
||||
const fullPath: $TSFixMe = Path.join(dir, entry.name);
|
||||
return entry.isDirectory()
|
||||
? deleteFolderRecursive(fullPath)
|
||||
: unlink(fullPath);
|
||||
})
|
||||
);
|
||||
await rmdir(dir); // Finally remove now empty directory
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
readFileContent,
|
||||
deleteFile,
|
||||
deleteFolderRecursive,
|
||||
};
|
||||
18
Probe/Utils/Ping.ts
Normal file
18
Probe/Utils/Ping.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import Hostname from 'Common/Types/API/Hostname';
|
||||
import IPv4 from 'Common/Types/IP/IPv4';
|
||||
import IPv6 from 'Common/Types/IP/IPv6';
|
||||
import PositiveNumber from 'Common/Types/PositiveNumber';
|
||||
import NotImplementedException from 'Common/Types/Exception/NotImplementedException';
|
||||
|
||||
export interface PingResponse {
|
||||
isAlive: boolean;
|
||||
responseTimeInMS: PositiveNumber;
|
||||
}
|
||||
|
||||
export default class Ping {
|
||||
public static async fetch(
|
||||
_host: Hostname | IPv4 | IPv6
|
||||
): Promise<PingResponse> {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
import fetch from 'node-fetch-commonjs';
|
||||
|
||||
import sslCert from 'get-ssl-certificate';
|
||||
import https from 'https';
|
||||
import http from 'http';
|
||||
|
||||
24
Probe/Utils/SSL.ts
Normal file
24
Probe/Utils/SSL.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import Hostname from 'Common/Types/API/Hostname';
|
||||
import NotImplementedException from 'Common/Types/Exception/NotImplementedException';
|
||||
|
||||
export interface SslResponse {
|
||||
isSelfSigned: boolean;
|
||||
createdAt: Date;
|
||||
expiresAt: Date;
|
||||
commonName: string;
|
||||
organizationalUnit: string;
|
||||
organization: string;
|
||||
locality: string;
|
||||
state: string;
|
||||
country: string;
|
||||
serialNumber: string;
|
||||
fingerprint: string;
|
||||
fingerprint256: string;
|
||||
fingerprint512: string;
|
||||
}
|
||||
|
||||
export default class SSL {
|
||||
public static async fetch(_host: Hostname): Promise<SslResponse> {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
0
Probe/Utils/Website.ts
Normal file
0
Probe/Utils/Website.ts
Normal file
@@ -1,20 +1,19 @@
|
||||
import logger from 'CommonServer/Utils/Logger';
|
||||
import ProbeAPI from '../Utils/api';
|
||||
import ApiMonitors from './apiMonitors';
|
||||
import UrlMonitors from './urlMonitors';
|
||||
import IPMonitors from './ipMonitors';
|
||||
import ServerMonitors from './serverMonitors';
|
||||
|
||||
import ApiMonitors from './ApiMonitors';
|
||||
import UrlMonitors from './UrlMonitors';
|
||||
import IPMonitors from './IpMonitors';
|
||||
import ServerMonitors from './ServerMonitors';
|
||||
import asyncSleep from 'await-sleep';
|
||||
import IncomingHttpRequestMonitors from './incomingHttpRequestMonitors';
|
||||
import KubernetesMonitors from './kubernetesMonitors';
|
||||
|
||||
let limit: $TSFixMe = process.env['RESOURCES_LIMIT'];
|
||||
|
||||
if (limit && typeof limit === 'string') {
|
||||
limit = parseInt(limit);
|
||||
}
|
||||
|
||||
import asyncSleep from 'await-sleep';
|
||||
|
||||
const _this: $TSFixMe = {
|
||||
runJob: async function (): void {
|
||||
logger.info(`Getting a list of ${limit} monitors`);
|
||||
@@ -2,12 +2,9 @@ import { spawn } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import Path from 'path';
|
||||
import fetch from 'node-fetch-commonjs';
|
||||
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import ApiService from '../Utils/apiService';
|
||||
|
||||
import { serverUrl } from '../Config';
|
||||
|
||||
import { deleteFile } from '../Utils/fsHandlers';
|
||||
|
||||
export default {
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "./build/dist", /* Specify an output folder for all emitted files. */
|
||||
"outDir": "build/dist", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
|
||||
Reference in New Issue
Block a user