mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Refactor command line argument parsing and update API endpoint
This commit is contained in:
@@ -7,19 +7,21 @@ import MonitorInfrastructure from './Jobs/MonitorInfrastructure';
|
||||
const usage: string =
|
||||
'\nUsage: oneuptime-infrastructure-agent --secret-key <secret-key>';
|
||||
|
||||
const argv: {
|
||||
[x: string]: unknown;
|
||||
k: string;
|
||||
u: string | undefined;
|
||||
_: (string | number)[];
|
||||
$0: string;
|
||||
} | Promise<{
|
||||
[x: string]: unknown;
|
||||
k: string;
|
||||
u: string | undefined;
|
||||
_: (string | number)[];
|
||||
$0: string;
|
||||
}> = yargs
|
||||
const argv:
|
||||
| {
|
||||
[x: string]: unknown;
|
||||
k: string;
|
||||
u: string | undefined;
|
||||
_: (string | number)[];
|
||||
$0: string;
|
||||
}
|
||||
| Promise<{
|
||||
[x: string]: unknown;
|
||||
k: string;
|
||||
u: string | undefined;
|
||||
_: (string | number)[];
|
||||
$0: string;
|
||||
}> = yargs
|
||||
.usage(usage)
|
||||
.option('k', {
|
||||
alias: 'secret-key',
|
||||
@@ -37,7 +39,8 @@ const argv: {
|
||||
.help(true).argv;
|
||||
|
||||
const secretKey: string | undefined = (argv as any)['secret-key'];
|
||||
const oneuptimeUrl: string = (argv as any)['oneuptime-url'] || 'https://oneuptime.com'
|
||||
const oneuptimeHost: string =
|
||||
(argv as any)['oneuptime-url'] || 'https://oneuptime.com';
|
||||
|
||||
if (!secretKey) {
|
||||
throw new Error(
|
||||
@@ -45,4 +48,4 @@ if (!secretKey) {
|
||||
);
|
||||
}
|
||||
|
||||
MonitorInfrastructure.initJob(secretKey, oneuptimeUrl);
|
||||
MonitorInfrastructure.initJob(secretKey, oneuptimeHost);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
|
||||
import ServerMonitorResponse from '../Types/ServerMonitorResponse';
|
||||
import BasicCron from '../Utils/BasicCron';
|
||||
import { BasicMetircs } from '../Utils/BasicMetrics';
|
||||
import Logger from '../Utils/Logger';
|
||||
import axios from 'axios';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
|
||||
export default class MonitorInfrastructure {
|
||||
public static initJob(secretKey: string, oneuptimeHost: string): void {
|
||||
|
||||
const EVERY_MINUTE = '* * * * *';
|
||||
const EVERY_MINUTE: string = '* * * * *';
|
||||
|
||||
BasicCron({
|
||||
jobName: 'MonitorInfrastructure',
|
||||
@@ -25,11 +23,11 @@ export default class MonitorInfrastructure {
|
||||
}
|
||||
|
||||
// get monitor steps to get disk paths.
|
||||
const monitorResult = await axios.get(
|
||||
const monitorResult: AxiosResponse = await axios.get(
|
||||
`${oneuptimeHost}/server-monitor/${secretKey}`
|
||||
);
|
||||
|
||||
const monitor = monitorResult.data;
|
||||
const monitor: any = monitorResult.data;
|
||||
// get disk paths to monitor.
|
||||
|
||||
const diskPaths: string[] = [];
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import logger from './Logger';
|
||||
import cron from 'node-cron';
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import os from 'node:os';
|
||||
|
||||
enum OSTypeEnum {
|
||||
|
||||
@@ -26,9 +26,6 @@ router.get(
|
||||
next: NextFunction
|
||||
): Promise<void> => {
|
||||
try {
|
||||
|
||||
debugger;
|
||||
|
||||
const monitorSecretKeyAsString: string | undefined =
|
||||
req.params['secretkey'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user