mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-21 09:48:56 +01:00
feat(status): add emoji support for RYZEN and XEON hosts in status monitoring
This commit is contained in:
@@ -6,6 +6,9 @@ CLIENT_ID=your_discord_client_id_here
|
|||||||
EMOJI_STATUS_ONLINE=<a:online:1432684754276323431>
|
EMOJI_STATUS_ONLINE=<a:online:1432684754276323431>
|
||||||
EMOJI_STATUS_OFFLINE=<a:offline:1432684900175183882>
|
EMOJI_STATUS_OFFLINE=<a:offline:1432684900175183882>
|
||||||
|
|
||||||
|
EMOJI_RYZEN=<:ryzen:1433711892009848833>
|
||||||
|
EMOJI_XEON=<:xeon:1433711864168054855>
|
||||||
|
|
||||||
# Database Configuration
|
# Database Configuration
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
|
|||||||
@@ -2,67 +2,80 @@ import ping from "ping";
|
|||||||
import * as cron from 'cron';
|
import * as cron from 'cron';
|
||||||
import { ActivityType, Client } from "discord.js";
|
import { ActivityType, Client } from "discord.js";
|
||||||
import { Host } from "../type";
|
import { Host } from "../type";
|
||||||
|
import { loadEnvFile } from "process";
|
||||||
|
import { configDotenv } from "dotenv";
|
||||||
|
|
||||||
|
configDotenv();
|
||||||
|
|
||||||
export class StatusService {
|
export class StatusService {
|
||||||
|
|
||||||
public hosts : Host[] = [
|
private EMOJI_RYZEN : string = process.env.EMOJI_RYZEN as string;
|
||||||
{
|
private EMOJI_XEON : string = process.env.EMOJI_XEON as string;
|
||||||
'host': 'https://protojx.com',
|
|
||||||
'name': 'Protojx Website 🌐',
|
|
||||||
alive: false,
|
|
||||||
type: 'website'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'host': 'https://manager.protojx.com',
|
|
||||||
'name': 'Espace Client 💻',
|
|
||||||
alive: false,
|
|
||||||
type: 'website'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
host: '5.178.99.4',
|
|
||||||
name: 'RYZEN 01 🖥️',
|
|
||||||
alive: false,
|
|
||||||
type: 'ping'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
host: '5.178.99.6',
|
|
||||||
name: 'RYZEN 02 🖥️',
|
|
||||||
alive: false,
|
|
||||||
type: 'ping'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
host: '5.178.99.5',
|
|
||||||
name: 'RYZEN 03 🖥️',
|
|
||||||
alive: false,
|
|
||||||
type: 'ping'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
host: '5.178.99.177',
|
|
||||||
name: 'XEON 01 (2697A V4) 🖥️',
|
|
||||||
alive: false,
|
|
||||||
type: 'ping'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
host: '5.178.99.248',
|
|
||||||
name: 'XEON 02 (2687W V4) 🖥️',
|
|
||||||
alive: false,
|
|
||||||
type: 'ping'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
host: '5.178.99.53',
|
|
||||||
name: 'RYZEN-GAME 01 👾',
|
|
||||||
alive: false,
|
|
||||||
type: 'ping'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
host: '5.178.99.63',
|
|
||||||
name: 'XEON-GAME 01 👾',
|
|
||||||
alive: false,
|
|
||||||
type: 'ping'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
private client : Client|null = null;
|
public hosts: Host[] = [
|
||||||
|
{
|
||||||
|
'host': 'https://protojx.com',
|
||||||
|
'name': 'Protojx Website 🌐',
|
||||||
|
alive: false,
|
||||||
|
type: 'website'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'host': 'https://manager.protojx.com',
|
||||||
|
'name': 'Espace Client 💻',
|
||||||
|
alive: false,
|
||||||
|
type: 'website'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '5.178.99.4',
|
||||||
|
name: 'RYZEN 01 ' + this.EMOJI_RYZEN,
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '5.178.99.6',
|
||||||
|
name: 'RYZEN 02 ' + this.EMOJI_RYZEN,
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '5.178.99.5',
|
||||||
|
name: 'RYZEN 03 ' + this.EMOJI_RYZEN,
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '154.16.254.10',
|
||||||
|
name: 'RYZEN7 04 ' + this.EMOJI_RYZEN,
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '5.178.99.177',
|
||||||
|
name: 'XEON 01 (2697A V4) ' + this.EMOJI_XEON,
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '5.178.99.248',
|
||||||
|
name: 'XEON 02 (2687W V4) ' + this.EMOJI_XEON,
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '5.178.99.53',
|
||||||
|
name: 'RYZEN-GAME 01 👾',
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
host: '5.178.99.63',
|
||||||
|
name: 'XEON-GAME 01 👾',
|
||||||
|
alive: false,
|
||||||
|
type: 'ping'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
private client: Client | null = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
||||||
@@ -83,19 +96,21 @@ export class StatusService {
|
|||||||
console.log('Status monitoring started - checking every 2 minutes');
|
console.log('Status monitoring started - checking every 2 minutes');
|
||||||
}
|
}
|
||||||
|
|
||||||
setClient(client : Client) {
|
setClient(client: Client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.client.user?.setActivity({name: '💭 Server load and status...'})
|
this.client.user?.setActivity({ name: '💭 Server load and status...' })
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateClientStatus() {
|
private async updateClientStatus() {
|
||||||
if(this.client) {
|
if (this.client) {
|
||||||
const hosts = this.hosts.length;
|
const hosts = this.hosts.length;
|
||||||
const hostsAlive = this.hosts.filter((h) => h.alive).length;
|
const hostsAlive = this.hosts.filter((h) => h.alive).length;
|
||||||
|
|
||||||
this.client.user?.setActivity({name: (
|
this.client.user?.setActivity({
|
||||||
hosts == hostsAlive ? '✅ All services are online.' : `📛 ${hosts - hostsAlive} service${hosts - hostsAlive > 1 ? 's' : ''} offline.`
|
name: (
|
||||||
), type: ActivityType.Watching});
|
hosts == hostsAlive ? '✅ All services are online.' : `📛 ${hosts - hostsAlive} service${hosts - hostsAlive > 1 ? 's' : ''} offline.`
|
||||||
|
), type: ActivityType.Watching
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,10 +120,10 @@ export class StatusService {
|
|||||||
|
|
||||||
const hosts = this.hosts.filter((value, index) => index < max * max_ping && index >= (max - 1) * max_ping);
|
const hosts = this.hosts.filter((value, index) => index < max * max_ping && index >= (max - 1) * max_ping);
|
||||||
async function fetchAlive(host: Host) {
|
async function fetchAlive(host: Host) {
|
||||||
if(host.type === 'ping'){
|
if (host.type === 'ping') {
|
||||||
let res = await ping.promise.probe(host.host, {timeout: 10});
|
let res = await ping.promise.probe(host.host, { timeout: 10 });
|
||||||
host.alive = res.alive;
|
host.alive = res.alive;
|
||||||
}else if(host.type === 'website'){
|
} else if (host.type === 'website') {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(host.host, { method: 'HEAD', signal: AbortSignal.timeout(10000) });
|
const response = await fetch(host.host, { method: 'HEAD', signal: AbortSignal.timeout(10000) });
|
||||||
host.alive = response.ok;
|
host.alive = response.ok;
|
||||||
@@ -129,7 +144,7 @@ export class StatusService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(this.hosts.length > max * max_ping) {
|
if (this.hosts.length > max * max_ping) {
|
||||||
await this.fetch(max + 1);
|
await this.fetch(max + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user