Skip to content

Commit

Permalink
Add options to ignore given NAME & TITLE patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
nices96 committed Aug 16, 2017
1 parent cd40ec0 commit 7fd70c3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/scouter.common"/>
<classpathentry combineaccessrules="false" kind="src" path="/scouter.server"/>
<classpathentry kind="lib" path="lib/commons-codec-1.9.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.2.jar"/>
<classpathentry kind="lib" path="lib/gson-2.6.2.jar"/>
<classpathentry kind="lib" path="lib/httpclient-4.5.2.jar"/>
<classpathentry kind="lib" path="lib/httpcore-4.4.4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/scouter-common"/>
<classpathentry combineaccessrules="false" kind="src" path="/scouter-server"/>
<classpathentry kind="output" path="bin"/>
</classpath>
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
Expand Down
40 changes: 39 additions & 1 deletion src/scouter/plugin/server/alert/telegram/TelegramPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class TelegramPlugin {

private static AtomicInteger ai = new AtomicInteger(0);
private static List<Integer> javaeeObjHashList = new ArrayList<Integer>();
private static AlertPack lastPack;
private static long lastSentTimestamp;

public TelegramPlugin() {
if (ai.incrementAndGet() == 1) {
Expand Down Expand Up @@ -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" +
Expand All @@ -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.");
Expand Down

0 comments on commit 7fd70c3

Please sign in to comment.