Skip to content

Commit

Permalink
add alert script check (#15752)
Browse files Browse the repository at this point in the history
  • Loading branch information
caishunfeng committed Mar 21, 2024
1 parent 56a834b commit f7358c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 5 additions & 5 deletions docs/docs/en/guide/alert/script.md
Expand Up @@ -7,11 +7,11 @@ The following shows the `Script` configuration example:

## Parameter Configuration

| **Parameter** | **Description** |
|---------------|--------------------------------------------------|
| User Params | User defined parameters will pass to the script. |
| Script Path | The file location path in the server. |
| Type | Support `Shell` script. |
| **Parameter** | **Description** |
|---------------|-------------------------------------------------------------|
| User Params | User defined parameters will pass to the script. |
| Script Path | The file location path in the server, only support .sh file |
| Type | Support `Shell` script. |

### Note

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/zh/guide/alert/script.md
Expand Up @@ -12,7 +12,7 @@
* 脚本路径

> 脚本在服务器上的文件位置
> 脚本在服务器上的文件位置,只支持.sh后缀的文件
* 脚本类型

Expand Down
Expand Up @@ -69,6 +69,11 @@ private AlertResult executeShellScript(String title, String content) {
alertResult.setMessage("shell script not support windows os");
return alertResult;
}
if (!scriptPath.endsWith(".sh")) {
alertResult.setMessage("shell script is invalid, only support .sh file");
return alertResult;
}

// validate script path in case of injections
File shellScriptFile = new File(scriptPath);
// validate existence
Expand Down
Expand Up @@ -79,6 +79,16 @@ public void testPathNPE() {
Assertions.assertEquals("false", alertResult.getStatus());
}

@Test
public void testPathError() {
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_PATH, "/usr/sbin/abc");
ScriptSender scriptSender = new ScriptSender(scriptConfig);
AlertResult alertResult;
alertResult = scriptSender.sendScriptAlert("test path NPE", "test content");
Assertions.assertEquals("false", alertResult.getStatus());
Assertions.assertTrue(alertResult.getMessage().contains("shell script is invalid, only support .sh file"));
}

@Test
public void testTypeIsError() {
scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TYPE, null);
Expand Down

0 comments on commit f7358c3

Please sign in to comment.