test
This commit is contained in:
parent
e0f2de0565
commit
e206016ad8
4
pom.xml
4
pom.xml
|
@ -11,10 +11,8 @@
|
|||
</parent>
|
||||
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>crawler.sql</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>crawler_sql</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>com.loafle.overflow.crawler.sql</name>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||
|
|
|
@ -15,55 +15,25 @@ public class SQLCrawler extends Crawler {
|
|||
|
||||
public SQLCrawler() {}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object getInternal(Map<String, Object> config) {
|
||||
TargetInfo info = getTargetInfo(config.get("id").toString());
|
||||
return getMetrics(info);
|
||||
public Object getInternal(Map<String, Object> config) {
|
||||
return getMetrics(config);
|
||||
}
|
||||
|
||||
private TargetInfo getTargetInfo(String id) {
|
||||
TargetInfo info = new TargetInfo();
|
||||
|
||||
// //MySQL
|
||||
// info.setUrl("jdbc:mysql://192.168.1.215:3306"); // ?useSSL=true&verifyServerCertificate=false
|
||||
// info.setId("root");
|
||||
// info.setPw("qwe123");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("show session status");
|
||||
// //MSSQL
|
||||
info.setUrl("jdbc:sqlserver://192.168.1.103:1433;integratedSecurity=SSPI;encrypt=false;trustServerCertificate=true");
|
||||
info.setId("sa");
|
||||
info.setPw("qwer5795");
|
||||
info.setSSL(true);
|
||||
info.setQuery("select * from master.dbo.sysprocesses");
|
||||
// //PGSQL
|
||||
// info.setUrl("jdbc:postgresql://192.168.1.107:5432/postgres");
|
||||
// info.setId("postgres");
|
||||
// info.setPw("!@#$qwer1234");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("select * from pg_stat_activity");
|
||||
// //Oracle
|
||||
// info.setUrl("jdbc:oracle:thin:@192.168.1.30:1521/oracle.loafle.com");
|
||||
// info.setId("sys as sysdba");
|
||||
// info.setPw("qwer5795QWER");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("select * from v$sysstat");
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
private List<Map<String, String>> getMetrics(TargetInfo info) {
|
||||
private List<Map<String, String>> getMetrics(Map<String, Object> config) {
|
||||
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
|
||||
conn = DriverManager.getConnection(info.getUrl(),info.getId(), info.getPw());
|
||||
conn = DriverManager.getConnection(
|
||||
(String)config.get("url"),
|
||||
(String)config.get("user"),
|
||||
(String)config.get("pw"));
|
||||
stmt = conn.createStatement();
|
||||
|
||||
rs = stmt.executeQuery(info.getQuery());
|
||||
rs = stmt.executeQuery((String)config.get("query"));
|
||||
|
||||
ResultSetMetaData md = rs.getMetaData();
|
||||
int cnt = md.getColumnCount();
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
package com.loafle.overflow.crawler.sql;
|
||||
|
||||
/**
|
||||
* Created by insanity on 17. 4. 11.
|
||||
*/
|
||||
public class TargetInfo {
|
||||
|
||||
private String url;
|
||||
private String id;
|
||||
private String pw;
|
||||
private Boolean isSSL;
|
||||
private String query;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPw() {
|
||||
return pw;
|
||||
}
|
||||
|
||||
public void setPw(String pw) {
|
||||
this.pw = pw;
|
||||
}
|
||||
|
||||
public Boolean getSSL() {
|
||||
return isSSL;
|
||||
}
|
||||
|
||||
public void setSSL(Boolean SSL) {
|
||||
isSSL = SSL;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
}
|
|
@ -1,17 +1,51 @@
|
|||
|
||||
package com.loafle.overflow;
|
||||
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.crawler.sql.SQLCrawler;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AppTest {
|
||||
// //MySQL
|
||||
// info.setUrl("jdbc:mysql://192.168.1.215:3306"); // ?useSSL=true&verifyServerCertificate=false
|
||||
// info.setId("root");
|
||||
// info.setPw("qwe123");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("show session status");
|
||||
// //MSSQL
|
||||
// info.setUrl("jdbc:sqlserver://192.168.1.103:1433;"); //encrypt=false;trustServerCertificate=true"
|
||||
// info.setId("sa");
|
||||
// info.setPw("qwer5795");
|
||||
// info.setSSL(true);
|
||||
// info.setQuery("select * from master.dbo.sysprocesses");
|
||||
// //PGSQL
|
||||
// info.setUrl("jdbc:postgresql://192.168.1.107:5432/postgres");
|
||||
// info.setId("postgres");
|
||||
// info.setPw("!@#$qwer1234");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("select * from pg_stat_activity");
|
||||
// //Oracle
|
||||
// info.setUrl("jdbc:oracle:thin:@192.168.1.30:1521/oracle.loafle.com");
|
||||
// info.setId("sys as sysdba");
|
||||
// info.setPw("qwer5795QWER");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("select * from v$sysstat");
|
||||
|
||||
@Test
|
||||
public void testSQL() {
|
||||
SQLCrawler sc = new SQLCrawler();
|
||||
List<Map<String,String>> result = (List<Map<String,String>>)sc.get("1111");
|
||||
Map config = new HashMap();
|
||||
config.put("url", "jdbc:mysql://192.168.1.215:3306");
|
||||
config.put("user", "root");
|
||||
config.put("pw", "qwe123");
|
||||
config.put("ssl", false);
|
||||
config.put("query", "show session status");
|
||||
|
||||
List<Map<String,String>> result = (List<Map<String,String>>)sc.getInternal(config);
|
||||
|
||||
for(Map<String, String> m : result) {
|
||||
for (Map.Entry<String, String> entry : m.entrySet()) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user