当前位置:网站首页>Custom nail robot alarm
Custom nail robot alarm
2022-04-23 12:57:00 【Look at the data at the top of the mountain】
The whole code logic

Source code
assembly.xml
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>${project.version}</id>
<formats>
<format>tar.gz</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<files>
<file>
<source>src/main/resources/plugin.properties</source>
<destName>conf/plugin.properties</destName>
</file>
<file>
<source>${project.build.directory}/${project.artifactId}-${project.version}.jar</source>
<destName>lib/${project.artifactId}-${project.version}.jar</destName>
</file>
</files>
</assembly>
DingAlerter
package com.qf.bigdata.azkaban.alert;
import azkaban.alert.Alerter;
import azkaban.executor.ExecutableFlow;
import azkaban.sla.SlaOption;
import azkaban.utils.Props;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.taobao.api.ApiException;
import org.apache.log4j.Logger;
import java.text.SimpleDateFormat;
import java.util.Map;
/**
* Send a message to nail
*/
public class DingAlerter implements Alerter {
private final static Logger LOGGER = Logger.getLogger(DingAlerter.class);
private String dingServerUrl;
private Props props;
public DingAlerter(Props props) {
this.props = props;
dingServerUrl = "https://oapi.dingtalk.com/robot/send?access_token=";
}
/**
* Determine whether the flow is activated
*/
public boolean isActived(ExecutableFlow flow, String type) {
// Get all the parameters in the workflow
Map<String, String> parameters = flow.getExecutionOptions().getFlowParameters();
// Put together a azkaban Events
String property = "ding.alert.on." + type;
// Set the default value , If according to ding.alert.on.success You can get the value , Take this value as the criterion , otherwise false
String defaultActive = props.getString(property, "false");
// Get the default value
String actived = parameters.getOrDefault(property, defaultActive);
return Boolean.parseBoolean(actived);
}
/**
* take long Of ts transformation string Time for
*/
private String formatTime(long time) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.format(time);
}
/**
* Convert the interval to a string representation
*/
private String formatDuration(long startTime, long endTime) {
if (startTime == -1) {
return "-";
}
long durationMs;
if (endTime == -1) {
durationMs = System.currentTimeMillis() - startTime;
} else {
durationMs = endTime - startTime;
}
long seconds = durationMs / 1000;
if (seconds < 60) {
return seconds + " sec";
}
long minute = seconds / 60;
seconds %= 60;
if (minute < 60) {
return minute + " min " + seconds + " sec";
}
long hour = minute / 60;
minute %= 60;
if (hour < 24) {
return hour + "h " + minute +" min ";
}
long day = hour / 24;
hour %= 24;
return day + " days " + hour + " h";
}
/**
* from azkaban Get the token to send the nail message in the process of (token)
*/
private String getPropertiesByFlowParameter(ExecutableFlow flow, String propKey) {
// Get the parameters of the whole process
Map<String, String> parameters = flow.getExecutionOptions().getFlowParameters();
String value = props.getString(propKey);
return parameters.getOrDefault(propKey, value);
}
/**
* Nail message
*/
private void send(ExecutableFlow flow, String title, int execId, String msg) throws Exception {
// Get token string
String dingdingToken = getPropertiesByFlowParameter(flow, "ding.token");
// Get the client sending the message
DefaultDingTalkClient client = new DefaultDingTalkClient(dingServerUrl + dingdingToken);
// Read azkaban Of host
String linkHost = getPropertiesByFlowParameter(flow, "ding.link.azkaban.host");
// Read keywords
String dingAuthWord = getPropertiesByFlowParameter(flow, "ding.auth.word");
// Splice an address
String linkAddress = linkHost + "/executor?execid=" + execId + "#joblist";
// Create request
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("link");
OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();
link.setTitle(dingAuthWord + title);
link.setPicUrl("");
link.setMessageUrl("http://www.1000phone.com/");
link.setText(msg);
request.setLink(link);
try {
client.execute(request);
}catch (ApiException e) {
String errorMsg = "send dingding message fail " + e.getMessage();
LOGGER.error(errorMsg);
throw new ApiException(errorMsg, e);
}
}
/**
* Nail message
*/
private void sendSla(String title,String msg) throws Exception {
// Get token string
//String dingdingToken = props.getString("ding.token");
String dingdingToken="660de36fffae0f1e34bcd47926a70a44afeed1a8e5a15ed057ca7f02c220276a";
// Get the client sending the message
DefaultDingTalkClient client = new DefaultDingTalkClient(dingServerUrl + dingdingToken);
// Read azkaban Of host
//String linkHost = props.getString("ding.link.azkaban.host");
String linkHost="http://172.16.53.11:8081";
// Read keywords
//String dingAuthWord = props.getString("ding.auth.word");
String dingAuthWord="1000phone";
// Create request
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("link");
OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();
link.setTitle(dingAuthWord + title);
link.setPicUrl("");
link.setMessageUrl("http://www.1000phone.com/");
link.setText(msg);
request.setLink(link);
try {
client.execute(request);
}catch (ApiException e) {
String errorMsg = "send sla dingding message fail " + e.getMessage();
LOGGER.error(errorMsg);
throw new ApiException(errorMsg, e);
}
}
@Override
public void alertOnSuccess(ExecutableFlow flow) throws Exception {
if (isActived(flow, "success")) {
int execId = flow.getExecutionId();
StringBuilder sb = new StringBuilder("Flow 1000phone").append(flow.getFlowId()).append("has success:\n");
String title = sb.toString();
sb.append("\t- Start: ").append(formatTime(flow.getStartTime())).append("\n");
sb.append("\t- End: ").append(formatTime(flow.getEndTime())).append("\n");
sb.append("\t- Duration: ").append(formatDuration(flow.getStartTime(), flow.getEndTime()));
send(flow, title, execId, sb.toString());
}
}
@Override
public void alertOnError(ExecutableFlow flow, String... strings) throws Exception {
if (isActived(flow, "error")) {
int execId = flow.getExecutionId();
StringBuilder sb = new StringBuilder("Flow 1000phone").append(flow.getFlowId()).append("has fail:\n");
String title = sb.toString();
sb.append("\t- Start: ").append(formatTime(flow.getStartTime())).append("\n");
sb.append("\t- End: ").append(formatTime(flow.getEndTime())).append("\n");
sb.append("\t- Duration: ").append(formatDuration(flow.getStartTime(), flow.getEndTime()));
send(flow, title, execId, sb.toString());
}
}
@Override
public void alertOnFirstError(ExecutableFlow flow) throws Exception {
if (isActived(flow, "first.error")) {
int execId = flow.getExecutionId();
StringBuilder sb = new StringBuilder("Flow 1000phone").append(flow.getFlowId()).append("has first fail:\n");
String title = sb.toString();
sb.append("\t- Start: ").append(formatTime(flow.getStartTime())).append("\n");
sb.append("\t- End: ").append(formatTime(flow.getEndTime())).append("\n");
sb.append("\t- Duration: ").append(formatDuration(flow.getStartTime(), flow.getEndTime()));
send(flow, title, execId, sb.toString());
}
}
@Override
public void alertOnSla(SlaOption slaOption, String s) throws Exception {
sendSla("sla alerter", "sla xxxx:\n" + s);
}
}
plugin.properties
alerter.name = dingding
alerter.class = com.qf.bigdata.azkaban.alert.DingAlerter
ding.token = 660de36fffae0f1e34bcd47926a70a44afeed1a8e5a15ed057ca7f02c220276a
ding.auth.word = 1000phone
ding.link.azkaban.host = http://172.16.53.11:8081
ding.alert.on.success=true
ding.alert.on.first.error=true
ding.alert.on.error=true
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.qf.bigdata</groupId>
<artifactId>azkaban-dingding</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<azkaban.version>2.5.0</azkaban.version>
<junit.version>4.13</junit.version>
<dingtalk-api.version>1.0.0</dingtalk-api.version>
<slf4j.version>1.6.4</slf4j.version>
<log4j.version>1.2.16</log4j.version>
</properties>
<repositories>
<repository>
<id>ali-maven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>ali-maven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.linkedin.azkaban</groupId>
<artifactId>azkaban</artifactId>
<version>${azkaban.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>com.dingtalk</groupId>
<artifactId>dingtalk-api</artifactId>
<version>${dingtalk-api.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>create-distribution</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>I
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<finalName>${project.artifactId}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Dfile.encoding=UTF-8</argLine>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And load your project into azkaban On
And be sure to specify the warning type when executing
namely :alert.type dingding

When the task is wrong or the task is completed, the nailing robot will automatically alarm ( Is to send a message to the group )
If you want to know more , You can go to the beep station to search the video and watch
版权声明
本文为[Look at the data at the top of the mountain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615025249.html
边栏推荐
- Wonderful review | the sixth issue of "source" - open source economy and industrial investment
- Golang implements MD5, sha256 and bcrypt encryption
- bert-base-chinese下载(智取)
- The quill editor image zooms, multiple rich text boxes are used on one page, and the quill editor upload image address is the server address
- CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
- World Book Day: I'd like to recommend these books
- The continuous construction of the Internet industry platform is not only able to collect traffic
- [daily question] chessboard question
- XinChaCha Trust SSL Organization Validated
- Packet capturing and sorting -- TCP protocol [8]
猜你喜欢

Importerror after tensorflow installation: DLL load failed: the specified module cannot be found, and the domestic installation is slow
![[csnote] ER diagram](/img/97/82e8c2183fcafda50950a953ca0955.png)
[csnote] ER diagram

Trier les principales utilisations de l'Agent IP réseau

Customize the shortcut options in El date picker, and dynamically set the disabled date

Software testing weekly (issue 68): the best way to solve difficult problems is to wait and see the changes and push the boat with the current.

How to click an object to play an animation

Remote access to raspberry pie at home (Part 1)

4.DRF 权限&访问频率&过滤&排序

Realize several "Postures" in which a box is horizontally and vertically centered in the parent box

SSL certificate refund instructions
随机推荐
At instruction of nbiot
STM32 control stepper motor (ULN2003 + 28byj)
云原生KubeSphere部署Mysql
Synchronously update the newly added and edited data to the list
Deploying MySQL in cloud native kubesphere
0基础可以考CPDA数据分析师证书吗
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
精度、速度完美平衡,最新图像分割SOTA模型重磅发布!!!
Byte jump 2020 autumn recruitment programming question: quickly find your own ranking according to the job number
梳理网络IP代理的几大用途
Introduction to servlet listener & filter
Summary of JVM knowledge points - continuously updated
网站首页文件被攻击篡改的形式有哪些
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
如何防止网站被黑客入侵篡改
If you were a golang interviewer, what questions would you ask?
Trier les principales utilisations de l'Agent IP réseau
Object. The disorder of key value array after keys
风尚云网学习-input属性总结