Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to ignore given NAME & TITLE & MESSAGE patterns #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
* **_ext\_plugin\_thread\_count\_threshold_** : Thread Count의 임계치 - 기본 값은 0으로, 0일때 Thread Count의 임계치 초과 여부를 확인하지 않는다.
* **_ext\_plugin\_slack\_xlog\_enabled_** : xlog message send (true / false) - default : false
* **_ext_plugin_slack_object_alert_enabled_** : object active/dead alert (true / false) - default : false

* **_ext\_plugin\_ignore\_name_patterns_** : Alert 메시지 발송에서 제외할 NAME 패턴 목록 (',' 구분자 사용, * (wildcard) 사용 가능)
* **_ext\_plugin\_ignore\_title_patterns_** : Alert 메시지 발송에서 제외할 TITLE 패턴 목록 (',' 구분자 사용, * (wildcard) 사용 가능)
* **_ext\_plugin\_ignore\_message_patterns_** : Alert 메시지 발송에서 제외할 MESSAGE 패턴 목록 (',' 구분자 사용, * (wildcard) 사용 가능)

* Example
```
# External Interface (Slack)
Expand All @@ -44,6 +47,10 @@ ext_plugin_slack_object_alert_enabled=true
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_message_patterns=*(/v1/common/user/testuser)*
```

### Dependencies
Expand Down
50 changes: 48 additions & 2 deletions src/main/java/scouter/plugin/server/alert/slack/SlackPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class SlackPlugin {

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

public SlackPlugin() {
groupConf = new MonitoringGroupConfigure(conf);
Expand Down Expand Up @@ -152,7 +154,51 @@ public void run(){
msg = pack.message.substring(0, pack.message.indexOf("OBJECT") - 1);
}

// Make message contents
try {
String ignoreNamePattern = conf.getValue("ext_plugin_ignore_name_patterns");
String ignoreTitlePattern = conf.getValue("ext_plugin_ignore_title_patterns");
String ignoreMessagePattern = conf.getValue("ext_plugin_ignore_message_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 (ignoreMessagePattern != null && !"".equals(ignoreMessagePattern)) {
for (String pattern : ignoreMessagePattern.split(",")) {
if (msg.matches(pattern.replaceAll("\\*", ".*")
.replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)")
.replaceAll("\\[", "\\\\[").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" +
"[LEVEL] : " + AlertLevel.getName(pack.level) + "\n" +
Expand Down Expand Up @@ -191,7 +237,7 @@ public void run(){
e.printStackTrace();
}
}
}
}

}.start();
}
Expand Down