@@ -498,6 +498,10 @@ SuperAdmin.sysinfo = function(callback) {
498
498
callback && callback ( null , SuperAdmin . server ) ;
499
499
MAIN . ws && MAIN . ws . send ( SuperAdmin . server ) ;
500
500
SuperAdmin . notify_system ( ) ;
501
+
502
+ var publish = CLONE ( SuperAdmin . server ) ;
503
+ publish . dttms = NOW ;
504
+ PUBLISH ( 'system_monitor' , publish ) ;
501
505
} ) ;
502
506
503
507
} ;
@@ -969,6 +973,28 @@ SuperAdmin.save = function(callback, stats) {
969
973
for ( var i = 0 ; i < APPLICATIONS . length ; i ++ ) {
970
974
var app = APPLICATIONS [ i ] ;
971
975
if ( app . current ) {
976
+
977
+ var current = app . current ;
978
+ var obj = { } ;
979
+ obj . id = app . id ;
980
+ obj . url = app . url ;
981
+ obj . name = app . name ;
982
+ obj . category = app . category ;
983
+ obj . note = app . note ;
984
+ obj . port = current . port ;
985
+ obj . pid = current . pid ;
986
+ obj . cpu = current . cpu ;
987
+ obj . memory = current . memory ;
988
+ obj . openfiles = current . openfiles ;
989
+ obj . connections = current . connections ;
990
+ obj . hdd = current . hdd ;
991
+ obj . version = app . version ;
992
+ obj . analyzator = app . analyzatoroutput ;
993
+ obj . ssl = app . ssl ;
994
+ obj . dtmonitor = NOW ;
995
+ obj . dttms = NOW ;
996
+ PUBLISH ( 'apps_monitor' , obj ) ;
997
+
972
998
delete app . current . TYPE ;
973
999
delete app . current . id ;
974
1000
delete app . current . analyzator ;
@@ -1359,23 +1385,36 @@ SuperAdmin.notify = function(app, type, callback) {
1359
1385
data . push ( 'FILES: ' + app . current . openfiles ) ;
1360
1386
data . push ( 'ANALYZATOR: ' + ( app . analyzatoroutput || 'none' ) ) ;
1361
1387
1388
+ var type = 'warning' ;
1362
1389
var message = item . message . format ( app . url ) + ' (' + data . join ( ', ' ) + ')' ;
1363
1390
1364
- LOGGER ( 'alarms' , item . name , message ) ;
1365
- EMIT ( 'superadmin_app_alarm' , app , item , message ) ;
1391
+ SuperAdmin . check_notify ( type , item . message , function ( notified ) {
1392
+
1393
+ if ( notified ) {
1394
+ next ( ) ;
1395
+ return ;
1396
+ }
1366
1397
1367
- if ( app . stats )
1368
- app . stats . alarms ++ ;
1369
- else
1370
- app . stats . alarms = 1 ;
1398
+ LOGGER ( 'alarms' , item . name , message ) ;
1399
+ EMIT ( 'superadmin_app_alarm' , app , item , message ) ;
1371
1400
1372
- SuperAdmin . send_notify ( 'warning' , message ) ;
1373
- NOSQL ( 'alarms' ) . modify ( { '+notified' : 1 , dtnotified : NOW } ) . id ( item . id ) ;
1374
- item . phone && SuperAdmin . send_sms ( item . phone , message . removeTags ( ) ) ;
1375
- item . email && SuperAdmin . send_email ( item . email , message , item . name ) ;
1376
- }
1401
+ if ( app . stats )
1402
+ app . stats . alarms ++ ;
1403
+ else
1404
+ app . stats . alarms = 1 ;
1377
1405
1378
- next ( ) ;
1406
+ SuperAdmin . send_notify ( type , message , item . message ) ;
1407
+ NOSQL ( 'alarms' ) . modify ( { '+notified' : 1 , dtnotified : NOW } ) . id ( item . id ) ;
1408
+ item . phone && SuperAdmin . send_sms ( item . phone , message . removeTags ( ) ) ;
1409
+ item . email && SuperAdmin . send_email ( item . email , message , item . name ) ;
1410
+
1411
+ PUBLISH ( 'notify_apps' , { type : type , body : message , message : item . message , dtnotified : NOW , dttms : NOW } ) ;
1412
+
1413
+ next ( ) ;
1414
+ } ) ;
1415
+
1416
+ } else
1417
+ next ( ) ;
1379
1418
1380
1419
} , callback ) ;
1381
1420
} ;
@@ -1407,19 +1446,38 @@ SuperAdmin.notify_system = function() {
1407
1446
data . push ( 'RAM: ' + SuperAdmin . server . memused . filesize ( ) ) ;
1408
1447
data . push ( 'HDD: ' + SuperAdmin . server . hddused . filesize ( ) ) ;
1409
1448
1449
+ var type = 'warning' ;
1410
1450
var message = item . message + ' (' + data . join ( ', ' ) + ')' ;
1411
1451
1412
- LOGGER ( 'alarms' , item . name , message ) ;
1413
- EMIT ( 'superadmin_system_alarm' , SuperAdmin . server , item , message ) ;
1452
+ SuperAdmin . check_notify ( type , item . message , function ( notified ) {
1414
1453
1415
- SuperAdmin . send_notify ( 'warning' , message ) ;
1416
- NOSQL ( 'alarms' ) . modify ( { '+notified' : 1 , dtnotified : NOW } ) . id ( item . id ) ;
1417
- item . phone && SuperAdmin . send_sms ( item . phone , message . removeTags ( ) ) ;
1418
- item . email && SuperAdmin . send_email ( item . email , message , item . name ) ;
1419
- }
1454
+ if ( notified ) {
1455
+ next ( ) ;
1456
+ return ;
1457
+ }
1420
1458
1421
- next ( ) ;
1459
+ LOGGER ( 'alarms' , item . name , message ) ;
1460
+ EMIT ( 'superadmin_system_alarm' , SuperAdmin . server , item , message ) ;
1461
+
1462
+ SuperAdmin . send_notify ( type , message , item . message ) ;
1463
+ NOSQL ( 'alarms' ) . modify ( { '+notified' : 1 , dtnotified : NOW } ) . id ( item . id ) ;
1464
+ item . phone && SuperAdmin . send_sms ( item . phone , message . removeTags ( ) ) ;
1465
+ item . email && SuperAdmin . send_email ( item . email , message , item . name ) ;
1466
+
1467
+ PUBLISH ( 'notify_system' , { type : type , body : message , message : item . message , dtnotified : NOW , dttms : NOW } ) ;
1468
+
1469
+ next ( ) ;
1470
+ } ) ;
1422
1471
1472
+ } else
1473
+ next ( ) ;
1474
+
1475
+ } ) ;
1476
+ } ;
1477
+
1478
+ SuperAdmin . check_notify = function ( type , message , callback ) {
1479
+ NOSQL ( 'notifications' ) . one ( ) . where ( 'message' , message ) . where ( 'type' , type ) . error ( 404 ) . callback ( function ( err ) {
1480
+ callback ( ! err ) ;
1423
1481
} ) ;
1424
1482
} ;
1425
1483
@@ -1436,14 +1494,17 @@ SuperAdmin.send_sms = function(numbers, message) {
1436
1494
} ;
1437
1495
1438
1496
SuperAdmin . send_email = function ( addresses , message , name ) {
1497
+ if ( ! addresses || ! addresses . length )
1498
+ return ;
1499
+
1439
1500
var message = LOGMAIL ( addresses [ 0 ] , name , message ) ;
1440
1501
for ( var i = 1 ; i < addresses . length ; i ++ )
1441
1502
message . to ( addresses [ i ] ) ;
1442
1503
} ;
1443
1504
1444
- SuperAdmin . send_notify = function ( type , body ) {
1505
+ SuperAdmin . send_notify = function ( type , body , message ) {
1445
1506
PREF . set ( 'notifications' , ( PREF . notifications || 0 ) + 1 ) ;
1446
- NOSQL ( 'notifications' ) . insert ( { type : type , body : body , dtcreated : NOW } ) ;
1507
+ NOSQL ( 'notifications' ) . insert ( { type : type , body : body , message : message , dtcreated : NOW } ) ;
1447
1508
} ;
1448
1509
1449
1510
SuperAdmin . init ( ) ;
0 commit comments