Skip to content

Commit 1aaea9d

Browse files
authored
Merge pull request #9 from nices96/master
Add options to ignore given NAME & TITLE patterns
2 parents 3e791e5 + 0149763 commit 1aaea9d

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

.classpath

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<attribute name="owner.project.facets" value="java"/>
77
</attributes>
88
</classpathentry>
9-
<classpathentry combineaccessrules="false" kind="src" path="/scouter.common"/>
10-
<classpathentry combineaccessrules="false" kind="src" path="/scouter.server"/>
119
<classpathentry kind="lib" path="lib/activation-1.1.1.jar"/>
1210
<classpathentry kind="lib" path="lib/commons-email-1.4.jar"/>
1311
<classpathentry kind="lib" path="lib/javax.mail-1.5.2.jar"/>
12+
<classpathentry combineaccessrules="false" kind="src" path="/scouter-common"/>
13+
<classpathentry combineaccessrules="false" kind="src" path="/scouter-server"/>
1414
<classpathentry kind="output" path="bin"/>
1515
</classpath>

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
* **_ext\_plugin\_elapsed\_time_threshold_** : 응답시간의 임계치 (ms) - 기본 값은 0으로, 0일때 응답시간의 임계치 초과 여부를 확인하지 않는다.
2929
* **_ext\_plugin\_gc\_time_threshold_** : GC Time의 임계치 (ms) - 기본 값은 0으로, 0일때 GC Time의 임계치 초과 여부를 확인하지 않는다.
3030
* **_ext\_plugin\_thread\_count_threshold_** : Thread Count의 임계치 - 기본 값은 0으로, 0일때 Thread Count의 임계치 초과 여부를 확인하지 않는다.
31-
32-
31+
* **_ext\_plugin\_ignore\_name_patterns_** : Alert 메시지 발송에서 제외할 NAME 패턴 목록 (',' 구분자 사용, * (wildcard) 사용 가능)
32+
* **_ext\_plugin\_ignore\_title_patterns_** : Alert 메시지 발송에서 제외할 TITLE 패턴 목록 (',' 구분자 사용, * (wildcard) 사용 가능)
33+
* **_ext\_plugin\_ignore\_continuous_dup_alert_** : 연속된 동일 Alert을 1시간 동안 제외 - 기본 값은 false
3334

3435
* Example
3536
```
@@ -49,6 +50,10 @@ ext_plugin_email_cc_address=ccreceiver@yopmail.com
4950
ext_plugin_elapsed_time_threshold=5000
5051
ext_plugin_gc_time_threshold=5000
5152
ext_plugin_thread_count_threshold=300
53+
54+
ext_plugin_ignore_name_patterns=myTomcat1
55+
ext_plugin_ignore_title_patterns=Elapsed,CONNECTION,activat*
56+
ext_plugin_ignore_continuous_dup_alert=true
5257
```
5358

5459
### Dependencies

src/scouter/plugin/server/alert/email/EmailPlugin.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class EmailPlugin {
6161

6262
private static AtomicInteger ai = new AtomicInteger(0);
6363
private static List<Integer> javaeeObjHashList = new ArrayList<Integer>();
64+
private static AlertPack lastPack;
65+
private static long lastSentTimestamp;
6466

6567
public EmailPlugin() {
6668
if (ai.incrementAndGet() == 1) {
@@ -155,6 +157,41 @@ public void run() {
155157
title = "An object has been inactivated.";
156158
msg = pack.message.substring(0, pack.message.indexOf("OBJECT") - 1);
157159
}
160+
161+
try {
162+
String ignoreNamePattern = conf.getValue("ext_plugin_ignore_name_patterns");
163+
String ignoreTitlePattern = conf.getValue("ext_plugin_ignore_title_patterns");
164+
165+
if (ignoreNamePattern != null && !"".equals(ignoreNamePattern)) {
166+
for (String pattern : ignoreNamePattern.split(",")) {
167+
if (name.matches(".*[" + pattern.replaceAll("-", "\\\\-") + "].*")) {
168+
return;
169+
}
170+
}
171+
}
172+
173+
if (ignoreTitlePattern != null && !"".equals(ignoreTitlePattern)) {
174+
for (String pattern : ignoreTitlePattern.split(",")) {
175+
if (title.matches(".*[" + pattern.replaceAll("-", "\\\\-") + "].*")) {
176+
return;
177+
}
178+
}
179+
}
180+
181+
if (conf.getBoolean("ext_plugin_ignore_continuous_dup_alert", false) && lastPack != null) {
182+
long diff = System.currentTimeMillis() - lastSentTimestamp;
183+
if (lastPack.objHash == pack.objHash
184+
&& lastPack.title.equals(pack.title)
185+
&& diff < DateUtil.MILLIS_PER_HOUR) {
186+
return;
187+
}
188+
}
189+
190+
lastPack = pack;
191+
} catch (Exception e) {
192+
// ignore
193+
println("[Error] : " + e.getMessage());
194+
}
158195

159196
// Make email message
160197
String message = "[TYPE] : " + pack.objType.toUpperCase() + "\n" +
@@ -186,7 +223,8 @@ public void run() {
186223

187224
// Send the email
188225
email.send();
189-
226+
227+
lastSentTimestamp = System.currentTimeMillis();
190228
println("Email sent to [" + to + "] successfully.");
191229
} catch (Exception e) {
192230
println("[Error] : " + e.getMessage());

0 commit comments

Comments
 (0)