1
1
// GET /api/v1/plugin/extension/monitoring-endpoint/monitoring
2
2
3
3
const fs = require ( 'fs' ) ;
4
+ const path = require ( 'path' ) ;
4
5
const https = require ( 'https' ) ;
5
6
6
7
let info = { }
@@ -316,6 +317,52 @@ process.stdin.on('end', () => {
316
317
} ) ;
317
318
}
318
319
320
+ function checkSqlBackups ( ) {
321
+ return new Promise ( ( resolve , reject ) => {
322
+ // check sqldumps
323
+ const sqlBackupDir = '/fylr/files/sqlbackups/' ;
324
+
325
+ fs . readdir ( sqlBackupDir , ( err , files ) => {
326
+ if ( err ) {
327
+ return resolve ( false ) ;
328
+ }
329
+ else {
330
+ for ( const file of files ) {
331
+ // get yesterdays-date
332
+ let yesterday = new Date ( ) ;
333
+ yesterday . setDate ( yesterday . getDate ( ) - 1 ) ;
334
+
335
+ const year = yesterday . getFullYear ( ) ;
336
+ const month = String ( yesterday . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
337
+ const day = String ( yesterday . getDate ( ) ) . padStart ( 2 , '0' ) ;
338
+
339
+ yesterday = year + '-' + month + '-' + day ;
340
+
341
+ const backupFile = files . find ( file => file . endsWith ( '.pgdump' ) && file . includes ( yesterday ) ) ;
342
+
343
+ if ( backupFile ) {
344
+ // Passende Log-Datei suchen
345
+ const logFile = `${ backupFile } .log` ;
346
+ if ( files . includes ( logFile ) ) {
347
+ // Log-Datei lesen und prüfen
348
+ const logPath = path . join ( sqlBackupDir , logFile ) ;
349
+ const logContent = fs . readFileSync ( logPath , 'utf8' ) ;
350
+ if ( logContent . includes ( 'Backup completed successfully' ) ) {
351
+ return resolve ( true ) ;
352
+ } else {
353
+ return resolve ( false ) ;
354
+ }
355
+ } else {
356
+ return resolve ( false ) ;
357
+ }
358
+ } else {
359
+ return resolve ( false ) ;
360
+ }
361
+ } ;
362
+ }
363
+ } ) ;
364
+ } ) ;
365
+ }
319
366
320
367
async function fetchData ( ) {
321
368
const infoData = await Promise . all ( [
@@ -329,11 +376,16 @@ process.stdin.on('end', () => {
329
376
getConfigFromInspectAPI ( ) ,
330
377
getPoolStatsFromAPI ( ) ,
331
378
getDiskUsageFromAPI ( ) ,
332
- getObjectTypeStatsFromAPI ( )
379
+ getObjectTypeStatsFromAPI ( ) ,
380
+ checkSqlBackups ( )
333
381
] ) ;
334
382
335
383
let configinfo = infoData [ 6 ] ;
336
-
384
+
385
+ //////////////////////////////////////////////////////////////
386
+ // check mysql-backups, a successfull backup from yesterday is wanted
387
+ result . sqlbackups = infoData [ 11 ] ;
388
+
337
389
//////////////////////////////////////////////////////////////
338
390
// email-configs
339
391
result . email = { } ;
0 commit comments