Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pentaLiker
DolphinScheduler
提交
f4ef86c5
DolphinScheduler
项目概览
pentaLiker
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f4ef86c5
编写于
11月 13, 2020
作者:
江
江蓠
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FEATURE#4029] alert spi support script alert
this closes #4029
上级
c61e5368
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
615 addition
and
0 deletion
+615
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml
...eduler-alert-plugin/dolphinscheduler-alert-script/pom.xml
+75
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java
.../apache/dolphinscheduler/plugin/alert/script/OSUtils.java
+25
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java
...he/dolphinscheduler/plugin/alert/script/ProcessUtils.java
+57
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java
...phinscheduler/plugin/alert/script/ScriptAlertChannel.java
+40
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
...eduler/plugin/alert/script/ScriptAlertChannelFactory.java
+69
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java
...lphinscheduler/plugin/alert/script/ScriptAlertPlugin.java
+35
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java
...nscheduler/plugin/alert/script/ScriptParamsConstants.java
+36
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
...he/dolphinscheduler/plugin/alert/script/ScriptSender.java
+75
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java
...ache/dolphinscheduler/plugin/alert/script/ScriptType.java
+63
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java
...e/dolphinscheduler/plugin/alert/script/StreamGobbler.java
+62
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java
...er/plugin/alert/script/ScriptAlertChannelFactoryTest.java
+49
-0
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh
...inscheduler-alert-script/src/test/script/shell/example.sh
+28
-0
dolphinscheduler-alert-plugin/pom.xml
dolphinscheduler-alert-plugin/pom.xml
+1
-0
未找到文件。
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/pom.xml
0 → 100644
浏览文件 @
f4ef86c5
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
dolphinscheduler-alert-plugin
</artifactId>
<groupId>
org.apache.dolphinscheduler
</groupId>
<version>
1.3.2-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.apache.dolphinscheduler
</groupId>
<artifactId>
dolphinscheduler-alert-script
</artifactId>
<dependencies>
<dependency>
<groupId>
org.apache.dolphinscheduler
</groupId>
<artifactId>
dolphinscheduler-spi
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-annotations
</artifactId>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
<type>
jar
</type>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/OSUtils.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
public
class
OSUtils
{
public
static
Boolean
isWindows
()
{
return
System
.
getProperty
(
"os.name"
).
startsWith
(
"Windows"
);
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
/**
* ProcessUtils
*/
public
class
ProcessUtils
{
public
static
Integer
executeScript
(
String
...
cmd
)
{
int
exitCode
=
-
1
;
ProcessBuilder
processBuilder
=
new
ProcessBuilder
(
cmd
);
try
{
Process
process
=
processBuilder
.
start
();
InputStream
in
=
process
.
getErrorStream
();
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
in
));
StringBuilder
result
=
new
StringBuilder
();
StreamGobbler
inputStreamGobbler
=
new
StreamGobbler
(
process
.
getInputStream
());
StreamGobbler
errorStreamGobbler
=
new
StreamGobbler
(
process
.
getErrorStream
());
inputStreamGobbler
.
start
();
errorStreamGobbler
.
start
();
return
process
.
waitFor
();
}
catch
(
IOException
|
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
exitCode
;
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannel.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannel
;
import
org.apache.dolphinscheduler.spi.alert.AlertData
;
import
org.apache.dolphinscheduler.spi.alert.AlertInfo
;
import
org.apache.dolphinscheduler.spi.alert.AlertResult
;
import
org.apache.dolphinscheduler.spi.params.PluginParamsTransfer
;
import
java.util.Map
;
/**
* ScriptAlertChannel
*/
public
class
ScriptAlertChannel
implements
AlertChannel
{
@Override
public
AlertResult
process
(
AlertInfo
alertinfo
)
{
AlertData
alertData
=
alertinfo
.
getAlertData
();
String
alertParams
=
alertinfo
.
getAlertParams
();
Map
<
String
,
String
>
paramsMap
=
PluginParamsTransfer
.
getPluginParamsMap
(
alertParams
);
return
new
ScriptSender
(
paramsMap
).
sendScriptAlert
(
alertData
.
getTitle
());
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannel
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannelFactory
;
import
org.apache.dolphinscheduler.spi.params.InputParam
;
import
org.apache.dolphinscheduler.spi.params.RadioParam
;
import
org.apache.dolphinscheduler.spi.params.base.ParamsOptions
;
import
org.apache.dolphinscheduler.spi.params.base.PluginParams
;
import
org.apache.dolphinscheduler.spi.params.base.Validate
;
/**
* ScriptAlertChannelFactory
*/
public
class
ScriptAlertChannelFactory
implements
AlertChannelFactory
{
@Override
public
String
getName
()
{
return
"script alert"
;
}
@Override
public
List
<
PluginParams
>
getParams
()
{
InputParam
scriptUserParam
=
InputParam
.
newBuilder
(
ScriptParamsConstants
.
NAME_SCRIPT_USER_PARAMS
,
ScriptParamsConstants
.
SCRIPT_USER_PARAMS
)
.
addValidate
(
Validate
.
newBuilder
()
.
setRequired
(
false
)
.
build
())
.
build
();
// need check file type and file exist
InputParam
scriptPathParam
=
InputParam
.
newBuilder
(
ScriptParamsConstants
.
NAME_SCRIPT_PATH
,
ScriptParamsConstants
.
SCRIPT_PATH
)
.
addValidate
(
Validate
.
newBuilder
()
.
setRequired
(
true
)
.
build
())
.
build
();
RadioParam
scriptTypeParams
=
RadioParam
.
newBuilder
(
ScriptParamsConstants
.
NAME_SCRIPT_TYPE
,
ScriptParamsConstants
.
SCRIPT_TYPE
)
.
addParamsOptions
(
new
ParamsOptions
(
ScriptType
.
SHELL
.
getDescp
(),
ScriptType
.
SHELL
.
getDescp
(),
false
))
.
setValue
(
ScriptType
.
SHELL
.
getDescp
())
.
addValidate
(
Validate
.
newBuilder
().
setRequired
(
true
).
build
())
.
build
();
return
Arrays
.
asList
(
scriptUserParam
,
scriptPathParam
,
scriptTypeParams
);
}
@Override
public
AlertChannel
create
()
{
return
new
ScriptAlertChannel
();
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertPlugin.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
org.apache.dolphinscheduler.spi.DolphinSchedulerPlugin
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannelFactory
;
import
com.google.common.collect.ImmutableList
;
/**
* ScriptAlertPlugin
*/
public
class
ScriptAlertPlugin
implements
DolphinSchedulerPlugin
{
@Override
public
Iterable
<
AlertChannelFactory
>
getAlertChannelFactorys
()
{
return
ImmutableList
.
of
(
new
ScriptAlertChannelFactory
());
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
/**
* ScriptParamsConstants
*/
public
class
ScriptParamsConstants
{
static
final
String
SCRIPT_TYPE
=
"script.type"
;
static
final
String
NAME_SCRIPT_TYPE
=
"scriptType"
;
static
final
String
SCRIPT_PATH
=
"script.path"
;
static
final
String
NAME_SCRIPT_PATH
=
"scriptPath"
;
static
final
String
SCRIPT_USER_PARAMS
=
"script.user.params"
;
static
final
String
NAME_SCRIPT_USER_PARAMS
=
"scriptUserParams"
;
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
org.apache.dolphinscheduler.spi.alert.AlertResult
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* ScriptSender
*/
public
class
ScriptSender
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ScriptSender
.
class
);
private
String
scriptPath
;
private
Integer
scriptType
;
private
String
userParams
;
public
ScriptSender
(
Map
<
String
,
String
>
config
)
{
scriptPath
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_PATH
);
scriptType
=
Integer
.
parseInt
(
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_TYPE
));
userParams
=
config
.
get
(
ScriptParamsConstants
.
NAME_SCRIPT_USER_PARAMS
);
}
public
AlertResult
sendScriptAlert
(
String
msg
)
{
AlertResult
alertResult
=
new
AlertResult
();
if
(
ScriptType
.
of
(
scriptType
).
equals
(
ScriptType
.
SHELL
))
{
executeShellScript
(
msg
);
}
return
alertResult
;
}
private
AlertResult
executeShellScript
(
String
msg
)
{
AlertResult
alertResult
=
new
AlertResult
();
alertResult
.
setStatus
(
"false"
);
if
(
OSUtils
.
isWindows
())
{
alertResult
.
setMessage
(
"shell script not support windows os"
);
return
alertResult
;
}
String
[]
cmd
=
{
"/bin/sh"
,
"-c"
,
scriptPath
+
" "
+
msg
+
" "
+
userParams
};
int
exitCode
=
ProcessUtils
.
executeScript
(
cmd
);
if
(
exitCode
==
0
)
{
alertResult
.
setStatus
(
"true"
);
alertResult
.
setMessage
(
"send script alert msg success"
);
return
alertResult
;
}
alertResult
.
setMessage
(
"send script alert msg error,exitCode is "
+
exitCode
);
return
alertResult
;
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptType.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* ScriptType
*/
public
enum
ScriptType
{
SHELL
(
0
,
"SHELL"
),
;
ScriptType
(
int
code
,
String
descp
)
{
this
.
code
=
code
;
this
.
descp
=
descp
;
}
private
final
int
code
;
private
final
String
descp
;
public
int
getCode
()
{
return
code
;
}
public
String
getDescp
()
{
return
descp
;
}
private
static
final
Map
<
Integer
,
ScriptType
>
SCRIPT_TYPE_MAP
=
new
HashMap
<>();
static
{
for
(
ScriptType
scriptType
:
ScriptType
.
values
())
{
SCRIPT_TYPE_MAP
.
put
(
scriptType
.
code
,
scriptType
);
}
}
public
static
ScriptType
of
(
Integer
code
)
{
if
(
SCRIPT_TYPE_MAP
.
containsKey
(
code
))
{
return
SCRIPT_TYPE_MAP
.
get
(
code
);
}
throw
new
IllegalArgumentException
(
"invalid code : "
+
code
);
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/StreamGobbler.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* StreamGobbler
*/
public
class
StreamGobbler
extends
Thread
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
StreamGobbler
.
class
);
InputStream
inputStream
;
StreamGobbler
(
InputStream
inputStream
)
{
this
.
inputStream
=
inputStream
;
}
public
void
run
()
{
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
);
BufferedReader
inputBufferReader
=
new
BufferedReader
(
inputStreamReader
);
try
{
String
line
;
StringBuilder
output
=
new
StringBuilder
();
while
((
line
=
inputBufferReader
.
readLine
())
!=
null
)
{
output
.
append
(
line
);
output
.
append
(
System
.
getProperty
(
"line.separator"
));
}
if
(
output
.
length
()
>
0
)
{
logger
.
info
(
output
.
toString
());
}
}
catch
(
IOException
e
)
{
logger
.
error
(
"I/O error occurs %S"
,
e
.
getMessage
());
}
}
}
\ No newline at end of file
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java
0 → 100644
浏览文件 @
f4ef86c5
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.plugin.alert.script
;
import
org.apache.dolphinscheduler.spi.alert.AlertChannel
;
import
org.apache.dolphinscheduler.spi.params.base.PluginParams
;
import
org.apache.dolphinscheduler.spi.utils.JSONUtils
;
import
java.util.List
;
import
org.junit.Assert
;
import
org.junit.Test
;
/**
* ScriptAlertChannelFactoryTest
*/
public
class
ScriptAlertChannelFactoryTest
{
@Test
public
void
testGetParams
()
{
ScriptAlertChannelFactory
scriptAlertChannelFactory
=
new
ScriptAlertChannelFactory
();
List
<
PluginParams
>
params
=
scriptAlertChannelFactory
.
getParams
();
JSONUtils
.
toJsonString
(
params
);
Assert
.
assertEquals
(
3
,
params
.
size
());
}
@Test
public
void
testCreate
()
{
ScriptAlertChannelFactory
scriptAlertChannelFactory
=
new
ScriptAlertChannelFactory
();
AlertChannel
alertChannel
=
scriptAlertChannelFactory
.
create
();
Assert
.
assertNotNull
(
alertChannel
);
}
}
dolphinscheduler-alert-plugin/dolphinscheduler-alert-script/src/test/script/shell/example.sh
0 → 100644
浏览文件 @
f4ef86c5
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
content
=
$1
msg
=
$2
# Write your specific logic here
echo
$content
echo
$msg
# Set the exit code according to your execution result, and alert needs to use it to judge the status of this alarm result
exit
888
dolphinscheduler-alert-plugin/pom.xml
浏览文件 @
f4ef86c5
...
...
@@ -33,6 +33,7 @@
<module>
dolphinscheduler-alert-email
</module>
<module>
dolphinscheduler-alert-wechat
</module>
<module>
dolphinscheduler-alert-dingtalk
</module>
<module>
dolphinscheduler-alert-script
</module>
</modules>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录