Refactor command line argument parsing and update API endpoint

This commit is contained in:
Simon Larsen
2024-03-16 19:17:38 +00:00
parent 98e1c3a41d
commit f4f9629350
5 changed files with 22 additions and 26 deletions

View File

@@ -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);

View File

@@ -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[] = [];

View File

@@ -1,4 +1,3 @@
import logger from './Logger';
import cron from 'node-cron';

View File

@@ -1,4 +1,3 @@
import os from 'node:os';
enum OSTypeEnum {

View File

@@ -26,9 +26,6 @@ router.get(
next: NextFunction
): Promise<void> => {
try {
debugger;
const monitorSecretKeyAsString: string | undefined =
req.params['secretkey'];