From 5dac96954321a720ba6728b703920aea97dfced9 Mon Sep 17 00:00:00 2001 From: nices96 Date: Tue, 5 Apr 2016 09:27:39 +0900 Subject: [PATCH] Add feature to alert in case of agent reconnected. --- README.md | 5 +- .../server/alert/email/EmailPlugin.java | 47 ++++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 12876c8..be6fca1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ - Agent의 Memory (warning / fatal) - Agent의 Disk (warning / fatal) - 신규 Agent 연결 - - Agent의 연결 해제 (연결 해제된 Agent의 재접속은 Scouter Server 내부 이슈로 지연) + - Agent의 연결 해제 + - Agent의 재접속 ### Properties (스카우터 서버 설치 경로 하위의 conf/scouter.conf) * **_ext\_plugin\_email\_send_alert_** : Email 발송 여부 (true / false) - 기본 값은 false @@ -38,7 +39,7 @@ ext_plugin_email_to_address=receiver1@scouter.com,receiver2@scouter.com ext_plugin_email_cc_address=ccreceiver@yopmail.com ``` -### dependencies +### Dependencies * Project - scouter.common - scouter.server diff --git a/src/scouter/plugin/server/alert/email/EmailPlugin.java b/src/scouter/plugin/server/alert/email/EmailPlugin.java index 800d36a..e14e05f 100644 --- a/src/scouter/plugin/server/alert/email/EmailPlugin.java +++ b/src/scouter/plugin/server/alert/email/EmailPlugin.java @@ -138,34 +138,35 @@ public void run() { @ServerPlugin(PluginConstants.PLUGIN_SERVER_OBJECT) public void object(ObjectPack pack) { - if (pack.version != null && pack.version.length() > 0) { - AlertPack p = null; - if (pack.wakeup == 0L) { + if (pack.version != null && pack.version.length() > 0) { + AlertPack ap = null; + ObjectPack op = AgentManager.getAgent(pack.objHash); + + if (op == null && pack.wakeup == 0L) { // in case of new agent connected - p = new AlertPack(); - p.level = AlertLevel.INFO; - p.objHash = pack.objHash; - p.title = "An object has been activated."; - p.message = pack.objName + " is connected."; - p.time = System.currentTimeMillis(); - p.objType = "scouter"; + ap = new AlertPack(); + ap.level = AlertLevel.INFO; + ap.objHash = pack.objHash; + ap.title = "An object has been activated."; + ap.message = pack.objName + " is connected."; + ap.time = System.currentTimeMillis(); + ap.objType = "scouter"; - alert(p); - } else if (pack.alive == false) { + alert(ap); + } else if (op.alive == false) { // in case of agent reconnected - p = new AlertPack(); - p.level = AlertLevel.INFO; - p.objHash = pack.objHash; - p.title = "An object has been activated."; - p.message = pack.objName + " is reconnected."; - p.time = System.currentTimeMillis(); - p.objType = "scouter"; + ap = new AlertPack(); + ap.level = AlertLevel.INFO; + ap.objHash = pack.objHash; + ap.title = "An object has been activated."; + ap.message = pack.objName + " is reconnected."; + ap.time = System.currentTimeMillis(); + ap.objType = "scouter"; - alert(p); - } - + alert(ap); + } // inactive state can be handled in alert() method. - } + } } private void println(Object o) {