tango-app-api-infra 3.1.17 → 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 +422 -326
- package/src/controllers/dataMismatch.controller.js +13 -1
- package/src/controllers/infra.controllers.js +14 -3
- package/src/controllers/internalInfra.controller.js +1 -1
- package/src/controllers/storeInfra.controlller.js +351 -479
- 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,174 +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
|
-
'size': 1000,
|
|
298
|
-
'query': {
|
|
299
|
-
'bool': {
|
|
300
|
-
'must': [
|
|
301
|
-
{
|
|
302
|
-
'term': {
|
|
303
|
-
'log_type.keyword': 'Application',
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
'term': {
|
|
308
|
-
'store_date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
'term': {
|
|
313
|
-
'storeId.keyword': req.body.storeId,
|
|
314
|
-
},
|
|
315
|
-
},
|
|
316
|
-
{
|
|
317
|
-
'term': {
|
|
318
|
-
'log_subtype.keyword': 'Speed_Test',
|
|
319
|
-
},
|
|
320
|
-
},
|
|
321
|
-
],
|
|
322
|
-
},
|
|
323
|
-
},
|
|
324
|
-
'sort': [
|
|
325
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
326
|
-
],
|
|
327
|
-
};
|
|
328
|
-
let speedTest = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, internetSpeedQuery );
|
|
329
|
-
if ( speedTest&& speedTest.body.hits && speedTest.body.hits.hits.length > 0 ) {
|
|
330
|
-
for ( const sourcedata of speedTest.body.hits.hits ) {
|
|
331
|
-
if ( sourcedata._source ) {
|
|
332
|
-
if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==obj.hour ) {
|
|
333
|
-
const megabytes = bytesToMB( sourcedata._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 );
|
|
334
|
-
obj.Internetspeed = megabytes+ ' MB/sec';
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
} else {
|
|
339
|
-
obj.Internetspeed = '';
|
|
340
|
-
}
|
|
341
|
-
let FileCountQuery = {
|
|
342
|
-
'size': 1000,
|
|
343
|
-
'query': {
|
|
344
|
-
'bool': {
|
|
345
|
-
'must': [
|
|
346
|
-
{
|
|
347
|
-
'term': {
|
|
348
|
-
'log_type.keyword': 'Application',
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
'term': {
|
|
353
|
-
'store_date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
'term': {
|
|
358
|
-
'storeId.keyword': req.body.storeId,
|
|
359
|
-
},
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
'term': {
|
|
363
|
-
'log_subtype.keyword': 'Zip_File_Count',
|
|
364
|
-
},
|
|
365
|
-
},
|
|
366
|
-
],
|
|
367
363
|
|
|
368
|
-
|
|
369
|
-
},
|
|
364
|
+
// Internet speed
|
|
370
365
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if ( newFilesCount&& newFilesCount.body.hits && newFilesCount.body.hits.hits.length > 0 ) {
|
|
377
|
-
obj.files_pushed = 0;
|
|
378
|
-
obj.files_generated = 0;
|
|
379
|
-
for ( let sourcedata of newFilesCount.body.hits.hits ) {
|
|
380
|
-
if ( sourcedata._source ) {
|
|
381
|
-
if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==obj.hour ) {
|
|
382
|
-
obj.files_pushed = obj.files_pushed+Number( sourcedata._source.data.files_pushed );
|
|
383
|
-
obj.files_generated = obj.files_generated+Number( sourcedata._source.data.files_generated );
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
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';
|
|
387
371
|
} else {
|
|
388
|
-
obj.
|
|
389
|
-
obj.files_generated = '';
|
|
372
|
+
obj.Internetspeed = speedTest ? `${bytesToMB( speedTest._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 )} MB/sec` : '';
|
|
390
373
|
}
|
|
391
|
-
let downTimeQuery = {
|
|
392
|
-
'size': 1000,
|
|
393
|
-
'query': {
|
|
394
|
-
'bool': {
|
|
395
|
-
'must': [
|
|
396
|
-
{
|
|
397
|
-
'term': {
|
|
398
|
-
'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
'term': {
|
|
403
|
-
'doc.store_id.keyword': req.body.storeId,
|
|
404
|
-
},
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
'terms': {
|
|
408
|
-
'doc.hour.keyword': [ obj.hour ],
|
|
409
|
-
},
|
|
410
|
-
},
|
|
411
|
-
],
|
|
412
374
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
+
}
|
|
424
396
|
} else {
|
|
425
397
|
obj.downtime = '';
|
|
426
398
|
}
|
|
427
399
|
}
|
|
400
|
+
|
|
428
401
|
if ( req.body.export ) {
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
} );
|
|
438
|
-
} );
|
|
439
|
-
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 );
|
|
440
410
|
return;
|
|
441
411
|
}
|
|
412
|
+
|
|
442
413
|
res.sendSuccess( timeSlots );
|
|
443
414
|
} catch ( error ) {
|
|
444
|
-
logger.error( { error
|
|
415
|
+
logger.error( { error, function: 'edgeAppLog' } );
|
|
445
416
|
return res.sendError( error, 500 );
|
|
446
417
|
}
|
|
447
418
|
}
|
|
419
|
+
|
|
448
420
|
function bytesToMB( bytes ) {
|
|
449
421
|
return bytes / ( 1024 * 1024 );
|
|
450
422
|
}
|
|
451
423
|
function generateTimeSlots( startHour, endHour, interval, req ) {
|
|
452
424
|
try {
|
|
453
425
|
const timeSlots = [];
|
|
454
|
-
for ( let hour = startHour; hour
|
|
426
|
+
for ( let hour = startHour; hour < endHour; hour++ ) {
|
|
455
427
|
for ( let minute = 0; minute < 60; minute += interval ) {
|
|
456
428
|
let isoDate = new Date();
|
|
457
429
|
|
|
@@ -488,172 +460,154 @@ export async function viewedgeAppLog( req, res ) {
|
|
|
488
460
|
try {
|
|
489
461
|
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
490
462
|
if ( !store ) {
|
|
491
|
-
return res.sendError( 'Stores Not
|
|
463
|
+
return res.sendError( 'Stores Not found', 204 );
|
|
492
464
|
}
|
|
493
|
-
const inputDate = dayjs( req.body.Date ).format( '
|
|
465
|
+
const inputDate = dayjs( req.body.Date ).format( 'DD-MM-YYYY' );
|
|
494
466
|
const fromTime = req.body.from;
|
|
495
467
|
const toTime = req.body.to;
|
|
496
468
|
let response = {};
|
|
497
469
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
{
|
|
505
|
-
|
|
506
|
-
'log_type.keyword': 'Application',
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
},
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
'term': {
|
|
516
|
-
'store_id.keyword': req.body.storeId,
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
{
|
|
520
|
-
'term': {
|
|
521
|
-
'log_subtype.keyword': 'AppStart_Time',
|
|
522
|
-
},
|
|
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
|
+
],
|
|
523
484
|
},
|
|
524
|
-
|
|
525
|
-
|
|
485
|
+
},
|
|
526
486
|
},
|
|
527
487
|
},
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
},
|
|
542
|
-
},
|
|
543
|
-
{
|
|
544
|
-
'term': {
|
|
545
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
546
|
-
},
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
'term': {
|
|
550
|
-
'store_id.keyword': req.body.storeId,
|
|
551
|
-
},
|
|
552
|
-
},
|
|
553
|
-
{
|
|
554
|
-
'term': {
|
|
555
|
-
'log_subtype.keyword': 'App_Quit',
|
|
556
|
-
},
|
|
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
|
+
],
|
|
557
501
|
},
|
|
558
|
-
|
|
559
|
-
|
|
502
|
+
},
|
|
503
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
560
504
|
},
|
|
561
505
|
},
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
let appCrashTimeQuery = {
|
|
575
|
-
'size': 1000,
|
|
576
|
-
'query': {
|
|
577
|
-
'bool': {
|
|
578
|
-
'must': [
|
|
579
|
-
{
|
|
580
|
-
'term': {
|
|
581
|
-
'log_type.keyword': 'Application',
|
|
582
|
-
},
|
|
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
|
+
],
|
|
583
518
|
},
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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
|
+
],
|
|
588
535
|
},
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
+
],
|
|
593
552
|
},
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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
|
+
],
|
|
598
569
|
},
|
|
599
|
-
|
|
600
|
-
|
|
570
|
+
},
|
|
571
|
+
sort: [ { timestamp: { order: 'desc' } } ],
|
|
601
572
|
},
|
|
602
573
|
},
|
|
603
|
-
|
|
604
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
605
|
-
],
|
|
606
|
-
};
|
|
574
|
+
];
|
|
607
575
|
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
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 : '';
|
|
615
596
|
}
|
|
616
|
-
const screenStatus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
|
|
617
|
-
'size': 1000,
|
|
618
|
-
'query': {
|
|
619
|
-
'bool': {
|
|
620
|
-
'must': [
|
|
621
|
-
{
|
|
622
|
-
'term': {
|
|
623
|
-
'log_type.keyword': 'Application',
|
|
624
|
-
},
|
|
625
|
-
},
|
|
626
|
-
{
|
|
627
|
-
'term': {
|
|
628
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
629
|
-
},
|
|
630
|
-
},
|
|
631
|
-
{
|
|
632
|
-
'term': {
|
|
633
|
-
'store_id.keyword': req.body.storeId,
|
|
634
|
-
},
|
|
635
|
-
},
|
|
636
|
-
{
|
|
637
|
-
'term': {
|
|
638
|
-
'log_subtype.keyword': 'System_Status',
|
|
639
|
-
},
|
|
640
|
-
},
|
|
641
|
-
],
|
|
642
597
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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
|
+
}
|
|
648
604
|
|
|
649
|
-
|
|
650
|
-
if ( screenStatus&& screenStatus.body.hits.hits&&screenStatus.body.hits.hits.length > 0 ) {
|
|
605
|
+
if ( screenStatusResult.body.hits.hits && screenStatusResult.body.hits.hits.length > 0 ) {
|
|
651
606
|
let suspendedTime;
|
|
652
607
|
let resumedTime;
|
|
653
608
|
const differences = [];
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
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] ) ) {
|
|
657
611
|
if ( sourceData._source.data.message.trim() === 'SYSTEM SUSPENDED' ) {
|
|
658
612
|
suspendedTime = sourceData._source.data.occuringTime;
|
|
659
613
|
} else if ( sourceData._source.data.message.trim() === 'SYSTEM RESUMED' ) {
|
|
@@ -672,96 +626,30 @@ export async function viewedgeAppLog( req, res ) {
|
|
|
672
626
|
}
|
|
673
627
|
}
|
|
674
628
|
}
|
|
675
|
-
response.screenStatus = differences.length>0
|
|
629
|
+
response.screenStatus = differences.length > 0 ? `${differences[0].minutes}Mins ${differences[0].seconds}Sec` : '';
|
|
676
630
|
}
|
|
677
|
-
const FileCountQuery = {
|
|
678
|
-
'size': 1000,
|
|
679
|
-
'query': {
|
|
680
|
-
'bool': {
|
|
681
|
-
'must': [
|
|
682
|
-
{
|
|
683
|
-
'term': {
|
|
684
|
-
'log_type.keyword': 'Application',
|
|
685
|
-
},
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
'term': {
|
|
689
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
690
|
-
},
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
'term': {
|
|
694
|
-
'storeId.keyword': req.body.storeId,
|
|
695
|
-
},
|
|
696
|
-
},
|
|
697
|
-
{
|
|
698
|
-
'term': {
|
|
699
|
-
'log_subtype.keyword': 'Zip_File_Count',
|
|
700
|
-
},
|
|
701
|
-
},
|
|
702
|
-
],
|
|
703
|
-
|
|
704
|
-
},
|
|
705
|
-
},
|
|
706
631
|
|
|
707
|
-
|
|
708
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
709
|
-
],
|
|
710
|
-
};
|
|
711
|
-
const newFilesCount = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, FileCountQuery );
|
|
712
|
-
if ( newFilesCount&& newFilesCount.body.hits && newFilesCount.body.hits.hits.length > 0 ) {
|
|
632
|
+
if ( fileCountResult.body.hits.hits && fileCountResult.body.hits.hits.length > 0 ) {
|
|
713
633
|
response.filesPushed = 0;
|
|
714
|
-
response.
|
|
715
|
-
for ( const
|
|
716
|
-
if (
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
response.files_genrated = response.files_generated+Number( sourcedata._source.data.files_generated );
|
|
720
|
-
}
|
|
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 );
|
|
721
639
|
}
|
|
722
640
|
}
|
|
723
641
|
} else {
|
|
724
642
|
response.filesPushed = '';
|
|
725
|
-
response.
|
|
643
|
+
response.files_generated = '';
|
|
726
644
|
}
|
|
727
645
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
'term': {
|
|
736
|
-
'log_type.keyword': 'Application',
|
|
737
|
-
},
|
|
738
|
-
},
|
|
739
|
-
{
|
|
740
|
-
'term': {
|
|
741
|
-
'store_id.keyword': req.body.storeId,
|
|
742
|
-
},
|
|
743
|
-
},
|
|
744
|
-
{
|
|
745
|
-
'term': {
|
|
746
|
-
'store_date.keyword': dayjs( inputDate ).format( 'DD-MM-YYYY' ),
|
|
747
|
-
},
|
|
748
|
-
},
|
|
749
|
-
{
|
|
750
|
-
'term': {
|
|
751
|
-
'log_subtype.keyword': 'Anti_Virus',
|
|
752
|
-
},
|
|
753
|
-
},
|
|
754
|
-
],
|
|
755
|
-
|
|
756
|
-
},
|
|
757
|
-
},
|
|
758
|
-
'sort': [
|
|
759
|
-
{ 'timestamp': { 'order': 'desc' } },
|
|
760
|
-
],
|
|
761
|
-
},
|
|
762
|
-
);
|
|
763
|
-
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 : '';
|
|
764
|
-
|
|
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
|
+
}
|
|
765
653
|
|
|
766
654
|
res.sendSuccess( response );
|
|
767
655
|
} catch ( error ) {
|
|
@@ -770,6 +658,7 @@ export async function viewedgeAppLog( req, res ) {
|
|
|
770
658
|
}
|
|
771
659
|
}
|
|
772
660
|
|
|
661
|
+
|
|
773
662
|
export async function cameraAngleChange( req, res ) {
|
|
774
663
|
try {
|
|
775
664
|
const angleChange = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).cameraAngleChange,
|
|
@@ -850,27 +739,30 @@ export async function datewiseDowntime( req, res ) {
|
|
|
850
739
|
try {
|
|
851
740
|
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
852
741
|
if ( !store ) {
|
|
853
|
-
return res.sendError( '
|
|
742
|
+
return res.sendError( 'Store Not Found', 204 );
|
|
854
743
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
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 = {
|
|
863
753
|
start: startHour,
|
|
864
754
|
end: endHour,
|
|
865
755
|
interval: 60,
|
|
866
756
|
};
|
|
867
757
|
req.body.Date = singleDate;
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
758
|
+
return livecountCheck( inputData, singleDate, req );
|
|
759
|
+
} );
|
|
760
|
+
|
|
761
|
+
const result = await Promise.all( resultPromises );
|
|
762
|
+
|
|
871
763
|
res.sendSuccess( {
|
|
872
764
|
count: datesArray.length,
|
|
873
|
-
data: result,
|
|
765
|
+
data: result.flat(), // Flatten the array of arrays
|
|
874
766
|
} );
|
|
875
767
|
} catch ( error ) {
|
|
876
768
|
logger.error( { error: error, function: 'datewiseDowntime' } );
|
|
@@ -881,55 +773,47 @@ export async function streamwiseDowntime( req, res ) {
|
|
|
881
773
|
try {
|
|
882
774
|
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
883
775
|
if ( !store ) {
|
|
884
|
-
return res.sendError( '
|
|
776
|
+
return res.sendError( 'Store not found', 204 );
|
|
885
777
|
}
|
|
886
|
-
|
|
887
|
-
|
|
778
|
+
|
|
779
|
+
const startHour = store.storeProfile.open.split( ':' )[0];
|
|
780
|
+
const endHour = store.storeProfile.close.split( ':' )[0];
|
|
888
781
|
const interval = 60; // 1 hour in minutes
|
|
889
782
|
const TimeSlots = generateTimeSlots( startHour, endHour, interval, req );
|
|
890
|
-
let timewise = [];
|
|
891
|
-
for ( const obj of TimeSlots ) {
|
|
892
|
-
obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
|
|
893
|
-
obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
|
|
894
|
-
let downTimeQuery = {
|
|
895
|
-
'size': 1,
|
|
896
|
-
'query': {
|
|
897
|
-
'bool': {
|
|
898
|
-
'must': [
|
|
899
|
-
{
|
|
900
|
-
'term': {
|
|
901
|
-
'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
902
|
-
},
|
|
903
|
-
},
|
|
904
|
-
{
|
|
905
|
-
'term': {
|
|
906
|
-
'doc.store_id.keyword': req.body.storeId,
|
|
907
|
-
},
|
|
908
|
-
},
|
|
909
|
-
{
|
|
910
|
-
'term': {
|
|
911
|
-
'doc.hour.keyword': obj.hour,
|
|
912
|
-
},
|
|
913
|
-
},
|
|
914
|
-
],
|
|
915
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
|
+
],
|
|
916
798
|
},
|
|
917
799
|
},
|
|
918
800
|
};
|
|
919
|
-
const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
|
|
920
801
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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 );
|
|
933
817
|
res.sendSuccess( timewise );
|
|
934
818
|
} catch ( error ) {
|
|
935
819
|
logger.error( { error: error, function: 'streamwiseDowntime' } );
|
|
@@ -937,73 +821,61 @@ export async function streamwiseDowntime( req, res ) {
|
|
|
937
821
|
}
|
|
938
822
|
}
|
|
939
823
|
|
|
940
|
-
export async function livecountCheck( inputData, req ) {
|
|
941
|
-
return new Promise( async ( Resolve, Reject ) => {
|
|
942
|
-
try {
|
|
943
|
-
let TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
|
|
944
|
-
let timewise = [];
|
|
945
|
-
for ( const obj of TimeSlots ) {
|
|
946
|
-
obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
|
|
947
|
-
obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
|
|
948
|
-
let downTimeQuery = {
|
|
949
|
-
'size': 1,
|
|
950
|
-
'query': {
|
|
951
|
-
'bool': {
|
|
952
|
-
'must': [
|
|
953
|
-
{
|
|
954
|
-
'term': {
|
|
955
|
-
'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
956
|
-
},
|
|
957
|
-
},
|
|
958
|
-
{
|
|
959
|
-
'term': {
|
|
960
|
-
'doc.store_id.keyword': req.body.storeId,
|
|
961
|
-
},
|
|
962
|
-
},
|
|
963
|
-
{
|
|
964
|
-
'terms': {
|
|
965
|
-
'doc.hour.keyword': [ obj.hour ],
|
|
966
|
-
},
|
|
967
|
-
},
|
|
968
|
-
],
|
|
969
824
|
|
|
970
|
-
|
|
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
|
+
],
|
|
971
842
|
},
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
|
|
975
|
-
if ( streamwiseDowntime.length > 0 ) {
|
|
976
|
-
const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
|
|
977
|
-
return accumulator + currentValue.down_time;
|
|
978
|
-
}, 0 );
|
|
979
|
-
const average = sum / streamwiseDowntime.length;
|
|
980
|
-
obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
|
|
981
|
-
} else {
|
|
982
|
-
obj[obj.startTime + '-' + obj.endTime] = '';
|
|
983
|
-
}
|
|
843
|
+
},
|
|
844
|
+
};
|
|
984
845
|
|
|
985
|
-
|
|
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] = '';
|
|
986
854
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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];
|
|
998
872
|
}
|
|
999
873
|
}
|
|
1000
|
-
}
|
|
874
|
+
}
|
|
875
|
+
} );
|
|
1001
876
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
Reject( err );
|
|
1007
|
-
}
|
|
1008
|
-
} );
|
|
877
|
+
return [ mergedData ];
|
|
878
|
+
} catch ( err ) {
|
|
879
|
+
throw err;
|
|
880
|
+
}
|
|
1009
881
|
}
|