Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
autodatacheck
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lipengbo
autodatacheck
Commits
19763609
Commit
19763609
authored
6 years ago
by
lipengbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加打电话及发短信告警功能
parent
0108269d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
587 additions
and
33 deletions
+587
-33
uiDesigner.xml
.idea/uiDesigner.xml
+125
-0
etlengine.log
logs/etlengine.log
+3
-0
pom.xml
pom.xml
+1
-28
App.java
src/main/java/com/reyun/check/App.java
+16
-5
Main.java
src/main/java/com/reyun/check/Main.java
+56
-0
HttpClientUtil.java
src/main/java/com/reyun/check/phonemsg/HttpClientUtil.java
+270
-0
PhoneMsgInfo.java
src/main/java/com/reyun/check/phonemsg/PhoneMsgInfo.java
+105
-0
ExecDownloadCheck.java
src/main/java/com/reyun/check/thread/ExecDownloadCheck.java
+11
-0
No files found.
.idea/uiDesigner.xml
0 → 100644
View file @
19763609
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"Palette2"
>
<group
name=
"Swing"
>
<item
class=
"com.intellij.uiDesigner.HSpacer"
tooltip-text=
"Horizontal Spacer"
icon=
"/com/intellij/uiDesigner/icons/hspacer.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"1"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"com.intellij.uiDesigner.VSpacer"
tooltip-text=
"Vertical Spacer"
icon=
"/com/intellij/uiDesigner/icons/vspacer.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"1"
anchor=
"0"
fill=
"2"
/>
</item>
<item
class=
"javax.swing.JPanel"
icon=
"/com/intellij/uiDesigner/icons/panel.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JScrollPane"
icon=
"/com/intellij/uiDesigner/icons/scrollPane.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"7"
hsize-policy=
"7"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JButton"
icon=
"/com/intellij/uiDesigner/icons/button.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"0"
fill=
"1"
/>
<initial-values>
<property
name=
"text"
value=
"Button"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JRadioButton"
icon=
"/com/intellij/uiDesigner/icons/radioButton.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"RadioButton"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JCheckBox"
icon=
"/com/intellij/uiDesigner/icons/checkBox.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"CheckBox"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JLabel"
icon=
"/com/intellij/uiDesigner/icons/label.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"Label"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JTextField"
icon=
"/com/intellij/uiDesigner/icons/textField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JPasswordField"
icon=
"/com/intellij/uiDesigner/icons/passwordField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JFormattedTextField"
icon=
"/com/intellij/uiDesigner/icons/formattedTextField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextArea"
icon=
"/com/intellij/uiDesigner/icons/textArea.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextPane"
icon=
"/com/intellij/uiDesigner/icons/textPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JEditorPane"
icon=
"/com/intellij/uiDesigner/icons/editorPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JComboBox"
icon=
"/com/intellij/uiDesigner/icons/comboBox.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"2"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JTable"
icon=
"/com/intellij/uiDesigner/icons/table.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JList"
icon=
"/com/intellij/uiDesigner/icons/list.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"2"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTree"
icon=
"/com/intellij/uiDesigner/icons/tree.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTabbedPane"
icon=
"/com/intellij/uiDesigner/icons/tabbedPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSplitPane"
icon=
"/com/intellij/uiDesigner/icons/splitPane.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSpinner"
icon=
"/com/intellij/uiDesigner/icons/spinner.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSlider"
icon=
"/com/intellij/uiDesigner/icons/slider.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSeparator"
icon=
"/com/intellij/uiDesigner/icons/separator.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JProgressBar"
icon=
"/com/intellij/uiDesigner/icons/progressbar.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JToolBar"
icon=
"/com/intellij/uiDesigner/icons/toolbar.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
>
<preferred-size
width=
"-1"
height=
"20"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JToolBar$Separator"
icon=
"/com/intellij/uiDesigner/icons/toolbarSeparator.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JScrollBar"
icon=
"/com/intellij/uiDesigner/icons/scrollbar.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"0"
anchor=
"0"
fill=
"2"
/>
</item>
</group>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
logs/etlengine.log
View file @
19763609
...
@@ -74100,3 +74100,6 @@ order by t1.task_no,t3.create_time
...
@@ -74100,3 +74100,6 @@ order by t1.task_no,t3.create_time
2018-03-05 11:47:54 ERROR: com.reyun.check.dao.MysqlDAO.insertCheckLog(MysqlDAO.java:268) - [9999-01-01][test]
2018-03-05 11:47:54 ERROR: com.reyun.check.dao.MysqlDAO.insertCheckLog(MysqlDAO.java:268) - [9999-01-01][test]
2018-03-05 11:51:07 ERROR: com.reyun.check.dao.MysqlDAO.insertCheckLog(MysqlDAO.java:268) - [9999-01-01][test]
2018-03-05 11:51:07 ERROR: com.reyun.check.dao.MysqlDAO.insertCheckLog(MysqlDAO.java:268) - [9999-01-01][test]
2018-03-05 11:51:28 ERROR: com.reyun.check.dao.MysqlDAO.insertCheckLog(MysqlDAO.java:268) - [9999-01-01][test]
2018-03-05 11:51:28 ERROR: com.reyun.check.dao.MysqlDAO.insertCheckLog(MysqlDAO.java:268) - [9999-01-01][test]
2018-03-08 14:59:42 INFO : com.reyun.check.phonemsg.PhoneMsgInfo_new.post(PhoneMsgInfo_new.java:78) - {"status":true,"message":"ok","data":[{"receiver":"18500791164"}]}
2018-03-08 14:59:42 INFO : com.reyun.check.phonemsg.PhoneMsgInfo_new.post(PhoneMsgInfo_new.java:82) - 请求服务器成功,做相应处理
This diff is collapsed.
Click to expand it.
pom.xml
View file @
19763609
...
@@ -63,34 +63,7 @@
...
@@ -63,34 +63,7 @@
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
</dependencies>
</dependencies>
<!--
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.reyun.check.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
-->
<build>
<build>
<plugins>
<plugins>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/reyun/check/App.java
View file @
19763609
package
com
.
reyun
.
check
;
package
com
.
reyun
.
check
;
import
com.reyun.check.dao.MysqlDAO
;
import
com.reyun.check.phonemsg.PhoneMsgInfo
;
import
com.reyun.check.dao.WarningDAO
;
import
com.reyun.check.phonemsg.HttpClientUtil
;
import
com.reyun.check.mail.MailUtils
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.PropertyConfigurator
;
import
org.apache.log4j.PropertyConfigurator
;
import
org.json.JSONObject
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.
Map
;
import
java.util.
concurrent.atomic.AtomicInteger
;
/**
/**
* Hello world!
* Hello world!
...
@@ -23,6 +23,18 @@ public class App
...
@@ -23,6 +23,18 @@ public class App
{
{
PropertyConfigurator
.
configure
(
"checkconf/log4j.properties"
);
PropertyConfigurator
.
configure
(
"checkconf/log4j.properties"
);
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
"error"
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
"error"
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
/**
//ds,task_no,exec_sql,exec_state,error_info
//ds,task_no,exec_sql,exec_state,error_info
String[] logarr=new String[5];
String[] logarr=new String[5];
logarr[0]="9999-01-01";
logarr[0]="9999-01-01";
...
@@ -32,7 +44,6 @@ public class App
...
@@ -32,7 +44,6 @@ public class App
logarr[4]="测试中文乱码";
logarr[4]="测试中文乱码";
MysqlDAO dao =new MysqlDAO();
MysqlDAO dao =new MysqlDAO();
dao.insertCheckLog(logarr);
dao.insertCheckLog(logarr);
/**
String ds="2018-03-01";
String ds="2018-03-01";
//发送告警邮件
//发送告警邮件
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/reyun/check/Main.java
View file @
19763609
...
@@ -3,6 +3,8 @@ package com.reyun.check;
...
@@ -3,6 +3,8 @@ package com.reyun.check;
import
com.reyun.check.dao.MysqlDAO
;
import
com.reyun.check.dao.MysqlDAO
;
import
com.reyun.check.dao.WarningDAO
;
import
com.reyun.check.dao.WarningDAO
;
import
com.reyun.check.mail.MailUtils
;
import
com.reyun.check.mail.MailUtils
;
import
com.reyun.check.phonemsg.HttpClientUtil
;
import
com.reyun.check.phonemsg.PhoneMsgInfo
;
import
com.reyun.check.thread.ExecThread
;
import
com.reyun.check.thread.ExecThread
;
import
org.apache.commons.cli.*
;
import
org.apache.commons.cli.*
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
...
@@ -47,6 +49,15 @@ public class Main {
...
@@ -47,6 +49,15 @@ public class Main {
}
else
{
}
else
{
title
=
sbmapw
.
get
(
"title"
).
toString
();
title
=
sbmapw
.
get
(
"title"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
title
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
title
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
}
logger
.
info
(
title
);
logger
.
info
(
title
);
logger
.
info
(
content
);
logger
.
info
(
content
);
...
@@ -63,6 +74,15 @@ public class Main {
...
@@ -63,6 +74,15 @@ public class Main {
title
=
sbmapw
.
get
(
"title"
).
toString
();
title
=
sbmapw
.
get
(
"title"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
mailUtils
.
sendMailContentEvery
(
title
,
content
);
mailUtils
.
sendMailContentEvery
(
title
,
content
);
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
title
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
title
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
}
//检查按指标统计差执行-是否出错
//检查按指标统计差执行-是否出错
title
=
""
;
title
=
""
;
...
@@ -74,6 +94,15 @@ public class Main {
...
@@ -74,6 +94,15 @@ public class Main {
title
=
sbmapw
.
get
(
"title"
).
toString
();
title
=
sbmapw
.
get
(
"title"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
mailUtils
.
sendMailContentEvery
(
title
,
content
);
mailUtils
.
sendMailContentEvery
(
title
,
content
);
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
title
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
title
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
}
//下载数据处理检查
//下载数据处理检查
...
@@ -109,6 +138,15 @@ public class Main {
...
@@ -109,6 +138,15 @@ public class Main {
}
else
{
}
else
{
title
=
sbmapw
.
get
(
"title"
).
toString
();
title
=
sbmapw
.
get
(
"title"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
title
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
title
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
}
logger
.
info
(
title
);
logger
.
info
(
title
);
logger
.
info
(
content
);
logger
.
info
(
content
);
...
@@ -125,6 +163,15 @@ public class Main {
...
@@ -125,6 +163,15 @@ public class Main {
title
=
sbmapw
.
get
(
"title"
).
toString
();
title
=
sbmapw
.
get
(
"title"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
mailUtils
.
sendMailContentEvery
(
title
,
content
);
mailUtils
.
sendMailContentEvery
(
title
,
content
);
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
title
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
title
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
}
//检查按指标统计差执行-是否出错
//检查按指标统计差执行-是否出错
title
=
""
;
title
=
""
;
...
@@ -136,6 +183,15 @@ public class Main {
...
@@ -136,6 +183,15 @@ public class Main {
title
=
sbmapw
.
get
(
"title"
).
toString
();
title
=
sbmapw
.
get
(
"title"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
content
=
sbmapw
.
get
(
"content"
).
toString
();
mailUtils
.
sendMailContentEvery
(
title
,
content
);
mailUtils
.
sendMailContentEvery
(
title
,
content
);
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
title
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
title
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
}
//执行结束后删除10天以前的检查结果数据
//执行结束后删除10天以前的检查结果数据
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/reyun/check/phonemsg/HttpClientUtil.java
0 → 100644
View file @
19763609
package
com
.
reyun
.
check
.
phonemsg
;
/***
* 发短信接口
*/
import
org.apache.commons.httpclient.*
;
import
org.apache.commons.httpclient.methods.GetMethod
;
import
org.apache.commons.httpclient.params.HttpConnectionManagerParams
;
import
org.apache.commons.httpclient.params.HttpMethodParams
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
HttpClientUtil
{
public
final
static
String
REQUEST_HEADER
=
"x-forwarded-for"
;
String
servicetoken
;
String
receiver
;
String
type
;
static
String
phone_url
;
static
String
title
;
public
HttpClientUtil
()
{
this
.
receiver
=
"q20180308144739930"
;
this
.
servicetoken
=
"e15057cc527dd4bdc054dce19a1316e9"
;
this
.
type
=
"sms"
;
this
.
phone_url
=
"http://www.linkedsee.com/alarm/cloudchannel"
;
this
.
title
=
"notice_sms"
;
}
public
void
sendMsg
(
String
description
)
throws
JSONException
{
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"receiver"
,
this
.
receiver
);
json
.
put
(
"type"
,
this
.
type
);
json
.
put
(
"title"
,
this
.
title
);
json
.
put
(
"content"
,
description
);
HttpClientUtil
.
httpPostWithJson
(
json
,
this
.
phone_url
,
this
.
servicetoken
);
}
/**
* 日志处理类
*/
// 读取超时
private
final
static
int
SOCKET_TIMEOUT
=
60000
;
// 连接超时
private
final
static
int
CONNECTION_TIMEOUT
=
60000
;
// 每个HOST的最大连接数量
private
final
static
int
MAX_CONN_PRE_HOST
=
20
;
// 连接池的最大连接数
private
final
static
int
MAX_CONN
=
100
;
// 连接池
private
final
static
HttpConnectionManager
httpConnectionManager
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpClientUtil
.
class
);
/**
* Http get请求,获取结果.
*
* @param url
* @param ip
* @return
*/
public
static
String
doHttpGetRequest
(
String
url
,
String
ip
)
{
HttpClient
httpClient
=
new
HttpClient
(
httpConnectionManager
);
resetRequestHeader
(
httpClient
,
ip
);
HttpMethod
method
=
new
GetMethod
(
url
);
return
executeMethod
(
httpClient
,
method
);
}
public
static
String
doHttpGetRequest4Mobile
(
String
url
,
String
ip
)
{
HttpClient
httpClient
=
new
HttpClient
(
httpConnectionManager
);
resetRequestHeader4Mobile
(
httpClient
,
ip
);
HttpMethod
method
=
new
GetMethod
(
url
);
return
executeMethod
(
httpClient
,
method
);
}
private
static
String
executeMethod
(
HttpClient
httpClient
,
HttpMethod
method
){
return
executeMethod
(
httpClient
,
method
,
"ISO-8859-1"
,
"GB2312"
);
}
private
static
String
executeMethod
(
HttpClient
httpClient
,
HttpMethod
method
,
String
readCharsetName
,
String
writeCharsetName
)
{
String
response
=
null
;
try
{
httpClient
.
executeMethod
(
method
);
}
catch
(
IOException
e
)
{
try
{
logger
.
error
(
"执行HTTP请求"
+
method
.
getURI
().
toString
()
+
"时,发生异常!"
,
e
);
}
catch
(
URIException
e1
)
{
logger
.
error
(
"URIException"
,
e1
);
}
}
finally
{
if
(
method
.
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
StringBuffer
stringBuffer
=
new
StringBuffer
();
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
method
.
getResponseBodyAsStream
(),
readCharsetName
));
String
str
=
""
;
while
((
str
=
reader
.
readLine
())
!=
null
)
{
stringBuffer
.
append
(
new
String
(
str
.
getBytes
(
readCharsetName
),
writeCharsetName
));
}
}
catch
(
IOException
e
)
{
try
{
logger
.
error
(
"执行HTTP响应结果"
+
method
.
getURI
().
toString
()
+
"时,发生异常!"
,
e
);
}
catch
(
URIException
e1
)
{
logger
.
error
(
"URIException"
,
e1
);
}
}
response
=
stringBuffer
.
toString
();
}
method
.
releaseConnection
();
}
return
response
;
}
/**
* 设置一下返回错误的通用提示,可以自定义格式.
*
* @param reason
* @return
*/
public
static
String
returnError
(
String
reason
)
{
StringBuffer
buffer
=
new
StringBuffer
();
buffer
.
append
(
"<?xml version=\"1.0\" encoding=\"GBK\"?>"
);
buffer
.
append
(
"<Response>"
);
buffer
.
append
(
"<Success>false</Success>"
);
buffer
.
append
(
"<reason>"
);
buffer
.
append
(
reason
);
buffer
.
append
(
"</reason>"
);
buffer
.
append
(
"</Response>"
);
return
buffer
.
toString
();
}
/**
* 将客户IP写入请求头
* 这个设置可以伪装IP请求,注意使用
*
* @param client
* @param ip
* @return
*/
public
static
void
resetRequestHeader
(
HttpClient
client
,
String
ip
)
{
List
<
Header
>
headers
=
new
ArrayList
<
Header
>();
headers
.
add
(
new
Header
(
REQUEST_HEADER
,
ip
));
headers
.
add
(
new
Header
(
"Servicetoken"
,
"69fc19debf4c8cf50d6778de556186d5"
));
client
.
getHostConfiguration
().
getParams
().
setParameter
(
"http.default-headers"
,
headers
);
client
.
getHostConfiguration
().
getParams
().
setParameter
(
HttpMethodParams
.
HTTP_CONTENT_CHARSET
,
"utf-8"
);
}
public
static
void
resetRequestHeader4Mobile
(
HttpClient
client
,
String
ip
)
{
List
<
Header
>
headers
=
new
ArrayList
<
Header
>();
headers
.
add
(
new
Header
(
REQUEST_HEADER
,
ip
));
client
.
getHostConfiguration
().
getParams
().
setParameter
(
"http.default-headers"
,
headers
);
client
.
getHostConfiguration
().
getParams
().
setParameter
(
HttpMethodParams
.
HTTP_CONTENT_CHARSET
,
"GBK"
);
}
/**
* Post请求短信通知接口
* @param jsonObj
* @param url
* @return
*/
public
static
boolean
httpPostWithJson
(
JSONObject
jsonObj
,
String
url
,
String
servicetoken
){
boolean
isSuccess
=
false
;
HttpPost
post
=
null
;
try
{
org
.
apache
.
http
.
client
.
HttpClient
httpClient
=
new
DefaultHttpClient
();
post
=
new
HttpPost
(
url
);
// 构造消息头
post
.
setHeader
(
"Content-type"
,
"application/json; charset=utf-8"
);
if
(
StringUtils
.
isNotBlank
(
"Servicetoken"
))
post
.
setHeader
(
"Servicetoken"
,
servicetoken
);
// 构建消息实体
StringEntity
entity
=
new
StringEntity
(
jsonObj
.
toString
(),
Charset
.
forName
(
"UTF-8"
));
entity
.
setContentEncoding
(
"UTF-8"
);
// 发送Json格式的数据请求
entity
.
setContentType
(
"application/json"
);
post
.
setEntity
(
entity
);
HttpResponse
response
=
httpClient
.
execute
(
post
);
// 检验返回码
int
statusCode
=
response
.
getStatusLine
().
getStatusCode
();
if
(
statusCode
==
org
.
apache
.
http
.
HttpStatus
.
SC_OK
){
isSuccess
=
true
;
// 获取响应输入流
String
result
=
""
;
InputStream
inStream
=
response
.
getEntity
().
getContent
();
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inStream
,
"utf-8"
));
StringBuilder
strber
=
new
StringBuilder
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
strber
.
append
(
line
+
"\n"
);
inStream
.
close
();
result
=
strber
.
toString
();
logger
.
info
(
"--------------------------"
+
result
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
isSuccess
=
false
;
}
finally
{
if
(
post
!=
null
){
try
{
post
.
releaseConnection
();
Thread
.
sleep
(
500
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
return
isSuccess
;
}
public
static
void
main
(
String
[]
args
)
{
try
{
String
url
=
"http://www.linkedsee.com/alarm/cloudchannel"
;
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"receiver"
,
"18610646715"
);
json
.
put
(
"type"
,
"sms"
);
json
.
put
(
"title"
,
"notice_sms"
);
json
.
put
(
"content"
,
"短信测试!!!!"
);
}
catch
(
Exception
ex
){
ex
.
printStackTrace
();
}
}
static
{
httpConnectionManager
=
new
MultiThreadedHttpConnectionManager
();
HttpConnectionManagerParams
params
=
httpConnectionManager
.
getParams
();
params
.
setConnectionTimeout
(
CONNECTION_TIMEOUT
);
params
.
setSoTimeout
(
SOCKET_TIMEOUT
);
params
.
setDefaultMaxConnectionsPerHost
(
MAX_CONN_PRE_HOST
);
params
.
setMaxTotalConnections
(
MAX_CONN
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/reyun/check/phonemsg/PhoneMsgInfo.java
0 → 100644
View file @
19763609
package
com
.
reyun
.
check
.
phonemsg
;
/**
* 打电话接口
*/
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.apache.http.message.BasicHeader
;
import
org.apache.http.protocol.HTTP
;
import
org.apache.log4j.Logger
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.io.BufferedReader
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.concurrent.atomic.AtomicInteger
;
public
class
PhoneMsgInfo
{
private
static
final
Logger
logger
=
Logger
.
getLogger
(
PhoneMsgInfo
.
class
);
String
Servicetoken
;
String
receiver
;
String
type
;
static
String
phone_url
;
public
PhoneMsgInfo
()
{
this
.
receiver
=
"q20180308144739930"
;
this
.
Servicetoken
=
"e15057cc527dd4bdc054dce19a1316e9"
;
this
.
type
=
"phone"
;
this
.
phone_url
=
"http://www.linkedsee.com/alarm/cloudchannel"
;
}
public
void
sendMsg
(
String
description
)
throws
JSONException
{
AtomicInteger
phonetime
=
new
AtomicInteger
(
0
);
if
(
phonetime
.
get
()==
0
)
{
JSONObject
jsobj1
=
new
JSONObject
();
jsobj1
.
put
(
"receiver"
,
this
.
receiver
);
jsobj1
.
put
(
"content"
,
description
);
jsobj1
.
put
(
"type"
,
this
.
type
);
jsobj1
.
put
(
"title"
,
"notice_phone"
);
post
(
jsobj1
);
phonetime
.
getAndIncrement
();
}
}
public
String
post
(
JSONObject
json
)
{
HttpClient
client
=
new
DefaultHttpClient
();
HttpPost
post
=
new
HttpPost
(
this
.
phone_url
);
post
.
setHeader
(
"Servicetoken"
,
this
.
Servicetoken
);
post
.
addHeader
(
"Content-Type"
,
"application/json"
);
String
result
=
""
;
try
{
StringEntity
s
=
new
StringEntity
(
json
.
toString
(),
"utf-8"
);
s
.
setContentEncoding
(
new
BasicHeader
(
HTTP
.
CONTENT_TYPE
,
"application/json"
));
post
.
setEntity
(
s
);
// 发送请求
HttpResponse
httpResponse
=
client
.
execute
(
post
);
// 获取响应输入流
InputStream
inStream
=
httpResponse
.
getEntity
().
getContent
();
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inStream
,
"utf-8"
));
StringBuilder
strber
=
new
StringBuilder
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
strber
.
append
(
line
+
"\n"
);
inStream
.
close
();
result
=
strber
.
toString
();
logger
.
info
(
result
);
if
(
httpResponse
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
logger
.
info
(
"请求服务器成功,做相应处理"
);
}
else
{
logger
.
info
(
"请求服务端失败"
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"请求异常"
);
throw
new
RuntimeException
(
e
);
}
return
result
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/reyun/check/thread/ExecDownloadCheck.java
View file @
19763609
...
@@ -4,6 +4,8 @@ import com.reyun.check.dao.HiveDAO;
...
@@ -4,6 +4,8 @@ import com.reyun.check.dao.HiveDAO;
import
com.reyun.check.dao.WarningDAO
;
import
com.reyun.check.dao.WarningDAO
;
import
com.reyun.check.hdfs.HdfsPathSize
;
import
com.reyun.check.hdfs.HdfsPathSize
;
import
com.reyun.check.mail.MailUtils
;
import
com.reyun.check.mail.MailUtils
;
import
com.reyun.check.phonemsg.HttpClientUtil
;
import
com.reyun.check.phonemsg.PhoneMsgInfo
;
import
com.reyun.check.util.ConfigLoader
;
import
com.reyun.check.util.ConfigLoader
;
import
com.reyun.check.util.DefaultConfigLoader
;
import
com.reyun.check.util.DefaultConfigLoader
;
import
org.apache.log4j.Logger
;
import
org.apache.log4j.Logger
;
...
@@ -43,6 +45,15 @@ public class ExecDownloadCheck implements Callable {
...
@@ -43,6 +45,15 @@ public class ExecDownloadCheck implements Callable {
if
(
title
.
length
()>
0
){
//异常才发邮件
if
(
title
.
length
()>
0
){
//异常才发邮件
MailUtils
mailUtils
=
new
MailUtils
(
new
WarningDAO
().
cfg
.
properties
);
MailUtils
mailUtils
=
new
MailUtils
(
new
WarningDAO
().
cfg
.
properties
);
mailUtils
.
sendMailContentEvery
(
title
,
content
);
mailUtils
.
sendMailContentEvery
(
title
,
content
);
try
{
//短信通知
new
HttpClientUtil
().
sendMsg
(
title
);
//打电话报警
new
PhoneMsgInfo
().
sendMsg
(
title
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
}
}
return
true
;
return
true
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment