From 7fd70c3b7289e06e86ddcd490155da6acf4a2fb4 Mon Sep 17 00:00:00 2001 From: nices96 Date: Wed, 16 Aug 2017 13:51:07 +0900 Subject: [PATCH] Add options to ignore given NAME & TITLE patterns --- .classpath | 4 +- README.md | 7 ++++ .../server/alert/telegram/TelegramPlugin.java | 40 ++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/.classpath b/.classpath index 26eab0e..b00e304 100644 --- a/.classpath +++ b/.classpath @@ -6,12 +6,12 @@ - - + + diff --git a/README.md b/README.md index fe70b4c..673b32c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ * **_ext\_plugin\_elapsed\_time_threshold_** : 응답시간의 임계치 (ms) - 기본 값은 0으로, 0일때 응답시간의 임계치 초과 여부를 확인하지 않는다. * **_ext\_plugin\_gc\_time_threshold_** : GC Time의 임계치 (ms) - 기본 값은 0으로, 0일때 GC Time의 임계치 초과 여부를 확인하지 않는다. * **_ext\_plugin\_thread\_count_threshold_** : Thread Count의 임계치 - 기본 값은 0으로, 0일때 Thread Count의 임계치 초과 여부를 확인하지 않는다. +* **_ext\_plugin\_ignore\_name_patterns_** : Alert 메시지 발송에서 제외할 NAME 패턴 목록 (',' 구분자 사용, * (wildcard) 사용 가능) +* **_ext\_plugin\_ignore\_title_patterns_** : Alert 메시지 발송에서 제외할 TITLE 패턴 목록 (',' 구분자 사용, * (wildcard) 사용 가능) +* **_ext\_plugin\_ignore\_continuous_dup_alert_** : 연속된 동일 Alert을 1시간 동안 제외 - 기본 값은 false * Example ``` @@ -35,6 +38,10 @@ ext_plugin_telegram_chat_id=@ScouterDemoChannel ext_plugin_elapsed_time_threshold=5000 ext_plugin_gc_time_threshold=5000 ext_plugin_thread_count_threshold=300 + +ext_plugin_ignore_name_patterns=myTomcat1 +ext_plugin_ignore_title_patterns=Elapsed,CONNECTION,activat* +ext_plugin_ignore_continuous_dup_alert=true ``` ### Dependencies diff --git a/src/scouter/plugin/server/alert/telegram/TelegramPlugin.java b/src/scouter/plugin/server/alert/telegram/TelegramPlugin.java index 04db18e..cbf4000 100644 --- a/src/scouter/plugin/server/alert/telegram/TelegramPlugin.java +++ b/src/scouter/plugin/server/alert/telegram/TelegramPlugin.java @@ -67,6 +67,8 @@ public class TelegramPlugin { private static AtomicInteger ai = new AtomicInteger(0); private static List javaeeObjHashList = new ArrayList(); + private static AlertPack lastPack; + private static long lastSentTimestamp; public TelegramPlugin() { if (ai.incrementAndGet() == 1) { @@ -150,7 +152,42 @@ public void run() { title = "An object has been inactivated."; msg = pack.message.substring(0, pack.message.indexOf("OBJECT") - 1); } - + + try { + String ignoreNamePattern = conf.getValue("ext_plugin_ignore_name_patterns"); + String ignoreTitlePattern = conf.getValue("ext_plugin_ignore_title_patterns"); + + if (ignoreNamePattern != null && !"".equals(ignoreNamePattern)) { + for (String pattern : ignoreNamePattern.split(",")) { + if (name.matches(".*[" + pattern.replaceAll("-", "\\\\-") + "].*")) { + return; + } + } + } + + if (ignoreTitlePattern != null && !"".equals(ignoreTitlePattern)) { + for (String pattern : ignoreTitlePattern.split(",")) { + if (title.matches(".*[" + pattern.replaceAll("-", "\\\\-") + "].*")) { + return; + } + } + } + + if (conf.getBoolean("ext_plugin_ignore_continuous_dup_alert", false) && lastPack != null) { + long diff = System.currentTimeMillis() - lastSentTimestamp; + if (lastPack.objHash == pack.objHash + && lastPack.title.equals(pack.title) + && diff < DateUtil.MILLIS_PER_HOUR) { + return; + } + } + + lastPack = pack; + } catch (Exception e) { + // ignore + println("[Error] : " + e.getMessage()); + } + // Make message contents String contents = "[TYPE] : " + pack.objType.toUpperCase() + "\n" + "[NAME] : " + name + "\n" + @@ -171,6 +208,7 @@ public void run() { HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + lastSentTimestamp = System.currentTimeMillis(); println("Telegram message sent to [" + chatId + "] successfully."); } else { println("Telegram message sent failed. Verify below information.");