tango-app-api-infra 3.1.16 → 3.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/controllers/clientInfra.controller.js +426 -293
- package/src/controllers/dataMismatch.controller.js +13 -1
- package/src/controllers/infra.controllers.js +14 -3
- package/src/controllers/internalInfra.controller.js +4 -4
- package/src/controllers/storeInfra.controlller.js +351 -478
- package/src/controllers/userInfra.controller.js +29 -21
- package/src/validations/infra.validation.js +20 -21
|
@@ -62,7 +62,12 @@ export async function storeTicketList( req, res ) {
|
|
|
62
62
|
$filter: {
|
|
63
63
|
input: '$ticketActivity',
|
|
64
64
|
as: 'item',
|
|
65
|
-
cond: {
|
|
65
|
+
cond: {
|
|
66
|
+
$and: [
|
|
67
|
+
{ $ne: [ '$$item.actionType', 'statusChange' ] },
|
|
68
|
+
{ $ne: [ '$$item.actionType', 'statusCheck' ] },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
66
71
|
},
|
|
67
72
|
},
|
|
68
73
|
primaryIssue: {
|
|
@@ -284,173 +289,141 @@ export async function edgeAppLogTable( req, res ) {
|
|
|
284
289
|
try {
|
|
285
290
|
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
286
291
|
if ( !store ) {
|
|
287
|
-
return res.sendError( '
|
|
292
|
+
return res.sendError( 'Store Not found', 204 );
|
|
288
293
|
}
|
|
289
|
-
|
|
290
|
-
let
|
|
294
|
+
|
|
295
|
+
let startHour = parseInt( store.storeProfile.open.split( ':' )[0], 10 );
|
|
296
|
+
let endHour = parseInt( store.storeProfile.close.split( ':' )[0], 10 );
|
|
291
297
|
const interval = 60; // 1 hour in minutes
|
|
292
298
|
const timeSlots = generateTimeSlots( startHour, endHour, interval, req );
|
|
299
|
+
|
|
300
|
+
const date = dayjs( timeSlots[0].from ).format( 'DD-MM-YYYY' );
|
|
301
|
+
const storeId = req.body.storeId;
|
|
302
|
+
|
|
303
|
+
const internetSpeedQuery = {
|
|
304
|
+
size: 100,
|
|
305
|
+
query: {
|
|
306
|
+
bool: {
|
|
307
|
+
must: [
|
|
308
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
309
|
+
{ term: { 'store_date.keyword': date } },
|
|
310
|
+
{ term: { 'storeId.keyword': storeId } },
|
|
311
|
+
{ term: { 'log_subtype.keyword': 'Speed_Test' } },
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
316
|
+
_source: [ 'data.upload_Speed', 'data.occuringTime' ],
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const fileCountQuery = {
|
|
320
|
+
size: 100,
|
|
321
|
+
query: {
|
|
322
|
+
bool: {
|
|
323
|
+
must: [
|
|
324
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
325
|
+
{ term: { 'store_date.keyword': date } },
|
|
326
|
+
{ term: { 'storeId.keyword': storeId } },
|
|
327
|
+
{ term: { 'log_subtype.keyword': 'Zip_File_Count' } },
|
|
328
|
+
],
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
332
|
+
_source: [ 'data.files_pushed', 'data.files_generated', 'data.occuringTime' ],
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const downTimeQuery = {
|
|
336
|
+
size: 100,
|
|
337
|
+
query: {
|
|
338
|
+
bool: {
|
|
339
|
+
must: [
|
|
340
|
+
{ term: { 'doc.date.keyword': date } },
|
|
341
|
+
{ term: { 'doc.store_id.keyword': storeId } },
|
|
342
|
+
],
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
_source: [ 'doc.streamwise_downtime', 'doc.hour' ],
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// Execute all queries in parallel
|
|
349
|
+
const [ speedTestResult, fileCountResult, downtimeResult ] = await Promise.all( [
|
|
350
|
+
getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, internetSpeedQuery ),
|
|
351
|
+
getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, fileCountQuery ),
|
|
352
|
+
getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery ),
|
|
353
|
+
] );
|
|
354
|
+
// Process results
|
|
355
|
+
const speedTestData = speedTestResult?.body?.hits?.hits ?? [];
|
|
356
|
+
const fileCountData = fileCountResult?.body?.hits?.hits ?? [];
|
|
357
|
+
const downtimeData = downtimeResult?.body?.hits?.hits ?? [];
|
|
358
|
+
|
|
293
359
|
for ( const obj of timeSlots ) {
|
|
360
|
+
const hour = obj.hour;
|
|
294
361
|
obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
|
|
295
362
|
obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
|
|
296
|
-
let internetSpeedQuery = {
|
|
297
|
-
'query': {
|
|
298
|
-
'bool': {
|
|
299
|
-
'must': [
|
|
300
|
-
{
|
|
301
|
-
'term': {
|
|
302
|
-
'log_type.keyword': 'Application',
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
{
|
|
306
|
-
'term': {
|
|
307
|
-
'store_date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
'term': {
|
|
312
|
-
'storeId.keyword': req.body.storeId,
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
'term': {
|
|
317
|
-
'log_subtype.keyword': 'Speed_Test',
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
},
|
|
322
|
-
},
|
|
323
|
-
'sort': [
|
|
324
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
325
|
-
],
|
|
326
|
-
};
|
|
327
|
-
let speedTest = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, internetSpeedQuery );
|
|
328
|
-
if ( speedTest&& speedTest.body.hits && speedTest.body.hits.hits.length > 0 ) {
|
|
329
|
-
for ( const sourcedata of speedTest.body.hits.hits ) {
|
|
330
|
-
if ( sourcedata._source ) {
|
|
331
|
-
if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==obj.hour ) {
|
|
332
|
-
const megabytes = bytesToMB( sourcedata._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 );
|
|
333
|
-
obj.Internetspeed = megabytes+ ' MB/sec';
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
} else {
|
|
338
|
-
obj.Internetspeed = '';
|
|
339
|
-
}
|
|
340
|
-
let FileCountQuery = {
|
|
341
|
-
'size': 1000,
|
|
342
|
-
'query': {
|
|
343
|
-
'bool': {
|
|
344
|
-
'must': [
|
|
345
|
-
{
|
|
346
|
-
'term': {
|
|
347
|
-
'log_type.keyword': 'Application',
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
{
|
|
351
|
-
'term': {
|
|
352
|
-
'store_date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
'term': {
|
|
357
|
-
'storeId.keyword': req.body.storeId,
|
|
358
|
-
},
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
'term': {
|
|
362
|
-
'log_subtype.keyword': 'Zip_File_Count',
|
|
363
|
-
},
|
|
364
|
-
},
|
|
365
|
-
],
|
|
366
363
|
|
|
367
|
-
|
|
368
|
-
},
|
|
364
|
+
// Internet speed
|
|
369
365
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if ( newFilesCount&& newFilesCount.body.hits && newFilesCount.body.hits.hits.length > 0 ) {
|
|
376
|
-
obj.files_pushed = 0;
|
|
377
|
-
obj.files_generated = 0;
|
|
378
|
-
for ( let sourcedata of newFilesCount.body.hits.hits ) {
|
|
379
|
-
if ( sourcedata._source ) {
|
|
380
|
-
if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==obj.hour ) {
|
|
381
|
-
obj.files_pushed = obj.files_pushed+Number( sourcedata._source.data.files_pushed );
|
|
382
|
-
obj.files_generated = obj.files_generated+Number( sourcedata._source.data.files_generated );
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
366
|
+
const speedTest = speedTestData.find(
|
|
367
|
+
( item ) => Number( item._source.data.occuringTime.split( ':' )[0] ) === hour,
|
|
368
|
+
);
|
|
369
|
+
if ( speedTest&&speedTest._source.data.upload_Speed =='0 bytes' ) {
|
|
370
|
+
obj.Internetspeed = '0 MB/sec';
|
|
386
371
|
} else {
|
|
387
|
-
obj.
|
|
388
|
-
obj.files_generated = '';
|
|
372
|
+
obj.Internetspeed = speedTest ? `${bytesToMB( speedTest._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 )} MB/sec` : '';
|
|
389
373
|
}
|
|
390
|
-
let downTimeQuery = {
|
|
391
|
-
'size': 1,
|
|
392
|
-
'query': {
|
|
393
|
-
'bool': {
|
|
394
|
-
'must': [
|
|
395
|
-
{
|
|
396
|
-
'term': {
|
|
397
|
-
'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
398
|
-
},
|
|
399
|
-
},
|
|
400
|
-
{
|
|
401
|
-
'term': {
|
|
402
|
-
'doc.store_id.keyword': req.body.storeId,
|
|
403
|
-
},
|
|
404
|
-
},
|
|
405
|
-
{
|
|
406
|
-
'terms': {
|
|
407
|
-
'doc.hour.keyword': [ obj.hour ],
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
],
|
|
411
374
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
375
|
+
|
|
376
|
+
// File counts
|
|
377
|
+
const fileCounts = fileCountData.filter(
|
|
378
|
+
( item ) => Number( item._source.data.occuringTime.split( ':' )[0] ) === hour,
|
|
379
|
+
);
|
|
380
|
+
obj.files_pushed = fileCounts.reduce( ( sum, item ) => sum + Number( item._source.data.files_pushed ), 0 ) || '';
|
|
381
|
+
obj.files_generated = fileCounts.reduce( ( sum, item ) => sum + Number( item._source.data.files_generated ), 0 ) || '';
|
|
382
|
+
|
|
383
|
+
// Downtime
|
|
384
|
+
|
|
385
|
+
const downtime = downtimeData.find( ( item ) => Number( item._source.doc.hour ) === hour );
|
|
386
|
+
|
|
387
|
+
if ( downtime ) {
|
|
388
|
+
const streamwiseDowntime = downtime._source.doc.streamwise_downtime || [];
|
|
389
|
+
if ( streamwiseDowntime.length > 0 ) {
|
|
390
|
+
const sum = streamwiseDowntime.reduce( ( acc, cur ) => acc + cur.down_time, 0 );
|
|
391
|
+
const average = sum / streamwiseDowntime.length;
|
|
392
|
+
obj.downtime = Math.round( average );
|
|
393
|
+
} else {
|
|
394
|
+
obj.downtime = '';
|
|
395
|
+
}
|
|
423
396
|
} else {
|
|
424
397
|
obj.downtime = '';
|
|
425
398
|
}
|
|
426
399
|
}
|
|
400
|
+
|
|
427
401
|
if ( req.body.export ) {
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
} );
|
|
437
|
-
} );
|
|
438
|
-
await download( exportdata, res );
|
|
402
|
+
const exportData = timeSlots.map( ( element ) => ( {
|
|
403
|
+
'Time Stamp': `${element.startTime}-${element.endTime}`,
|
|
404
|
+
'Downtime': element.downtime?element.downtime +' Mins':'--',
|
|
405
|
+
'Avg Internet Speed': element.Internetspeed,
|
|
406
|
+
'Files Generated': element.files_generated,
|
|
407
|
+
'Files Pushed': element.files_pushed,
|
|
408
|
+
} ) );
|
|
409
|
+
await download( exportData, res );
|
|
439
410
|
return;
|
|
440
411
|
}
|
|
412
|
+
|
|
441
413
|
res.sendSuccess( timeSlots );
|
|
442
414
|
} catch ( error ) {
|
|
443
|
-
logger.error( { error
|
|
415
|
+
logger.error( { error, function: 'edgeAppLog' } );
|
|
444
416
|
return res.sendError( error, 500 );
|
|
445
417
|
}
|
|
446
418
|
}
|
|
419
|
+
|
|
447
420
|
function bytesToMB( bytes ) {
|
|
448
421
|
return bytes / ( 1024 * 1024 );
|
|
449
422
|
}
|
|
450
423
|
function generateTimeSlots( startHour, endHour, interval, req ) {
|
|
451
424
|
try {
|
|
452
425
|
const timeSlots = [];
|
|
453
|
-
for ( let hour = startHour; hour
|
|
426
|
+
for ( let hour = startHour; hour < endHour; hour++ ) {
|
|
454
427
|
for ( let minute = 0; minute < 60; minute += interval ) {
|
|
455
428
|
let isoDate = new Date();
|
|
456
429
|
|
|
@@ -487,172 +460,154 @@ export async function viewedgeAppLog( req, res ) {
|
|
|
487
460
|
try {
|
|
488
461
|
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
489
462
|
if ( !store ) {
|
|
490
|
-
return res.sendError( 'Stores Not
|
|
463
|
+
return res.sendError( 'Stores Not found', 204 );
|
|
491
464
|
}
|
|
492
|
-
const inputDate = dayjs( req.body.Date ).format( '
|
|
465
|
+
const inputDate = dayjs( req.body.Date ).format( 'DD-MM-YYYY' );
|
|
493
466
|
const fromTime = req.body.from;
|
|
494
467
|
const toTime = req.body.to;
|
|
495
468
|
let response = {};
|
|
496
469
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
{
|
|
504
|
-
|
|
505
|
-
'log_type.keyword': 'Application',
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
},
|
|
512
|
-
},
|
|
513
|
-
{
|
|
514
|
-
'term': {
|
|
515
|
-
'store_id.keyword': req.body.storeId,
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
'term': {
|
|
520
|
-
'log_subtype.keyword': 'AppStart_Time',
|
|
521
|
-
},
|
|
470
|
+
const queries = [
|
|
471
|
+
{
|
|
472
|
+
queryName: 'appStartTime',
|
|
473
|
+
query: {
|
|
474
|
+
size: 1,
|
|
475
|
+
query: {
|
|
476
|
+
bool: {
|
|
477
|
+
must: [
|
|
478
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
479
|
+
{ term: { 'store_date.keyword': inputDate } },
|
|
480
|
+
{ term: { 'storeId.keyword': req.body.storeId } },
|
|
481
|
+
{ term: { 'log_subtype.keyword': 'AppStart_Time' } },
|
|
482
|
+
{ term: { 'data.message.keyword': 'Login Success Event' } },
|
|
483
|
+
],
|
|
522
484
|
},
|
|
523
|
-
|
|
524
|
-
|
|
485
|
+
},
|
|
525
486
|
},
|
|
526
487
|
},
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
},
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
'term': {
|
|
544
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
545
|
-
},
|
|
546
|
-
},
|
|
547
|
-
{
|
|
548
|
-
'term': {
|
|
549
|
-
'store_id.keyword': req.body.storeId,
|
|
550
|
-
},
|
|
551
|
-
},
|
|
552
|
-
{
|
|
553
|
-
'term': {
|
|
554
|
-
'log_subtype.keyword': 'App_Quit',
|
|
555
|
-
},
|
|
488
|
+
{
|
|
489
|
+
queryName: 'appQuitTime',
|
|
490
|
+
query: {
|
|
491
|
+
size: 1,
|
|
492
|
+
query: {
|
|
493
|
+
bool: {
|
|
494
|
+
must: [
|
|
495
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
496
|
+
{ term: { 'store_date.keyword': inputDate } },
|
|
497
|
+
{ term: { 'storeId.keyword': req.body.storeId } },
|
|
498
|
+
{ term: { 'log_subtype.keyword': 'App_Quit_Time' } },
|
|
499
|
+
{ term: { 'data.message.keyword': 'App Quit With password' } },
|
|
500
|
+
],
|
|
556
501
|
},
|
|
557
|
-
|
|
558
|
-
|
|
502
|
+
},
|
|
503
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
559
504
|
},
|
|
560
505
|
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
let appCrashTimeQuery = {
|
|
574
|
-
'size': 1,
|
|
575
|
-
'query': {
|
|
576
|
-
'bool': {
|
|
577
|
-
'must': [
|
|
578
|
-
{
|
|
579
|
-
'term': {
|
|
580
|
-
'log_type.keyword': 'Application',
|
|
581
|
-
},
|
|
506
|
+
{
|
|
507
|
+
queryName: 'appCrashTime',
|
|
508
|
+
query: {
|
|
509
|
+
size: 1,
|
|
510
|
+
query: {
|
|
511
|
+
bool: {
|
|
512
|
+
must: [
|
|
513
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
514
|
+
{ term: { 'store_date.keyword': inputDate } },
|
|
515
|
+
{ term: { 'storeId.keyword': req.body.storeId } },
|
|
516
|
+
{ term: { 'log_subtype.keyword': 'App_Close_Event' } },
|
|
517
|
+
],
|
|
582
518
|
},
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
519
|
+
},
|
|
520
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
queryName: 'screenStatus',
|
|
525
|
+
query: {
|
|
526
|
+
size: 100,
|
|
527
|
+
query: {
|
|
528
|
+
bool: {
|
|
529
|
+
must: [
|
|
530
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
531
|
+
{ term: { 'store_date.keyword': inputDate } },
|
|
532
|
+
{ term: { 'storeId.keyword': req.body.storeId } },
|
|
533
|
+
{ term: { 'log_subtype.keyword': 'System_Status' } },
|
|
534
|
+
],
|
|
587
535
|
},
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
536
|
+
},
|
|
537
|
+
sort: [ { timestamp: { order: 'asc' } } ],
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
queryName: 'fileCount',
|
|
542
|
+
query: {
|
|
543
|
+
size: 100,
|
|
544
|
+
query: {
|
|
545
|
+
bool: {
|
|
546
|
+
must: [
|
|
547
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
548
|
+
{ term: { 'store_date.keyword': inputDate } },
|
|
549
|
+
{ term: { 'storeId.keyword': req.body.storeId } },
|
|
550
|
+
{ term: { 'log_subtype.keyword': 'Zip_File_Count' } },
|
|
551
|
+
],
|
|
592
552
|
},
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
553
|
+
},
|
|
554
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
queryName: 'antiVirus',
|
|
559
|
+
query: {
|
|
560
|
+
size: 100,
|
|
561
|
+
query: {
|
|
562
|
+
bool: {
|
|
563
|
+
must: [
|
|
564
|
+
{ term: { 'log_type.keyword': 'Application' } },
|
|
565
|
+
{ term: { 'store_date.keyword': inputDate } },
|
|
566
|
+
{ term: { 'storeId.keyword': req.body.storeId } },
|
|
567
|
+
{ term: { 'log_subtype.keyword': 'Anti_Virus' } },
|
|
568
|
+
],
|
|
597
569
|
},
|
|
598
|
-
|
|
599
|
-
|
|
570
|
+
},
|
|
571
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
600
572
|
},
|
|
601
573
|
},
|
|
602
|
-
|
|
603
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
604
|
-
],
|
|
605
|
-
};
|
|
574
|
+
];
|
|
606
575
|
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
576
|
+
const fetchLogs = queries.map( ( q ) =>
|
|
577
|
+
getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, q.query ),
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
const results = await Promise.all( fetchLogs );
|
|
581
|
+
|
|
582
|
+
const appStartTimeResult = results[0];
|
|
583
|
+
const appQuitTimeResult = results[1];
|
|
584
|
+
const appCrashTimeResult = results[2];
|
|
585
|
+
const screenStatusResult = results[3];
|
|
586
|
+
const fileCountResult = results[4];
|
|
587
|
+
const antiVirusResult = results[5];
|
|
588
|
+
|
|
589
|
+
response.appStartTime = appStartTimeResult.body.hits.hits.length > 0 ? appStartTimeResult.body.hits.hits[0]._source.data.occuringTime : '';
|
|
590
|
+
|
|
591
|
+
if ( appQuitTimeResult.body.hits.hits && appQuitTimeResult.body.hits.hits.length > 0 ) {
|
|
592
|
+
const quitTime = appQuitTimeResult.body.hits.hits.find( ( sourceData ) =>
|
|
593
|
+
Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ),
|
|
594
|
+
);
|
|
595
|
+
response.appQuitTime = quitTime ? quitTime._source.data.occuringTime : '';
|
|
614
596
|
}
|
|
615
|
-
const screenStatus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
|
|
616
|
-
'size': 1000,
|
|
617
|
-
'query': {
|
|
618
|
-
'bool': {
|
|
619
|
-
'must': [
|
|
620
|
-
{
|
|
621
|
-
'term': {
|
|
622
|
-
'log_type.keyword': 'Application',
|
|
623
|
-
},
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
'term': {
|
|
627
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
628
|
-
},
|
|
629
|
-
},
|
|
630
|
-
{
|
|
631
|
-
'term': {
|
|
632
|
-
'store_id.keyword': req.body.storeId,
|
|
633
|
-
},
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
'term': {
|
|
637
|
-
'log_subtype.keyword': 'System_Status',
|
|
638
|
-
},
|
|
639
|
-
},
|
|
640
|
-
],
|
|
641
597
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
598
|
+
if ( appCrashTimeResult.body.hits.hits && appCrashTimeResult.body.hits.hits.length > 0 ) {
|
|
599
|
+
const crashTime = appCrashTimeResult.body.hits.hits.find( ( sourceData ) =>
|
|
600
|
+
Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ),
|
|
601
|
+
);
|
|
602
|
+
response.AppCrashtime = crashTime ? crashTime._source.data.occuringTime : '';
|
|
603
|
+
}
|
|
647
604
|
|
|
648
|
-
|
|
649
|
-
if ( screenStatus&& screenStatus.body.hits.hits&&screenStatus.body.hits.hits.length > 0 ) {
|
|
605
|
+
if ( screenStatusResult.body.hits.hits && screenStatusResult.body.hits.hits.length > 0 ) {
|
|
650
606
|
let suspendedTime;
|
|
651
607
|
let resumedTime;
|
|
652
608
|
const differences = [];
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] )== Number( fromTime.split( ':' )[0] ) ) {
|
|
609
|
+
for ( const sourceData of screenStatusResult.body.hits.hits ) {
|
|
610
|
+
if ( Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) ) {
|
|
656
611
|
if ( sourceData._source.data.message.trim() === 'SYSTEM SUSPENDED' ) {
|
|
657
612
|
suspendedTime = sourceData._source.data.occuringTime;
|
|
658
613
|
} else if ( sourceData._source.data.message.trim() === 'SYSTEM RESUMED' ) {
|
|
@@ -671,96 +626,30 @@ export async function viewedgeAppLog( req, res ) {
|
|
|
671
626
|
}
|
|
672
627
|
}
|
|
673
628
|
}
|
|
674
|
-
response.screenStatus = differences.length>0
|
|
629
|
+
response.screenStatus = differences.length > 0 ? `${differences[0].minutes}Mins ${differences[0].seconds}Sec` : '';
|
|
675
630
|
}
|
|
676
|
-
const FileCountQuery = {
|
|
677
|
-
'size': 1000,
|
|
678
|
-
'query': {
|
|
679
|
-
'bool': {
|
|
680
|
-
'must': [
|
|
681
|
-
{
|
|
682
|
-
'term': {
|
|
683
|
-
'log_type.keyword': 'Application',
|
|
684
|
-
},
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
'term': {
|
|
688
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
689
|
-
},
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
'term': {
|
|
693
|
-
'storeId.keyword': req.body.storeId,
|
|
694
|
-
},
|
|
695
|
-
},
|
|
696
|
-
{
|
|
697
|
-
'term': {
|
|
698
|
-
'log_subtype.keyword': 'Zip_File_Count',
|
|
699
|
-
},
|
|
700
|
-
},
|
|
701
|
-
],
|
|
702
|
-
|
|
703
|
-
},
|
|
704
|
-
},
|
|
705
631
|
|
|
706
|
-
|
|
707
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
708
|
-
],
|
|
709
|
-
};
|
|
710
|
-
const newFilesCount = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, FileCountQuery );
|
|
711
|
-
if ( newFilesCount&& newFilesCount.body.hits && newFilesCount.body.hits.hits.length > 0 ) {
|
|
632
|
+
if ( fileCountResult.body.hits.hits && fileCountResult.body.hits.hits.length > 0 ) {
|
|
712
633
|
response.filesPushed = 0;
|
|
713
|
-
response.
|
|
714
|
-
for ( const
|
|
715
|
-
if (
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
response.files_genrated = response.files_generated+Number( sourcedata._source.data.files_generated );
|
|
719
|
-
}
|
|
634
|
+
response.files_generated = 0;
|
|
635
|
+
for ( const sourceData of fileCountResult.body.hits.hits ) {
|
|
636
|
+
if ( sourceData._source && Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) ) {
|
|
637
|
+
response.filesPushed += Number( sourceData._source.data.files_pushed );
|
|
638
|
+
response.files_generated += Number( sourceData._source.data.files_generated );
|
|
720
639
|
}
|
|
721
640
|
}
|
|
722
641
|
} else {
|
|
723
642
|
response.filesPushed = '';
|
|
724
|
-
response.
|
|
643
|
+
response.files_generated = '';
|
|
725
644
|
}
|
|
726
645
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
'term': {
|
|
735
|
-
'log_type.keyword': 'Application',
|
|
736
|
-
},
|
|
737
|
-
},
|
|
738
|
-
{
|
|
739
|
-
'term': {
|
|
740
|
-
'store_id.keyword': req.body.storeId,
|
|
741
|
-
},
|
|
742
|
-
},
|
|
743
|
-
{
|
|
744
|
-
'term': {
|
|
745
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
746
|
-
},
|
|
747
|
-
},
|
|
748
|
-
{
|
|
749
|
-
'term': {
|
|
750
|
-
'log_subtype.keyword': 'Anti_Virus',
|
|
751
|
-
},
|
|
752
|
-
},
|
|
753
|
-
],
|
|
754
|
-
|
|
755
|
-
},
|
|
756
|
-
},
|
|
757
|
-
'sort': [
|
|
758
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
759
|
-
],
|
|
760
|
-
},
|
|
761
|
-
);
|
|
762
|
-
response.antiVirus = antiVirus.body.hits.hits.length > 0 && antiVirus.body.hits.hits[0]._source.data.message == 'st-launch-1.0.exe is deleted' ? antiVirus.body.hits.hits[0]._source.data.occuringTime : '';
|
|
763
|
-
|
|
646
|
+
if ( antiVirusResult.body.hits.hits && antiVirusResult.body.hits.hits.length > 0 ) {
|
|
647
|
+
const antivirusEvent = antiVirusResult.body.hits.hits.find( ( sourceData ) =>
|
|
648
|
+
Number( sourceData._source.data.occuringTime.split( ':' )[0] ) === Number( fromTime.split( ':' )[0] ) &&
|
|
649
|
+
sourceData._source.data.message === 'st-launch-1.0.exe is deleted',
|
|
650
|
+
);
|
|
651
|
+
response.antiVirus = antivirusEvent ? antivirusEvent._source.data.occuringTime : '';
|
|
652
|
+
}
|
|
764
653
|
|
|
765
654
|
res.sendSuccess( response );
|
|
766
655
|
} catch ( error ) {
|
|
@@ -769,6 +658,7 @@ export async function viewedgeAppLog( req, res ) {
|
|
|
769
658
|
}
|
|
770
659
|
}
|
|
771
660
|
|
|
661
|
+
|
|
772
662
|
export async function cameraAngleChange( req, res ) {
|
|
773
663
|
try {
|
|
774
664
|
const angleChange = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).cameraAngleChange,
|
|
@@ -849,27 +739,30 @@ export async function datewiseDowntime( req, res ) {
|
|
|
849
739
|
try {
|
|
850
740
|
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
851
741
|
if ( !store ) {
|
|
852
|
-
return res.sendError( '
|
|
742
|
+
return res.sendError( 'Store Not Found', 204 );
|
|
853
743
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
744
|
+
|
|
745
|
+
const startHour = parseInt( store.storeProfile.open.split( ':' )[0], 10 );
|
|
746
|
+
const endHour = parseInt( store.storeProfile.close.split( ':' )[0], 10 );
|
|
747
|
+
|
|
748
|
+
const datesArray = getDatesArray( req.body.fromDate, req.body.toDate );
|
|
749
|
+
const paginatedDates = paginateArray( datesArray, req.body.offset, req.body.limit );
|
|
750
|
+
|
|
751
|
+
const resultPromises = paginatedDates.map( ( singleDate ) => {
|
|
752
|
+
const inputData = {
|
|
862
753
|
start: startHour,
|
|
863
754
|
end: endHour,
|
|
864
755
|
interval: 60,
|
|
865
756
|
};
|
|
866
757
|
req.body.Date = singleDate;
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
758
|
+
return livecountCheck( inputData, singleDate, req );
|
|
759
|
+
} );
|
|
760
|
+
|
|
761
|
+
const result = await Promise.all( resultPromises );
|
|
762
|
+
|
|
870
763
|
res.sendSuccess( {
|
|
871
764
|
count: datesArray.length,
|
|
872
|
-
data: result,
|
|
765
|
+
data: result.flat(), // Flatten the array of arrays
|
|
873
766
|
} );
|
|
874
767
|
} catch ( error ) {
|
|
875
768
|
logger.error( { error: error, function: 'datewiseDowntime' } );
|
|
@@ -880,55 +773,47 @@ export async function streamwiseDowntime( req, res ) {
|
|
|
880
773
|
try {
|
|
881
774
|
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
882
775
|
if ( !store ) {
|
|
883
|
-
return res.sendError( '
|
|
776
|
+
return res.sendError( 'Store not found', 204 );
|
|
884
777
|
}
|
|
885
|
-
|
|
886
|
-
|
|
778
|
+
|
|
779
|
+
const startHour = store.storeProfile.open.split( ':' )[0];
|
|
780
|
+
const endHour = store.storeProfile.close.split( ':' )[0];
|
|
887
781
|
const interval = 60; // 1 hour in minutes
|
|
888
782
|
const TimeSlots = generateTimeSlots( startHour, endHour, interval, req );
|
|
889
|
-
let timewise = [];
|
|
890
|
-
for ( const obj of TimeSlots ) {
|
|
891
|
-
obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
|
|
892
|
-
obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
|
|
893
|
-
let downTimeQuery = {
|
|
894
|
-
'size': 1,
|
|
895
|
-
'query': {
|
|
896
|
-
'bool': {
|
|
897
|
-
'must': [
|
|
898
|
-
{
|
|
899
|
-
'term': {
|
|
900
|
-
'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
901
|
-
},
|
|
902
|
-
},
|
|
903
|
-
{
|
|
904
|
-
'term': {
|
|
905
|
-
'doc.store_id.keyword': req.body.storeId,
|
|
906
|
-
},
|
|
907
|
-
},
|
|
908
|
-
{
|
|
909
|
-
'term': {
|
|
910
|
-
'doc.hour.keyword': obj.hour,
|
|
911
|
-
},
|
|
912
|
-
},
|
|
913
|
-
],
|
|
914
783
|
|
|
784
|
+
const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
|
|
785
|
+
const downTimeIndex = parsedOpenSearch.downTimeHourly;
|
|
786
|
+
|
|
787
|
+
const batchRequests = TimeSlots.map( async ( obj ) => {
|
|
788
|
+
const formattedDate = dayjs( obj.from ).format( 'DD-MM-YYYY' );
|
|
789
|
+
const downTimeQuery = {
|
|
790
|
+
size: 1,
|
|
791
|
+
query: {
|
|
792
|
+
bool: {
|
|
793
|
+
must: [
|
|
794
|
+
{ term: { 'doc.date.keyword': formattedDate } },
|
|
795
|
+
{ term: { 'doc.store_id.keyword': req.body.storeId } },
|
|
796
|
+
{ term: { 'doc.hour.keyword': obj.hour } },
|
|
797
|
+
],
|
|
915
798
|
},
|
|
916
799
|
},
|
|
917
800
|
};
|
|
918
|
-
const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
|
|
919
801
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
802
|
+
const downtime = await getOpenSearchData( downTimeIndex, downTimeQuery );
|
|
803
|
+
const streamwiseDowntime = downtime.body.hits.hits.length > 0 ?
|
|
804
|
+
downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
|
|
805
|
+
|
|
806
|
+
const foundStream = streamwiseDowntime.find( ( stream ) => stream.stream === req.body.stream );
|
|
807
|
+
return {
|
|
808
|
+
startTime: dayjs( obj.from ).format( 'hh:mm A' ),
|
|
809
|
+
endTime: dayjs( obj.to ).format( 'hh:mm A' ),
|
|
810
|
+
downTime: foundStream ? foundStream.down_time : '',
|
|
811
|
+
hour: obj.hour,
|
|
812
|
+
|
|
813
|
+
};
|
|
814
|
+
} );
|
|
815
|
+
|
|
816
|
+
const timewise = await Promise.all( batchRequests );
|
|
932
817
|
res.sendSuccess( timewise );
|
|
933
818
|
} catch ( error ) {
|
|
934
819
|
logger.error( { error: error, function: 'streamwiseDowntime' } );
|
|
@@ -936,73 +821,61 @@ export async function streamwiseDowntime( req, res ) {
|
|
|
936
821
|
}
|
|
937
822
|
}
|
|
938
823
|
|
|
939
|
-
export async function livecountCheck( inputData, req ) {
|
|
940
|
-
return new Promise( async ( Resolve, Reject ) => {
|
|
941
|
-
try {
|
|
942
|
-
let TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
|
|
943
|
-
let timewise = [];
|
|
944
|
-
for ( const obj of TimeSlots ) {
|
|
945
|
-
obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
|
|
946
|
-
obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
|
|
947
|
-
let downTimeQuery = {
|
|
948
|
-
'size': 1,
|
|
949
|
-
'query': {
|
|
950
|
-
'bool': {
|
|
951
|
-
'must': [
|
|
952
|
-
{
|
|
953
|
-
'term': {
|
|
954
|
-
'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
955
|
-
},
|
|
956
|
-
},
|
|
957
|
-
{
|
|
958
|
-
'term': {
|
|
959
|
-
'doc.store_id.keyword': req.body.storeId,
|
|
960
|
-
},
|
|
961
|
-
},
|
|
962
|
-
{
|
|
963
|
-
'terms': {
|
|
964
|
-
'doc.hour.keyword': [ obj.hour ],
|
|
965
|
-
},
|
|
966
|
-
},
|
|
967
|
-
],
|
|
968
824
|
|
|
969
|
-
|
|
825
|
+
export async function livecountCheck( inputData, singleDate, req ) {
|
|
826
|
+
try {
|
|
827
|
+
const TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
|
|
828
|
+
|
|
829
|
+
const queryPromises = TimeSlots.map( async ( obj ) => {
|
|
830
|
+
obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
|
|
831
|
+
obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
|
|
832
|
+
|
|
833
|
+
const downTimeQuery = {
|
|
834
|
+
size: 1,
|
|
835
|
+
query: {
|
|
836
|
+
bool: {
|
|
837
|
+
must: [
|
|
838
|
+
{ term: { 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ) } },
|
|
839
|
+
{ term: { 'doc.store_id.keyword': req.body.storeId } },
|
|
840
|
+
{ terms: { 'doc.hour.keyword': [ obj.hour ] } },
|
|
841
|
+
],
|
|
970
842
|
},
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
|
|
974
|
-
if ( streamwiseDowntime.length > 0 ) {
|
|
975
|
-
const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
|
|
976
|
-
return accumulator + currentValue.down_time;
|
|
977
|
-
}, 0 );
|
|
978
|
-
const average = sum / streamwiseDowntime.length;
|
|
979
|
-
obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
|
|
980
|
-
} else {
|
|
981
|
-
obj[obj.startTime + '-' + obj.endTime] = '';
|
|
982
|
-
}
|
|
843
|
+
},
|
|
844
|
+
};
|
|
983
845
|
|
|
984
|
-
|
|
846
|
+
const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
|
|
847
|
+
const streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
|
|
848
|
+
if ( streamwiseDowntime.length > 0 ) {
|
|
849
|
+
const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => accumulator + currentValue.down_time, 0 );
|
|
850
|
+
const average = sum / streamwiseDowntime.length;
|
|
851
|
+
obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
|
|
852
|
+
} else {
|
|
853
|
+
obj[obj.startTime + '-' + obj.endTime] = '';
|
|
985
854
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
855
|
+
return obj;
|
|
856
|
+
} );
|
|
857
|
+
|
|
858
|
+
const timewise = await Promise.all( queryPromises );
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
const mergedData = {
|
|
862
|
+
Date: dayjs( singleDate ).format( 'YYYY-MM-DD' ),
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
timewise.forEach( ( obj ) => {
|
|
866
|
+
for ( const key in obj ) {
|
|
867
|
+
if ( key !== 'hour' && key !== 'from' && key !== 'to' && key !== 'startTime' && key !== 'endTime' && key !== 'clientId' ) {
|
|
868
|
+
if ( mergedData[key] ) {
|
|
869
|
+
mergedData[key] += obj[key];
|
|
870
|
+
} else {
|
|
871
|
+
mergedData[key] = obj[key];
|
|
997
872
|
}
|
|
998
873
|
}
|
|
999
|
-
}
|
|
874
|
+
}
|
|
875
|
+
} );
|
|
1000
876
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
Reject( err );
|
|
1006
|
-
}
|
|
1007
|
-
} );
|
|
877
|
+
return [ mergedData ];
|
|
878
|
+
} catch ( err ) {
|
|
879
|
+
throw err;
|
|
880
|
+
}
|
|
1008
881
|
}
|