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

[doc]update doc for custom plugin #2245

Merged
merged 10 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 9 additions & 5 deletions home/docs/help/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_label: Custom plugin

Currently, `Hertzbeat` relies on the `alert` module to notify the user, and then the user can take actions such as sending requests, executing `sql`, executing `shell` scripts, etc. However, this can only be automated manually or by `webhook` to receive the alert message.
However, at present, it is only possible to automate the process by receiving alert messages manually or through a `webhook`. For this reason, `HertzBeat` has added a new `plugin` module, which has a generic interface `Plugin`, which allows users to implement the `alert` method of this interface and receive the `Alert` class as a parameter to customize the operation.
After adding the customized code, you only need to package the `plugin` module, copy it to the `/ext-lib` folder under the installation directory, restart the `HertzBeat` main program, and then you can execute the customized function after the alert, without having to re-package and deploy the whole program by yourself.
After adding the customized code, you only need to package the `plugin` module, upload the plug-in in `Plugin Manage` to execute custom functions after the alarm.
Currently, `HertzBeat` only set up the trigger `alert` method after alarm, if you need to set up the trigger method at the time of acquisition, startup program, etc., please mention `Task` in `https://github.com/apache/hertzbeat/issues/new/choose`.

### Specific uses
Expand All @@ -18,8 +18,12 @@ Currently, `HertzBeat` only set up the trigger `alert` method after alarm, if yo
![plugin-1.png](/img/docs/help/plugin-1.png)
2. In the `org.apache.hertzbeat.plugin.impl` directory, create a new interface implementation class, such as `org.apache.hertzbeat.plugin.impl.DemoPluginImpl`, and receive the `Alert` class as a parameter, implement the `alert ` method, the logic is customized by the user, here we simply print the object.
![plugin-2.png](/img/docs/help/plugin-2.png)
3. Package the `hertzbeat-plugin` module.
3. Add the fully qualified names of the interface implementation classes to the `META-INF/services/org.apache.hertzbeat.plugin.Plugin` file, with each implementation class name on a separate line.
4. Package the `hertzbeat-plugin` module.
![plugin-3.png](/img/docs/help/plugin-3.png)
4. Copy the packaged `jar` package to the `ext-lib` directory under the installation directory (for `docker` installations, mount the `ext-lib` directory first, then copy it there).
![plugin-4.png](/img/docs/help/plugin-4.png)
5. Then restart `HertzBeat` to enable the customized post-alert handling policy.
5. Upload the jar file with the name ending in `-jar-with-lib.jar` to `HertzBeat` through the `Plugin Manage` - `Upload Plugin` feature, and enable the plugin to implement a custom alarm post-processing strategy.
![plugin-5-en.jpg](/img/docs/help/plugin-5-en.jpg)

### Recommendations
1. Since the `Plugin manage` function can only enable or disable the entire plugin package, it is recommended that a plugin package contains only one class that implements the `org.apache.hertzbeat.plugin.Plugin` interface.
2. If you have been using Hertzbeat's plug-in function on a version without the `Plugin Manage` , when upgrading to a new version, you need to upload all the previously used plug-in packages to `Hertzbeat` through `Plugin Manage`-`Upload Plugin` so that the plug-ins can take effect in the new version.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_label: 自定义插件

当前`Hertzbeat`在使用时,主要依赖`alert`模块对用户进行通知,然后用户采取一些措施如发送请求、执行`sql`、执行`shell`脚本等。
但目前只能通过手动或者`webhook`接收告警信息进行自动化处理。基于此,`HertzBeat`新增了`plugin`模块,该模块有一个通用接口`Plugin`,用户可以自己实现这个接口的`alert`方法,接收`Alert`类作为参数进行自定义操作。
用户添加自定义代码后,只需要对`plugin`模块进行打包,拷贝到安装目录下`/ext-lib`文件夹中,重启`HertzBeat`主程序,即可实现告警后执行自定义功能,无需自己重新打包部署整个程序
用户添加自定义代码后,只需要对`plugin`模块进行打包。在`插件管理`中上传插件,即可实现告警后执行自定义功能。
目前,`HertzBeat`只在告警后设置了触发`alert`方法,如需在采集、启动程序等时机设置触发方法,请在`https://github.com/apache/hertzbeat/issues/new/choose` 提`Task`。

### 具体使用
Expand All @@ -18,8 +18,12 @@ sidebar_label: 自定义插件
![plugin-1.png](/img/docs/help/plugin-1.png)
2. 在`org.apache.hertzbeat.plugin.impl`目录下, 新建一个接口实现类,如`org.apache.hertzbeat.plugin.impl.DemoPluginImpl`,在实现类中接收`Alert`类作为参数,实现`alert`方法,逻辑由用户自定义,这里我们简单打印一下对象。
![plugin-2.png](/img/docs/help/plugin-2.png)
3. 打包`hertzbeat-plugin`模块。
3. 在 `META-INF/services/org.apache.hertzbeat.plugin.Plugin` 文件中增加接口实现类的全限定名,每个实现类全限定名单独成行。
4. 打包`hertzbeat-plugin`模块。
![plugin-3.png](/img/docs/help/plugin-3.png)
4. 将打包后的`jar`包,拷贝到安装目录下的`ext-lib`目录下(若为`docker`安装则先将`ext-lib`目录挂载出来,再拷贝到该目录下)
![plugin-4.png](/img/docs/help/plugin-4.png)
5. 然后重启`HertzBeat`,即可实现自定义告警后处理策略。
5. 将打包后的`jar`包,通过 `插件管理`-`上传插件`功能将名称以 `-jar-with-lib.jar` 结尾的 jar 包上传到`HertzBeat` 中并启用该插件即可实现自定义告警后处理策略。
![plugin-5.jpg](/img/docs/help/plugin-5.jpg)

### 使用建议
1. 由于 `插件管理` 功能仅能对整个插件包启用或禁用,因此建议一个插件包中仅包含一个实现了 `org.apache.hertzbeat.plugin.Plugin` 接口的类。
2. 如果你已经在没有`插件管理`功能的版本上使用 Hertzbeat 的插件功能,当升级到新版本时,你需要通过 `插件管理`-`上传插件` 将之前使用的所有插件包上传到 `Hertzbeat`,以便插件可以在新版本生效。
Binary file modified home/static/img/docs/help/plugin-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added home/static/img/docs/help/plugin-5-en.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added home/static/img/docs/help/plugin-5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.