From 67144d0f824222692a31af7715738305e683b3c3 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 24 Apr 2018 18:47:31 +0900 Subject: [PATCH] ing --- .gitignore | 73 ++++ .vscode/launch.json | 26 ++ .vscode/settings.json | 3 + pom.xml | 190 +++++++++ .../container/general/GeneralContainer.java | 24 ++ .../container/general/crawler/Crawlers.java | 43 ++ .../impl/database/DatabaseCrawler.java | 126 ++++++ .../impl/database/DatabaseMetaInfo.java | 11 + .../impl/database/mysql/MySQLCrawler.java | 20 + .../impl/database/oracle/OracleCrawler.java | 20 + .../postgresql/PostgreSQLCrawler.java | 20 + .../database/sqlserver/SQLServerCrawler.java | 20 + .../general/crawler/impl/jmx/JMXCrawler.java | 225 ++++++++++ .../crawler/impl/mongodb/MongoDBCrawler.java | 85 ++++ .../crawler/impl/redis/RedisCralwer.java | 126 ++++++ .../crawler/impl/snmp/SNMPCrawler.java | 151 +++++++ .../crawler/impl/snmp/version/SNMP.java | 82 ++++ .../crawler/impl/snmp/version/SNMPv2c.java | 63 +++ .../crawler/impl/snmp/version/SNMPv3.java | 148 +++++++ .../general/crawler/impl/wmi/WMICrawler.java | 33 ++ .../crawler/impl/wmi/WMICrawlerLinux.java | 152 +++++++ .../crawler/impl/wmi/WMICrawlerOS.java | 47 +++ .../crawler/impl/wmi/WMICrawlerWindows.java | 249 +++++++++++ .../server/GeneralContainerServer.java | 12 + .../container/general/util/Primitives.java | 44 ++ src/main/resources/application.properties | 0 .../general/crawler/CrawlerTest.java | 10 + .../impl/database/DatabaseCrawlerTest.java | 60 +++ .../impl/database/mysql/MySQLCrawlerTest.java | 14 + .../database/oracle/OracleCrawlerTest.java | 16 + .../postgresql/PostgreSQLCrawlerTest.java | 16 + .../sqlserver/SQLServerCrawlerTest.java | 25 ++ .../crawler/impl/jmx/JMXCrawlerTest.java | 6 + .../impl/jmx/tomcat/TomcatCrawlerTest.java | 63 +++ .../impl/mongodb/MongoDBCrawlerTest.java | 40 ++ .../crawler/impl/redis/RedisCralwerTest.java | 42 ++ .../crawler/impl/snmp/SNMPCrawlerTest.java | 70 ++++ .../crawler/impl/wmi/WMICrawlerTest.java | 294 +++++++++++++ src/test/resources/_ | 0 .../resources/config/mongodb/example.json | 43 ++ .../resources/config/mysql/mysql-test.json | 395 ++++++++++++++++++ src/test/resources/config/mysql/mysql.json | 44 ++ .../config/postgresql/postgresql.json | 36 ++ src/test/resources/config/redis/example.json | 67 +++ src/test/resources/config/snmp/examplev2.json | 38 ++ src/test/resources/config/snmp/examplev3.json | 42 ++ .../sqlserver/sqlserver_connection_count.json | 38 ++ .../sqlserver_multiple_key_array.json | 50 +++ src/test/resources/config/tomcat/example.json | 46 ++ .../resources/config/tomcat/example1.json | 130 ++++++ .../resources/config/tomcat/example2.json | 47 +++ .../resources/config/tomcat/generate1.json | 106 +++++ src/test/resources/config/wmi/example.json | 63 +++ .../resources/config/wmi/meta/meta_cpu.json | 49 +++ .../config/wmi/meta/meta_filesystem.json | 61 +++ .../config/wmi/meta/meta_memory.json | 53 +++ .../config/wmi/meta/meta_network.json | 53 +++ src/test/resources/config/wmi/test.json | 130 ++++++ 58 files changed, 4140 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 pom.xml create mode 100644 src/main/java/com/loafle/overflow/container/general/GeneralContainer.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/Crawlers.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseMetaInfo.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwer.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMP.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv2c.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv3.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerLinux.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java create mode 100644 src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerWindows.java create mode 100644 src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java create mode 100644 src/main/java/com/loafle/overflow/container/general/util/Primitives.java create mode 100644 src/main/resources/application.properties create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/CrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/tomcat/TomcatCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawlerTest.java create mode 100644 src/test/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerTest.java create mode 100644 src/test/resources/_ create mode 100644 src/test/resources/config/mongodb/example.json create mode 100644 src/test/resources/config/mysql/mysql-test.json create mode 100644 src/test/resources/config/mysql/mysql.json create mode 100644 src/test/resources/config/postgresql/postgresql.json create mode 100644 src/test/resources/config/redis/example.json create mode 100644 src/test/resources/config/snmp/examplev2.json create mode 100644 src/test/resources/config/snmp/examplev3.json create mode 100644 src/test/resources/config/sqlserver/sqlserver_connection_count.json create mode 100644 src/test/resources/config/sqlserver/sqlserver_multiple_key_array.json create mode 100644 src/test/resources/config/tomcat/example.json create mode 100644 src/test/resources/config/tomcat/example1.json create mode 100644 src/test/resources/config/tomcat/example2.json create mode 100644 src/test/resources/config/tomcat/generate1.json create mode 100644 src/test/resources/config/wmi/example.json create mode 100644 src/test/resources/config/wmi/meta/meta_cpu.json create mode 100644 src/test/resources/config/wmi/meta/meta_filesystem.json create mode 100644 src/test/resources/config/wmi/meta/meta_memory.json create mode 100644 src/test/resources/config/wmi/meta/meta_network.json create mode 100644 src/test/resources/config/wmi/test.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eaec1c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,73 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### Go template +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ +.idea/ +*.iml + +vendor/ +glide.lock +.DS_Store +dist/ +debug + +target +.settings +.project +.classpath \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..974a88c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Debug", + "request": "launch", + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "stopOnEntry": false, + "mainClass": "com.loafle.overflow.container.general.GeneralContainer", + "projectName": "container_general", + "args": "${workspaceFolder}/general.pid" + }, + { + "type": "java", + "name": "Debug (Attach)", + "request": "attach", + "hostName": "localhost", + "port": 0 + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1133129 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5832ff0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,190 @@ + + + 4.0.0 + + + com.loafle + maven_parent_jar + 1.0.0-RELEASE + + + com.loafle.overflow + container_general + 1.0.0-SNAPSHOT + jar + + com.loafle.overflow.container_general + container_general project + + + 1.0.0-SNAPSHOT + 1.0.0-SNAPSHOT + + 1.0.0-SNAPSHOT + 1.0.0-SNAPSHOT + 1.0.0-SNAPSHOT + + 4.1.17.Final + 2.8.2 + 5.0.5.RELEASE + + 6.0.6 + 42.1.4 + 6.2.2.jre8 + + 1.18 + + 2.9.0 + + 3.6.0 + + 2.5.8 + + + + + com.loafle.commons + server-java + ${server-java.version} + + + com.loafle.commons + rpc-java + ${rpc-java.version} + + + + com.loafle.overflow + commons-java + ${overflow.commons-java.version} + + + com.loafle.overflow + crawler-java + ${overflow.crawler-java.version} + + + com.loafle.overflow + container-java + ${overflow.container-java.version} + + + + io.netty + netty-all + ${netty.version} + + + com.google.code.gson + gson + ${gson.version} + + + org.springframework + spring-context + ${spring.version} + + + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + + + + org.postgresql + postgresql + ${postgresql.version} + + + + com.microsoft.sqlserver + mssql-jdbc + ${mssql-jdbc.version} + + + + + com.hynnet + jacob + ${jacob.version} + + + + + redis.clients + jedis + ${jedis.version} + + + + + org.mongodb + mongo-java-driver + ${mongo-java-driver.version} + + + + + org.snmp4j + snmp4j + ${snmp4j.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.6 + + + jar-with-dependencies + + + + com.loafle.overflow.container.general.Container + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/container/general/GeneralContainer.java b/src/main/java/com/loafle/overflow/container/general/GeneralContainer.java new file mode 100644 index 0000000..19e05ba --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/GeneralContainer.java @@ -0,0 +1,24 @@ +package com.loafle.overflow.container.general; + +import com.loafle.overflow.container.general.server.GeneralContainerServer; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class GeneralContainer { + + public static void main(String[] args) throws Exception { + if (args.length <= 0) { + System.out.println("first parameter is path of pid file"); + return; + } + String pidFilePath = args[0]; + + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + "com.loafle.overflow")) { + context.registerShutdownHook(); + context.getBeanFactory().registerSingleton("pidFilePath", pidFilePath); + GeneralContainerServer server = context.getBean(GeneralContainerServer.class); + server.start(); + } + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/Crawlers.java b/src/main/java/com/loafle/overflow/container/general/crawler/Crawlers.java new file mode 100644 index 0000000..5a61e43 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/Crawlers.java @@ -0,0 +1,43 @@ +package com.loafle.overflow.container.general.crawler; + +import java.util.HashMap; +import java.util.Map; + +import com.loafle.overflow.container.general.crawler.impl.database.mysql.MySQLCrawler; +import com.loafle.overflow.container.general.crawler.impl.database.oracle.OracleCrawler; +import com.loafle.overflow.container.general.crawler.impl.database.postgresql.PostgreSQLCrawler; +import com.loafle.overflow.container.general.crawler.impl.database.sqlserver.SQLServerCrawler; +import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawler; +import com.loafle.overflow.container.general.crawler.impl.mongodb.MongoDBCrawler; +import com.loafle.overflow.container.general.crawler.impl.redis.RedisCralwer; +import com.loafle.overflow.container.general.crawler.impl.snmp.SNMPCrawler; +import com.loafle.overflow.container.general.crawler.impl.wmi.WMICrawler; +import com.loafle.overflow.crawler.Crawler; + +public abstract class Crawlers { + private static Map crawlers = new HashMap<>(); + + static { + addCrawler(new MySQLCrawler()); + addCrawler(new OracleCrawler()); + addCrawler(new PostgreSQLCrawler()); + addCrawler(new SQLServerCrawler()); + addCrawler(new JMXCrawler()); + addCrawler(new MongoDBCrawler()); + addCrawler(new RedisCralwer()); + addCrawler(new SNMPCrawler()); + addCrawler(new WMICrawler()); + + } + + private static void addCrawler(Crawler crawler) { + String name = crawler.name(); + crawlers.put(name, crawler); + } + + public Map getCrawlers() { + return Crawlers.crawlers; + } + +} + diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawler.java new file mode 100644 index 0000000..ad88435 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawler.java @@ -0,0 +1,126 @@ +package com.loafle.overflow.container.general.crawler.impl.database; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.crawler.Crawler; +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.ResultSetRow; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +public abstract class DatabaseCrawler implements Crawler { + + public DatabaseCrawler() { + } + + @Override + public void auth(Map authInfoMap) throws OverflowException { + Connection conn = null; + + String url = (String) authInfoMap.get("url"); + String id = (String) authInfoMap.get("id"); + String pw = (String) authInfoMap.get("pw"); + + try { + loadDriverClass(); + } catch (ClassNotFoundException e) { + throw new OverflowException("DatabaseCrawler", e); + } + + try { + conn = java.sql.DriverManager.getConnection(url, id, pw); + } catch (Exception e) { + throw new OverflowException("DatabaseCrawler", e); + } finally { + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + @Override + public Map get(SensorConfig sensorConfig) throws OverflowException { + Connection conn = null; + Statement stmt = null; + + java.sql.ResultSet rs = null; + + String url = (String) sensorConfig.getTarget().getAuth().get("url"); + String id = (String) sensorConfig.getTarget().getAuth().get("id"); + String pw = (String) sensorConfig.getTarget().getAuth().get("pw"); + + try { + loadDriverClass(); + } catch (ClassNotFoundException e) { + throw new OverflowException("DatabaseCrawler", e); + } + + Map resultMap = new HashMap<>(); + + try { + conn = java.sql.DriverManager.getConnection(url, id, pw); + stmt = conn.createStatement(); + + for (Item item : sensorConfig.getItems()) { + + ResultSet resultSet = ResultSetRow.newInstance(item); + Map meta = resultSet.getMeta(); + + rs = stmt.executeQuery((String) item.getQueryInfo().getQuery()); + + while (rs.next()) { + List row = new ArrayList<>(Arrays.asList(new String[meta.size()])); + for (Map.Entry info : meta.entrySet()) { + String data = rs.getString(info.getKey()); + data = data.trim(); + row.set(info.getValue().intValue(), data); + } + resultSet.addRow(row); + } + + rs.close(); + resultMap.putAll(resultSet.getData()); + } + return resultMap; + + } catch (Exception e) { + throw new OverflowException("DatabaseCrawler", e); + } finally { + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + protected abstract void loadDriverClass() throws ClassNotFoundException; +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseMetaInfo.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseMetaInfo.java new file mode 100644 index 0000000..52e3a02 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseMetaInfo.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.container.general.crawler.impl.database; + +public class DatabaseMetaInfo { + private String name; + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawler.java new file mode 100644 index 0000000..0774ee4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawler.java @@ -0,0 +1,20 @@ +package com.loafle.overflow.container.general.crawler.impl.database.mysql; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler; + +public class MySQLCrawler extends DatabaseCrawler { + @Override + public String name() { + return "MYSQL"; + } + + @Override + public String toString() { + return "MySQL Crawler"; + } + + @Override + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("com.mysql.cj.jdbc.Driver"); + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawler.java new file mode 100644 index 0000000..8948005 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawler.java @@ -0,0 +1,20 @@ +package com.loafle.overflow.container.general.crawler.impl.database.oracle; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler; + +public class OracleCrawler extends DatabaseCrawler { + @Override + public String name() { + return "ORACLE"; + } + + @Override + public String toString() { + return "Oracle Crawler"; + } + + @Override + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("oracle.jdbc.driver.OracleDriver"); + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawler.java new file mode 100644 index 0000000..2de35b6 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawler.java @@ -0,0 +1,20 @@ +package com.loafle.overflow.container.general.crawler.impl.database.postgresql; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler; + +public class PostgreSQLCrawler extends DatabaseCrawler { + @Override + public String name() { + return "POSTGRESQL"; + } + + @Override + public String toString() { + return "PostgreSQL Crawler"; + } + + @Override + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("org.postgresql.Driver"); + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawler.java new file mode 100644 index 0000000..4a3777b --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawler.java @@ -0,0 +1,20 @@ +package com.loafle.overflow.container.general.crawler.impl.database.sqlserver; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler; + +public class SQLServerCrawler extends DatabaseCrawler { + @Override + public String name() { + return "SQLSERVER"; + } + + @Override + public String toString() { + return "SQL Server Crawler"; + } + + @Override + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawler.java new file mode 100644 index 0000000..4cd7d5d --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawler.java @@ -0,0 +1,225 @@ +package com.loafle.overflow.container.general.crawler.impl.jmx; + +import com.loafle.overflow.crawler.Crawler; +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; +import com.loafle.overflow.core.exception.OverflowException; + +import javax.management.*; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; +import javax.management.remote.rmi.RMIConnectorServer; +import javax.naming.Context; +import javax.rmi.ssl.SslRMIClientSocketFactory; +import java.io.IOException; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class JMXCrawler implements Crawler { + private static final Logger logger = Logger.getLogger(JMXCrawler.class.getName()); + + public JMXCrawler() { + } + + @Override + public String name() { + return "JMX"; + } + + @Override + public String toString() { + return "JMX Crawler"; + } + + @Override + public void auth(Map authInfoMap) throws OverflowException { + String hostIp = (String) authInfoMap.get("ip"); + Integer port = (Integer) authInfoMap.get("port"); + + String jmxUrl = "service:jmx:rmi:///jndi/rmi://" + hostIp + ":" + port + "/jmxrmi"; + String username = (String) authInfoMap.get("id"); + String password = (String) authInfoMap.get("pw"); + Boolean useSSL = (Boolean) authInfoMap.get("ssl"); + + // connection + JMXConnector jmxconn = null; + try { + Map environment = getAuthority(useSSL, username, password); + jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl), environment); + jmxconn.getMBeanServerConnection(); + } catch (Exception e) { + throw new OverflowException("JMXCrawler", e); + } finally { + if (jmxconn != null) { + try { + jmxconn.close(); + } catch (IOException e) { + } + } + } + } + + @Override + public Map get(SensorConfig sensorConfig) throws OverflowException { + String hostIp = sensorConfig.getTarget().getConnection().getIp(); + int port = sensorConfig.getTarget().getConnection().getPort(); + + String jmxUrl = "service:jmx:rmi:///jndi/rmi://" + hostIp + ":" + port + "/jmxrmi"; + String username = (String) sensorConfig.getTarget().getAuth().get("id"); + String password = (String) sensorConfig.getTarget().getAuth().get("pw"); + boolean useSSL = sensorConfig.getTarget().getConnection().isSsl(); + + // connection + MBeanServerConnection beanCon; + JMXConnector jmxconn = null; + try { + Map environment = getAuthority(useSSL, username, password); + jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl), environment); + beanCon = jmxconn.getMBeanServerConnection(); + + Map resultMap = new HashMap<>(); + + List objectNames = new LinkedList(); + objectNames.add(null); + ObjectName on = null; + + for (Item item : sensorConfig.getItems()) { + + ResultSet resultSet = ResultSet.newInstance(item); + + // get object + String query = item.getQueryInfo().getQuery(); + on = new ObjectName(query); + Set names = beanCon.queryMBeans(on, null); + + List> keys = (List>) item.getQueryInfo().getExtend().get("aliases"); + + for (ObjectInstance name : names) { + + Map attrs = parseAttribute(beanCon, name.getObjectName()); + if (keys != null) { + for (Map keyMap : keys) { + String key = (String) keyMap.get("key"); + int index = (int) keyMap.get("index"); + String objectName = parseObjectName(name.toString(), key); + String alias = item.getMappingInfo().getArrayColumns().get(index); + attrs.put(alias, objectName); + } + } + + resultSet.addRow(parse(attrs, resultSet.getMeta())); + } + + resultMap.putAll(resultSet.getData()); + } + + return resultMap; + } catch (Exception e) { + throw new OverflowException("JMXCrawler", e); + } finally { + if (jmxconn != null) { + try { + jmxconn.close(); + } catch (IOException e) { + } + } + } + } + + private List parse(Map dataMap, Map meta) { + + List row = new ArrayList<>(Arrays.asList(new String[meta.size()])); + for (Map.Entry info : meta.entrySet()) { + String data = dataMap.get(info.getKey()); + data = data.trim(); + row.set(info.getValue().intValue(), data); + } + return row; + } + + private Map parseAttribute(MBeanServerConnection beanCon, ObjectName mbeanName) + throws IntrospectionException, ReflectionException, InstanceNotFoundException, IOException, + AttributeNotFoundException, MBeanException { + + Map returnMap = new HashMap<>(); + MBeanInfo info = beanCon.getMBeanInfo(mbeanName); + + for (MBeanAttributeInfo attr : info.getAttributes()) { + + if (!attr.isReadable()) { + logCrawler(mbeanName, attr, "not readable"); + continue; + } + + // System.out.println("========================================================================"); + // System.out.println("PropertyListString"+mbeanName.getCanonicalKeyPropertyListString()); + // System.out.println("canonicaName="+mbeanName.getCanonicalName()); + // System.out.println(mbeanName.getDomain()); + // System.out.println(mbeanName.getKeyPropertyListString().compareTo("http")); + // System.out.println("========================================================================"); + Object att = null; + + try { + att = beanCon.getAttribute(mbeanName, attr.getName()); + } catch (Exception e) { + logCrawler(mbeanName, attr, "fail: " + e); + continue; + } + + if (att != null) + returnMap.put(attr.getName(), att.toString()); + } + return returnMap; + } + + private String parseObjectName(String s, String key) { + + int start = s.indexOf("["); + int end = s.lastIndexOf("]"); + s = s.substring(start + 1, end); + + String[] slices = s.split(","); + String returnData = ""; + for (String item : slices) { + String[] itemSplit = item.split("="); + if (itemSplit == null || itemSplit.length != 2) { + continue; + } + if (itemSplit[0].equals(key)) { + returnData = itemSplit[1]; + } + } + + return returnData; + } + + private Map getAuthority(boolean useSSL, String username, String password) { + Map environment = new HashMap(); + + if (username != null && username.length() != 0 && password != null && password.length() != 0) { + String[] credent = new String[] { username, password }; + environment.put(JMXConnector.CREDENTIALS, credent); + } + + if (useSSL) { + environment.put(Context.SECURITY_PROTOCOL, "ssl"); + SslRMIClientSocketFactory clientSocketFactory = new SslRMIClientSocketFactory(); + environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, clientSocketFactory); + environment.put("com.sun.jndi.rmi.factory.socket", clientSocketFactory); + } + + return environment; + } + + private static void logCrawler(String name, String msg) { + logger.log(Level.FINE, "crawler : '" + name + "': " + msg); + } + + private static void logCrawler(ObjectName mbeanName, MBeanAttributeInfo attr, String msg) { + logCrawler(mbeanName + "'_'" + attr.getName(), msg); + } + +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawler.java new file mode 100644 index 0000000..a046661 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawler.java @@ -0,0 +1,85 @@ +package com.loafle.overflow.container.general.crawler.impl.mongodb; + +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.crawler.Crawler; +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; +import com.mongodb.MongoClient; +import com.mongodb.MongoClientOptions; +import com.mongodb.ServerAddress; +import com.mongodb.client.MongoDatabase; +import org.bson.Document; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class MongoDBCrawler implements Crawler { + @Override + public String name() { + return "MONGODB"; + } + + @Override + public String toString() { + return "MongoDB Crawler"; + } + + @Override + public void auth(Map authInfoMap) throws OverflowException { + throw new OverflowException("Not implemented", null); + } + + @Override + public Map get(SensorConfig sensorConfig) throws OverflowException { + MongoClient mongoClient = null; + Map returnMap = new HashMap(); + + String dataBaseName = null; + String statusCommand = null; + + String targetIP = sensorConfig.getTarget().getConnection().getIp(); + int targetPort = sensorConfig.getTarget().getConnection().getPort(); + + try { + + mongoClient = new MongoClient(new ServerAddress(targetIP, targetPort), + MongoClientOptions.builder().serverSelectionTimeout(1000).connectTimeout(1000).socketTimeout(1000).build()); + + ResultSet rs = null; + List items = sensorConfig.getItems(); + List row = null; + for (Item item : items) { + + rs = ResultSet.newInstance(item); + Map metaMap = rs.getMeta(); + row = new ArrayList<>(Arrays.asList(new String[metaMap.size()])); + + dataBaseName = (String) item.getQueryInfo().getExtend().get("dataBaseName"); + statusCommand = (String) item.getQueryInfo().getExtend().get("statusCommand"); + + MongoDatabase database = mongoClient.getDatabase(dataBaseName); + Document serverStatus = database.runCommand(new Document(statusCommand, 1)); + + Map re = (Map) serverStatus.get(item.getQueryInfo().getQuery()); + + for (Map.Entry info : metaMap.entrySet()) { + row.set(info.getValue().intValue(), String.valueOf(re.get(info.getKey()))); + } + + rs.addRow(row); + returnMap.putAll(rs.getData()); + } + } catch (Exception e) { + throw new OverflowException("MongoDBCrawler", e); + } finally { + if (mongoClient != null) { + mongoClient.close(); + } + } + return returnMap; + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwer.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwer.java new file mode 100644 index 0000000..1aac268 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwer.java @@ -0,0 +1,126 @@ +package com.loafle.overflow.container.general.crawler.impl.redis; + +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.crawler.Crawler; +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import redis.clients.jedis.Jedis; + +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class RedisCralwer implements Crawler { + + private static final Logger LOGGER = Logger.getLogger(RedisCralwer.class.getName()); + + public RedisCralwer() { + + } + + @Override + public String name() { + return "REDIS"; + } + + @Override + public String toString() { + return "Redis Crawler"; + } + + @Override + public void auth(Map authIMap) throws OverflowException { + throw new OverflowException("Not implemented", null); + } + + @Override + public Map get(SensorConfig sensorConfig) throws OverflowException { + String targetIP = sensorConfig.getTarget().getConnection().getIp(); + int targetPort = sensorConfig.getTarget().getConnection().getPort(); + + String authpw = (String) sensorConfig.getTarget().getAuth().get("authpw"); + + Jedis jedis = null; + List items = sensorConfig.getItems(); + + try { + jedis = new Jedis(targetIP, targetPort, false); + if (authpw != null && !authpw.equals("")) { + String code = jedis.auth(authpw); + if (!code.equals("")) { + // set error auth + } + } + + Map returnMap = new HashMap(); + + for (Item item : items) { + ResultSet resultSet = ResultSet.newInstance(item); + + String queryString = (String) item.getQueryInfo().getQuery(); + String info = jedis.info(queryString); + Map resultMap = (Map) parseToMap(info).get(queryString); + + resultSet.addRow(parse(resultMap, resultSet.getMeta())); + + returnMap.putAll(resultSet.getData()); + } + + return returnMap; + } catch (Exception e) { + throw new OverflowException("RedisCralwer", e); + } finally { + if (jedis != null) { + jedis.close(); + } + } + } + + private List parse(Map dataMap, Map meta) { + + List row = new ArrayList<>(Arrays.asList(new String[meta.size()])); + for (Map.Entry info : meta.entrySet()) { + String data = dataMap.get(info.getKey()); + data = data.trim(); + row.set(info.getValue().intValue(), data); + } + return row; + } + + public Map parseToMap(String source) { + String[] categorys = source.split("\r\n\r\n"); + Map result = new HashMap(); + + for (String category : categorys) { + + if (category.length() == 0) { + continue; + } + Map sm = new HashMap(); + String[] lines = category.split("\r\n"); + + int idx = 0; + for (String line : lines) { + + if (idx == 0) { + idx++; + continue; + } + if (line.length() == 0) { + continue; + } + + String[] items = line.split(":"); + if (items.length != 0 && items.length > 1) { + sm.put(items[0], items[1]); + } + } + String[] ca = lines[0].split(" "); + result.put(ca[1], sm); + } + return result; + } + +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawler.java new file mode 100644 index 0000000..aab3449 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawler.java @@ -0,0 +1,151 @@ +package com.loafle.overflow.container.general.crawler.impl.snmp; + +import com.loafle.overflow.crawler.Crawler; +import com.loafle.overflow.model.sensorconfig.Connection; +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; +import com.loafle.overflow.container.general.crawler.impl.snmp.version.SNMPv2c; +import com.loafle.overflow.container.general.crawler.impl.snmp.version.SNMPv3; +import com.loafle.overflow.core.exception.OverflowException; + +import org.snmp4j.Snmp; +import org.snmp4j.TransportMapping; +import org.snmp4j.smi.Address; +import org.snmp4j.transport.DefaultUdpTransportMapping; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SNMPCrawler implements Crawler { + @Override + public String name() { + return "SNMP"; + } + + @Override + public String toString() { + return "SNMP Crawler"; + } + + @Override + public void auth(Map authIMap) throws OverflowException { + throw new OverflowException("Not implemented", null); + } + + @Override + public Map get(SensorConfig sensorConfig) throws OverflowException { + Snmp snmp = null; + TransportMapping transport = null; + + Map returnMap = new HashMap(); + + try { + transport = new DefaultUdpTransportMapping(); + snmp = new Snmp(transport); + transport.listen(); + + List items = sensorConfig.getItems(); + String[] oids = null; + + Map snmpResultMap = null; + for (Item item : items) { + oids = new String[item.getKeys().size()]; + for (int i = 0; i < item.getKeys().size(); i++) { + oids[i] = item.getKeys().get(i).getKey(); + } + + snmpResultMap = getSNMPV(snmp, sensorConfig, oids); + returnMap.putAll(convertResultSet(snmpResultMap, item).getData()); + } + return returnMap; + + } catch (Exception e) { + throw new OverflowException("RedisCralwer", e); + } finally { + if (snmp != null) { + try { + snmp.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (transport != null) { + try { + transport.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + private Map getSNMPV(Snmp snmp, SensorConfig sensorConfig, String[] oids) throws Exception { + + String targetVer = (String) sensorConfig.getTarget().getAuth().get("version"); + switch (targetVer) { + case "v2c": + return getV2c(snmp, sensorConfig, oids); + case "v3": + return getV3(snmp, sensorConfig, oids); + default: + new Exception("Unknown SNMP protocol : " + targetVer).printStackTrace(); + } + + return null; + } + + private Map getV2c(Snmp snmp, SensorConfig sensorConfig, String[] oids) throws Exception { + + SNMPv2c snmpV2 = new SNMPv2c(snmp); + + Map authInfo = sensorConfig.getTarget().getAuth(); + Connection connInfo = sensorConfig.getTarget().getConnection(); + + String ip = connInfo.getIp(); + int port = connInfo.getPort(); + String community = (String) authInfo.get("community"); + + return snmpV2.get(ip, port, community, oids); + } + + private Map getV3(Snmp snmp, SensorConfig sensorConfig, String[] oids) throws Exception { + SNMPv3 snmpV3 = new SNMPv3(snmp); + + Map authInfo = sensorConfig.getTarget().getAuth(); + Connection connInfo = sensorConfig.getTarget().getConnection(); + + String ip = connInfo.getIp(); + int port = connInfo.getPort(); + // String method = sensorConfig.get; + + String user = (String) authInfo.get("user"); + String authType = (String) authInfo.get("authType"); + String authPass = (String) authInfo.get("authPass"); + String privType = (String) authInfo.get("privType"); + String privPass = (String) authInfo.get("privPass"); + + return snmpV3.get(ip, port, user, authType, authPass, privType, privPass, oids); + } + + protected ResultSet convertResultSet(Map map, Item item) { + + ResultSet rs = ResultSet.newInstance(item); + + List row = new ArrayList<>(Arrays.asList(new String[map.size()])); + + Map metaMap = rs.getMeta(); + + for (Map.Entry info : metaMap.entrySet()) { + row.set(info.getValue().intValue(), map.get(info.getKey())); + } + rs.addRow(row); + + return rs; + } + +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMP.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMP.java new file mode 100644 index 0000000..eb0b536 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMP.java @@ -0,0 +1,82 @@ +package com.loafle.overflow.container.general.crawler.impl.snmp.version; + +import org.snmp4j.PDU; +import org.snmp4j.Snmp; +import org.snmp4j.Target; +import org.snmp4j.event.ResponseEvent; +import org.snmp4j.smi.OID; +import org.snmp4j.smi.VariableBinding; +import org.snmp4j.util.TreeEvent; +import org.snmp4j.util.TreeUtils; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by insanity on 17. 4. 10. + */ +public abstract class SNMP { + + protected Map get(Snmp snmp, PDU pdu, Target target) throws Exception { + + ResponseEvent response = snmp.get(pdu, target); + + if (response == null) { + throw new Exception("Error: No response from SNMP Agent."); + } + + PDU responsePDU = response.getResponse(); + if (responsePDU == null) { + throw new Exception("Error: Response PDU is null"); + } + + int errorStatus = responsePDU.getErrorStatus(); + int errorIndex = responsePDU.getErrorIndex(); + String errorStatusText = responsePDU.getErrorStatusText(); + + if (errorStatus != PDU.noError) { + throw new Exception("Error: " + errorIndex + " " + errorStatusText); + } + + Map result = new LinkedHashMap(); + for (VariableBinding varBinding : responsePDU.getVariableBindings()) { + if (varBinding == null) { + continue; + } + result.put(varBinding.getOid().toString(), varBinding.getVariable().toString()); + } + return result; + } + + protected Map walk(String oidStr, Target target, TreeUtils treeUtils) throws Exception { + OID oid = new OID(oidStr); + List events = treeUtils.getSubtree(target, oid); + + if(events == null || events.size() == 0){ + throw new Exception("No data."); + } + + Map result = new LinkedHashMap(); + for (TreeEvent event : events) { + if(event == null) { + continue; + } + if (event.isError()) { + System.err.println(event.getErrorMessage()); + continue; + } + + VariableBinding[] varBindings = event.getVariableBindings(); + + for (VariableBinding varBinding : varBindings) { + if (varBinding == null) { + continue; + } + result.put(varBinding.getOid().toString(), varBinding.getVariable().toString()); + } + } + return result; + } +} + diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv2c.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv2c.java new file mode 100644 index 0000000..03f6bc8 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv2c.java @@ -0,0 +1,63 @@ +package com.loafle.overflow.container.general.crawler.impl.snmp.version; + +import org.snmp4j.CommunityTarget; +import org.snmp4j.PDU; +import org.snmp4j.Snmp; +import org.snmp4j.mp.SnmpConstants; +import org.snmp4j.smi.*; +import org.snmp4j.util.DefaultPDUFactory; +import org.snmp4j.util.TreeUtils; + +import java.util.Map; + +public class SNMPv2c extends SNMP { + + private Snmp snmp = null; + + public SNMPv2c(Snmp snmp) { + this.snmp = snmp; + } + + private CommunityTarget getTarget(String addr, int port, String community) { + UdpAddress address = new UdpAddress(addr + "/" + port); + CommunityTarget target = new CommunityTarget(); + target.setCommunity(new OctetString(community)); + target.setAddress(address); + target.setRetries(2); + target.setTimeout(5000); + target.setVersion(SnmpConstants.version2c); + return target; + } + + public Boolean validate(String addr, int port, String community) throws Exception { + String testOid = "1.3.6.1.2.1.1.3.0"; + Map result = this.get(addr, port, community, new String[]{testOid}); + if (result.get(testOid) != null) return true; + return false; + } + + public Map walk(String addr, int port, String community, String oidStr) throws Exception { + + TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory()); + CommunityTarget target = getTarget(addr, port, community); + + return super.walk(oidStr, target, treeUtils); + } + + + public Map get(String addr, int port, String community, String[] oids) throws Exception { + + CommunityTarget target = getTarget(addr, port, community); + + PDU pdu = new PDU(); + for (String oid : oids) { + pdu.add(new VariableBinding(new OID(oid))); + } + pdu.setType(PDU.GET); + pdu.setRequestID(new Integer32(1)); + + return super.get(this.snmp, pdu, target); + } + +} + diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv3.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv3.java new file mode 100644 index 0000000..671d852 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/snmp/version/SNMPv3.java @@ -0,0 +1,148 @@ +package com.loafle.overflow.container.general.crawler.impl.snmp.version; + +import org.snmp4j.*; +import org.snmp4j.mp.MPv3; +import org.snmp4j.mp.MessageProcessingModel; +import org.snmp4j.mp.SnmpConstants; +import org.snmp4j.security.*; +import org.snmp4j.smi.*; +import org.snmp4j.transport.DefaultUdpTransportMapping; +import org.snmp4j.util.PDUFactory; +import org.snmp4j.util.TreeUtils; + +import java.util.Map; + +/** + * Created by insanity on 17. 4. 10. + */ +public class SNMPv3 extends SNMP { + + private Snmp snmp = null; + + public SNMPv3(Snmp snmp) { + this.snmp = snmp; + } + + public Boolean validate(String addr, int port, String user, String authType, String authPass, String privType, String privPass) throws Exception { + String testOid = "1.3.6.1.2.1.1.3.0"; + Map result = this.get(addr, port, user, authType, authPass, privType, privPass, new String[]{testOid}); + if (result.get(testOid) != null) return true; + return false; + } + + public Map walk(String addr, int port, String user, String authType, String authPass, String privType, String privPass, String oidStr) + throws Exception { + USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); + SecurityModels.getInstance().addSecurityModel(usm); + + UsmUser usmUser = getUser(user, authType, authPass, privType, privPass); + this.snmp.getUSM().addUser(new OctetString(user), usmUser); + + + TreeUtils treeUtils = new TreeUtils(this.snmp, new PDUFactory() { + public PDU createPDU(Target target) { + ScopedPDU sp = new ScopedPDU(); + sp.setRequestID(new Integer32(1)); + return sp; + } + + public PDU createPDU(MessageProcessingModel messageProcessingModel) { + return new ScopedPDU(); + } + }); + + Target target = getTarget(addr, port, usmUser); + return super.walk(oidStr, target, treeUtils); + } + + public Map get(String addr, int port, String user, String authType, String authPass, String privType, String privPass, String[] oids) + throws Exception { + + TransportMapping transport = new DefaultUdpTransportMapping(); + Snmp snmp = new Snmp(transport); + transport.listen(); + + USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); + SecurityModels.getInstance().addSecurityModel(usm); + + UsmUser usmUser = getUser(user, authType, authPass, privType, privPass); + this.snmp.getUSM().addUser(new OctetString(user), usmUser); + + PDU pdu = new ScopedPDU(); + for (String oid : oids) { + pdu.addOID(new VariableBinding(new OID(oid))); + } + pdu.setType(PDU.GET); + pdu.setRequestID(new Integer32(1)); + + Target target = getTarget(addr, port, usmUser); + + return super.get(snmp, pdu, target); + } + + private UserTarget getTarget(String addr, int port, UsmUser user) { + + UdpAddress address = new UdpAddress(addr + "/" + port); + UserTarget target = new UserTarget(); + target.setAddress(address); + target.setRetries(2); + target.setTimeout(5000); + target.setVersion(SnmpConstants.version3); + target.setSecurityModel(user.getSecurityModel()); + + int secLv; + OID autyType = user.getAuthenticationProtocol(); + OID privType = user.getPrivacyProtocol(); + if (autyType != null && privType != null) { + secLv = SecurityLevel.AUTH_PRIV; + }else if (autyType != null && privType == null) { + secLv = SecurityLevel.AUTH_NOPRIV; + }else { + secLv = SecurityLevel.NOAUTH_NOPRIV; + } + target.setSecurityLevel(secLv); + target.setSecurityName(new OctetString(user.getSecurityName())); + return target; + } + + private UsmUser getUser(String user, String authType, String authPass, String privType, String privPass) { + OctetString octetUser = new OctetString(user); + OctetString octetAuthPass = authPass.equals("") ? null : new OctetString(authPass); + OctetString octetPrivPass = privPass.equals("") ? null : new OctetString(privPass); + + UsmUser usmUser = new UsmUser(octetUser, getAuthOID(authType), octetAuthPass, getPrivOID(privType), octetPrivPass); + return usmUser; + } + + private OID getAuthOID(String authType) { + OID authOID = null; + switch(authType) { + case "": + authOID = null; + break; + case "MD5": + authOID = AuthMD5.ID; + break; + case "SHA": + authOID = AuthSHA.ID; + break; + } + return authOID; + } + + private OID getPrivOID(String privType) { + OID privOID = null; + switch(privType) { + case "": + privOID = null; + break; + case "DES": + privOID = PrivDES.ID; + break; + case "AES": + privOID = PrivAES128.ID; + break; + } + return privOID; + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java new file mode 100644 index 0000000..51db8f1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java @@ -0,0 +1,33 @@ +package com.loafle.overflow.container.general.crawler.impl.wmi; + +import com.loafle.overflow.core.exception.OverflowException; +import com.loafle.overflow.crawler.Crawler; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import java.util.Map; + +public class WMICrawler implements Crawler { + @Override + public String name() { + return "WMI"; + } + + @Override + public String toString() { + return "WMI Crawler"; + } + + @Override + public void auth(Map authIMap) throws OverflowException { + throw new OverflowException("Not implemented", null); + } + + @Override + public Map get(SensorConfig sensorConfig) throws OverflowException { + try { + return WMICrawlerOS.getInstance().process(sensorConfig); + } catch (Exception e) { + throw new OverflowException("WMICrawler", e); + } + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerLinux.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerLinux.java new file mode 100644 index 0000000..5794315 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerLinux.java @@ -0,0 +1,152 @@ +package com.loafle.overflow.container.general.crawler.impl.wmi; + +import java.util.*; + +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +public class WMICrawlerLinux extends WMICrawlerOS { + private final String DELIMITER = "||"; + private final String DELIMITER_SPLIT = "\\|\\|"; + + public ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception { + + List argList = createCommand(sensorConfig, item); + + String result = execute(argList.toArray(new String[argList.size()])); + + ResultSet ofResultSet = parseResult(result, item); + + return ofResultSet; + } + + public List createCommand(SensorConfig sensorConfig, Item item) throws Exception { + + String id = (String) sensorConfig.getTarget().getAuth().get("id"); + String pw = (String) sensorConfig.getTarget().getAuth().get("pw"); + String nameSpace = (String) item.getQueryInfo().getExtend().get("nameSpace"); + String ip = sensorConfig.getTarget().getConnection().getIp(); + String query = item.getQueryInfo().getQuery(); + + String wmicPath = (String) item.getQueryInfo().getExtend().get("wmicPath"); + //FIXME:: where is wmic ?? + List argList = new ArrayList(); + + argList.add(wmicPath); + argList.add("-U"); + argList.add(id + "%" + pw); + argList.add("//" + ip); + argList.add(query); + argList.add("--namespace=" + nameSpace); + argList.add("--delimiter=" + DELIMITER); + + return argList; + } + + public String execute(String... args) throws Exception { + System.out.println(""); + ProcessBuilder builder = new ProcessBuilder(args); + Process process = builder.start(); + + byte[] msg = new byte[1024]; + + StringBuffer buf = new StringBuffer(); + + while (process.getInputStream().read(msg) > 0) { + buf.append(new String(msg)); + Arrays.fill(msg, (byte) 0); + } + + return buf.toString(); + } + + public ResultSet parseResult(String result, Item item) throws Exception { + + if (result == null || result.length() <= 0) { + return null; + } + + result = result.trim(); + + String errStr = checkError(result); + if (errStr.length() > 0) { + throw new Exception(errStr); + } + + String[] lines = result.split("\\n"); + String line = ""; + + ResultSet ofResultSet = ResultSet.newInstance(item); + Map metaMap = ofResultSet.getMeta(); + + List columns = null; + Map tempMap = new HashMap(); + List row = null; + for (int indexI = 0; indexI < lines.length; ++indexI) { + tempMap.clear(); + + line = lines[indexI].trim(); + if (line.length() <= 0) + continue; + if (indexI == 0) { + int idx = line.indexOf("CLASS:"); + if (idx >= 0) { + continue; + } + } + + if (columns == null) { + String[] datas = line.split(DELIMITER_SPLIT); + columns = Arrays.asList(datas); + continue; + } + + row = new ArrayList<>(Arrays.asList(new String[metaMap.size()])); + + String[] datas = line.split(DELIMITER_SPLIT); + + for (int indexJ = 0; indexJ < columns.size(); ++indexJ) { + tempMap.put(columns.get(indexJ), datas[indexJ]); + } + + int tempSize = tempMap.size(); + int metaSize = metaMap.size(); + int resultSize = tempSize - metaSize; + + int currentIdx = 0; + for (Map.Entry info : metaMap.entrySet()) { + currentIdx = info.getValue().intValue(); + if (currentIdx >= metaSize) { + currentIdx -= resultSize; + } + row.set(currentIdx, tempMap.get(info.getKey())); + } + + ofResultSet.addRow(row); + + } + + return ofResultSet; + } + + public String checkError(String result) { + int errIdx = result.indexOf("ERROR:"); + String retErrStr = ""; + if (errIdx >= 0) { + + int enterIdx = result.indexOf("\\n", errIdx); + if (enterIdx < 0) + enterIdx = result.length(); + String errStr = result.substring(errIdx + "ERROR:".length(), enterIdx); + + // Map map = new HashMap<>(); + + // map.put("ERROR", errStr); + // resultMapList.add(map); + // return resultMapList; + retErrStr = errStr; + } + return retErrStr; + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java new file mode 100644 index 0000000..e80598f --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java @@ -0,0 +1,47 @@ +package com.loafle.overflow.container.general.crawler.impl.wmi; + +import java.util.HashMap; +import java.util.Map; + +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +public abstract class WMICrawlerOS { + + private static WMICrawlerOS wmiCrawlerOS = null; + + public static WMICrawlerOS getInstance() { + + if(WMICrawlerOS.wmiCrawlerOS == null) { + + String os = System.getProperty("os.name").toLowerCase(); + + if(os.indexOf("linux") >= 0) { + WMICrawlerOS.wmiCrawlerOS = new WMICrawlerLinux(); + } else if(os.indexOf("") >= 0) { + WMICrawlerOS.wmiCrawlerOS = new WMICrawlerWindows(); + } + + } + + return WMICrawlerOS.wmiCrawlerOS; + } + + public Map process(SensorConfig sensorConfig) throws Exception { + Map returnMap = new HashMap(); + + ResultSet ofResultSet = null; + for(int cIndexI = 0 ; cIndexI < sensorConfig.getItems().size() ; ++cIndexI) { + + ofResultSet = processWMI(sensorConfig, sensorConfig.getItems().get(cIndexI)); + returnMap.putAll(ofResultSet.getData()); + } + + + return returnMap; + } + + public abstract ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception ; +} + diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerWindows.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerWindows.java new file mode 100644 index 0000000..8c6f10f --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerWindows.java @@ -0,0 +1,249 @@ +package com.loafle.overflow.container.general.crawler.impl.wmi; + +import com.jacob.activeX.ActiveXComponent; +import com.jacob.com.Dispatch; +import com.jacob.com.EnumVariant; +import com.jacob.com.Variant; +import com.loafle.overflow.model.sensorconfig.Item; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class WMICrawlerWindows extends WMICrawlerOS { + + public ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception { + + String query = ""; + ActiveXComponent wmiconnect = null; + ResultSet ofResultSet = null; + + query = item.getQueryInfo().getQuery(); + wmiconnect = connectServer(sensorConfig, item); + + Variant vQuery = new Variant(query); + Variant vCollection = wmiconnect.invoke("ExecQuery", vQuery); + wmiconnect.safeRelease(); + vQuery.safeRelease(); + + Dispatch dConnection = vCollection.toDispatch(); + vCollection.safeRelease(); + // int count = getCount(dConnection); + + EnumVariant enumVariant = new EnumVariant(dConnection); + dConnection.safeRelease(); + + ofResultSet = getResultSet(enumVariant, item); + enumVariant.safeRelease(); + return ofResultSet; + } + + protected ResultSet getResultSet(EnumVariant enumVariant, Item citem) { + + ResultSet ofResultSet = ResultSet.newInstance(citem); + + Variant vItem = null; + Dispatch item = null; + + Variant vValue = null; + String value = null; + + List row = null; + Map metaMap = ofResultSet.getMeta(); + + while (enumVariant.hasMoreElements()) { + + row = new ArrayList<>(Arrays.asList(new String[metaMap.size()])); + + vItem = enumVariant.nextElement(); + item = vItem.toDispatch(); + + for (Map.Entry info : metaMap.entrySet()) { + vValue = Dispatch.call(item, info.getKey()); + value = vValue.toString(); + vValue.safeRelease(); + row.set(info.getValue().intValue(), value); + } + + vItem.safeRelease(); + item.safeRelease(); + + ofResultSet.addRow(row); + } + + return ofResultSet; + } + // + // protected void getMultiValue(EnumVariant enumVariant, Query cQuery, Item cItem, int idxMetric, Map resultMap) { + // + // Variant vItem = null; + // Dispatch item = null; + // + // + // int keyIdx = 0; + // while (enumVariant.hasMoreElements()) { + // + // vItem = enumVariant.nextElement(); + // item = vItem.toDispatch(); + // + // + // String name = null; + // String value = null; + // Variant vValue = null; + // + // for(int indexI = 0 ; indexI < cQuery.getKeys().size(); ++indexI) { + // name = cQuery.getKeys().get(indexI); + // vValue = Dispatch.call(item, name); + // value = vValue.toString(); + // String keyStr = convertArrayKey(cItem.getMetrics().get(indexI),keyIdx ); + // resultMap.put(keyStr, value); + // vValue.safeRelease(); + // } + // + // vItem.safeRelease(); + // item.safeRelease(); + // ++idxMetric; + // ++keyIdx; + // } + // + // } + + protected String convertArrayKey(String key, int index) { + int idx = key.indexOf("["); + String ret = ""; + + if (idx <= 0) { + idx = key.indexOf("."); + ret += key.substring(0, idx); + ret += "["; + ret += String.valueOf(index); + ret += "]"; + ret += key.substring(idx + 1); + } else { + + ret += key.substring(0, idx + 1); + ret += String.valueOf(index); + ret += key.substring(idx + 1); + } + + return ret; + } + + // protected void getSingleValue(EnumVariant enumVariant, Query cQuery, Item cItem, int idxMetric, Map resultMap) { + // + // Variant vItem = null; + // Dispatch item = null; + // + // while (enumVariant.hasMoreElements()) { + // + // vItem = enumVariant.nextElement(); + // item = vItem.toDispatch(); + // + // String name = null; + // String value = null; + // Variant vValue = null; + // + // for(int indexI = 0 ; indexI < cQuery.getKeys().size(); ++indexI) { + // name = cQuery.getKeys().get(indexI); + // vValue = Dispatch.call(item, name); + // value = vValue.toString(); + // resultMap.put(cItem.getMetrics().get(idxMetric++), value); + // vValue.safeRelease(); + // } + // + // vItem.safeRelease(); + // item.safeRelease(); + // } + // + // } + + protected List getColumns(Dispatch item) { + + List columns = new ArrayList(); + + Variant propertyesa = Dispatch.call(item, "Properties_"); + + Dispatch disProperty = propertyesa.toDispatch(); + + Variant newEnum = Dispatch.call(disProperty, "_NewEnum"); + + propertyesa.safeRelease(); + disProperty.safeRelease(); + + EnumVariant enumv = newEnum.toEnumVariant(); + + newEnum.safeRelease(); + + Variant vElem = null; + Dispatch disElem = null; + Variant vName = null; + + while (enumv.hasMoreElements()) { + vElem = enumv.nextElement(); + disElem = vElem.toDispatch(); + + vName = Dispatch.call(disElem, "Name"); + String vs = vName.toString(); + + columns.add(vs); + + disElem.safeRelease(); + vElem.safeRelease(); + vName.safeRelease(); + } + + enumv.safeRelease(); + return columns; + } + + protected int getCount(Dispatch d) { + + Variant c = Dispatch.call(d, "Count"); + + int retInt = Integer.valueOf(c.toString()); + + c.safeRelease(); + + return retInt; + } + + protected ActiveXComponent connectServer(SensorConfig sensorConfig, Item item) { + + String id = (String) sensorConfig.getTarget().getAuth().get("id"); + String pw = (String) sensorConfig.getTarget().getAuth().get("pw"); + String nameSpace = (String) item.getQueryInfo().getExtend().get("nameSpace"); + // String query = (String)sensorConfig.get.get("query"); + + String ip = sensorConfig.getTarget().getConnection().getIp(); + + ActiveXComponent wmi = null; + wmi = new ActiveXComponent("WbemScripting.SWbemLocator"); + + Variant vIp = new Variant(ip); + Variant vNs = new Variant(nameSpace); + Variant vId = new Variant(id); + Variant vPw = new Variant(pw); + + Variant conRet = wmi.invoke("ConnectServer", vIp, vNs, vId, vPw); + + vIp.safeRelease(); + vNs.safeRelease(); + vId.safeRelease(); + vPw.safeRelease(); + + Dispatch disConret = conRet.toDispatch(); + + ActiveXComponent wmiconnect = new ActiveXComponent(disConret); + disConret.safeRelease(); + + wmi.safeRelease(); + conRet.safeRelease(); + + return wmiconnect; + + } + +} diff --git a/src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java b/src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java new file mode 100644 index 0000000..b76d8a3 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/server/GeneralContainerServer.java @@ -0,0 +1,12 @@ +package com.loafle.overflow.container.general.server; + +import com.loafle.overflow.container.server.ContainerServer; + +import org.springframework.stereotype.Component; + +@Component +public class GeneralContainerServer extends ContainerServer { + + public GeneralContainerServer() { + } +} diff --git a/src/main/java/com/loafle/overflow/container/general/util/Primitives.java b/src/main/java/com/loafle/overflow/container/general/util/Primitives.java new file mode 100644 index 0000000..7169ec6 --- /dev/null +++ b/src/main/java/com/loafle/overflow/container/general/util/Primitives.java @@ -0,0 +1,44 @@ +package com.loafle.overflow.container.general.util; + +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public final class Primitives { + /** A map from primitive types to their corresponding wrapper types. */ + private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPE; + /** A map from wrapper types to their corresponding primitive types. */ + private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPE; + + static { + Map, Class> primToWrap = new HashMap, Class>(16); + Map, Class> wrapToPrim = new HashMap, Class>(16); + + add(primToWrap, wrapToPrim, boolean.class, Boolean.class); + add(primToWrap, wrapToPrim, byte.class, Byte.class); + add(primToWrap, wrapToPrim, char.class, Character.class); + add(primToWrap, wrapToPrim, double.class, Double.class); + add(primToWrap, wrapToPrim, float.class, Float.class); + add(primToWrap, wrapToPrim, int.class, Integer.class); + add(primToWrap, wrapToPrim, long.class, Long.class); + add(primToWrap, wrapToPrim, short.class, Short.class); + add(primToWrap, wrapToPrim, void.class, Void.class); + + PRIMITIVE_TO_WRAPPER_TYPE = Collections.unmodifiableMap(primToWrap); + WRAPPER_TO_PRIMITIVE_TYPE = Collections.unmodifiableMap(wrapToPrim); + } + + private static void add(Map, Class> forward, + Map, Class> backward, Class key, Class value) { + forward.put(key, value); + backward.put(value, key); + } + /** + * Returns true if this type is a primitive. + */ + public static boolean isPrimitive(Type type) { + return PRIMITIVE_TO_WRAPPER_TYPE.containsKey(type); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/CrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/CrawlerTest.java new file mode 100644 index 0000000..2bd9481 --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/CrawlerTest.java @@ -0,0 +1,10 @@ +package com.loafle.overflow.container.general.crawler; + +import org.junit.Before; + +public abstract class CrawlerTest { + @Before + public void setUp() throws Exception { + } + +} diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawlerTest.java new file mode 100644 index 0000000..712724e --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/DatabaseCrawlerTest.java @@ -0,0 +1,60 @@ +package com.loafle.overflow.container.general.crawler.impl.database; + +import com.google.gson.Gson; +import com.loafle.overflow.container.general.crawler.CrawlerTest; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class DatabaseCrawlerTest extends CrawlerTest { +// //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"); + protected SensorConfig getSensorConfig(String path) throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource(path).getFile(); + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class); + return c; + } + + protected void print(String s, Map m) { + + System.out.println(s); + + for (Map.Entry item : m.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + } + + +} diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawlerTest.java new file mode 100644 index 0000000..9d36102 --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/mysql/MySQLCrawlerTest.java @@ -0,0 +1,14 @@ +package com.loafle.overflow.container.general.crawler.impl.database.mysql; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest; +import org.junit.Test; + +import java.util.Map; + +public class MySQLCrawlerTest extends DatabaseCrawlerTest { + @Test + public void testMySQL() throws Exception { + Map result = new MySQLCrawler().get(getSensorConfig("config/mysql/mysql-test.json")); + print("MySQL row", result); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawlerTest.java new file mode 100644 index 0000000..f693857 --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/oracle/OracleCrawlerTest.java @@ -0,0 +1,16 @@ +package com.loafle.overflow.container.general.crawler.impl.database.oracle; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.Map; + +public class OracleCrawlerTest extends DatabaseCrawlerTest { + @Ignore + @Test + public void testMySQL() throws Exception { + Map result = new OracleCrawler().get(getSensorConfig("config/oracle/oracle-test.json")); + print("Oracle row", result); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawlerTest.java new file mode 100644 index 0000000..866f3fb --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/postgresql/PostgreSQLCrawlerTest.java @@ -0,0 +1,16 @@ +package com.loafle.overflow.container.general.crawler.impl.database.postgresql; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.Map; + +public class PostgreSQLCrawlerTest extends DatabaseCrawlerTest { + @Ignore + @Test + public void testPostgreSQL() throws Exception { + Map result = new PostgreSQLCrawler().get(getSensorConfig("config/postgresql/postgresql.json")); + print("PostgreSQL", result); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawlerTest.java new file mode 100644 index 0000000..1813ab2 --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/database/sqlserver/SQLServerCrawlerTest.java @@ -0,0 +1,25 @@ +package com.loafle.overflow.container.general.crawler.impl.database.sqlserver; + +import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +public class SQLServerCrawlerTest extends DatabaseCrawlerTest { + @Ignore + @Test + public void testConnection_Count() throws Exception { + Map result = new SQLServerCrawler().get(getSensorConfig("config/sqlserver/sqlserver_connection_count.json")); + print("SQL Server Connection count", result); + } + + @Ignore + @Test + public void testMultiKeyArray() throws Exception { + Map result = new SQLServerCrawler().get(getSensorConfig("config/sqlserver/sqlserver_multiple_key_array.json")); + print("SQL Server MultiArray", result); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawlerTest.java new file mode 100644 index 0000000..fbc91e7 --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/JMXCrawlerTest.java @@ -0,0 +1,6 @@ +package com.loafle.overflow.container.general.crawler.impl.jmx; + +import com.loafle.overflow.container.general.crawler.CrawlerTest; + +public class JMXCrawlerTest extends CrawlerTest { +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/tomcat/TomcatCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/tomcat/TomcatCrawlerTest.java new file mode 100644 index 0000000..d510b6d --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/jmx/tomcat/TomcatCrawlerTest.java @@ -0,0 +1,63 @@ +package com.loafle.overflow.container.general.crawler.impl.jmx.tomcat; + +import com.google.gson.Gson; +import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawler; +import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawlerTest; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class TomcatCrawlerTest extends JMXCrawlerTest { + + @Test + public void testSum() { + assertEquals(1, 1); + } + + @Ignore + @Test + public void TestDoCrawler() throws Exception { + + ClassLoader classLoader = getClass().getClassLoader(); + URL url = classLoader.getResource("config/tomcat/"); + String filePath = classLoader.getResource("config/tomcat/example1.json").getFile(); + + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + JMXCrawler cr = new JMXCrawler(); + Map result = cr.get(c); + + print("", result); + } + + //keytool -export -alias alias_name -keystore path_to_keystore_file -rfc -file path_to_certificate_file + private void print(String s, Map m) { + System.out.println(s); + + for (Map.Entry item : m.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + } + + @Ignore + @Test + public void testParseObject() { + String s = "org.apache.catalina.mbeans.ConnectorMBean[Catalina:type=Connector,port=8080]"; + + int start = s.indexOf("["); + int end = s.lastIndexOf("]"); + s = s.substring(start + 1, end); + assertEquals("Catalina:type=Connector,port=8080", s); + } +} diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawlerTest.java new file mode 100644 index 0000000..beb108d --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/mongodb/MongoDBCrawlerTest.java @@ -0,0 +1,40 @@ +package com.loafle.overflow.container.general.crawler.impl.mongodb; + +import com.google.gson.Gson; +import com.loafle.overflow.container.general.crawler.CrawlerTest; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Map; + +import static org.junit.Assert.*; + +public class MongoDBCrawlerTest extends CrawlerTest { + + @Test + @Ignore + public void TestCollectMetric() throws Exception { + + // read test resources config/example.json + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/mongodb/example.json").getFile(); + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + MongoDBCrawler cr = new MongoDBCrawler(); + Map m = cr.get(c); + + for (Map.Entry item : m.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + + // assertEquals(6, m.size()); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwerTest.java new file mode 100644 index 0000000..755aece --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/redis/RedisCralwerTest.java @@ -0,0 +1,42 @@ +package com.loafle.overflow.container.general.crawler.impl.redis; + +import com.google.gson.Gson; +import com.loafle.overflow.container.general.crawler.CrawlerTest; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Map; + +import static org.junit.Assert.*; + +public class RedisCralwerTest extends CrawlerTest { + + @Test + @Ignore + public void collectMetric() throws Exception { + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/redis/example.json").getFile(); + + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + RedisCralwer rc = new RedisCralwer(); + print("", rc.get(c)); + } + + private void print(String s, Map m) { + + System.out.println(s); + + for (Map.Entry item : m.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawlerTest.java new file mode 100644 index 0000000..42055a5 --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/snmp/SNMPCrawlerTest.java @@ -0,0 +1,70 @@ +package com.loafle.overflow.container.general.crawler.impl.snmp; + +import com.google.gson.Gson; +import com.loafle.overflow.container.general.crawler.CrawlerTest; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.Map; + +import static org.junit.Assert.*; + +public class SNMPCrawlerTest extends CrawlerTest { + /*** + * v2c test info + * private static String addr = "192.168.1.215"; + * private static String port = "161"; + * private static String community = "public"; + * + * v3 test info + * loafle MD5 "qwer5795" DES "qweqwe123" : AUTHPRIV + * loafle2 SHA "qwer5795" AES "qweqwe123" : AUTHPRIV + * loafle3 MD5 "qwer5795" : AUTHNOPRIV + * loafle4 :NOAUTHNOPRIV + */ + + @Ignore + @Test + public void testSNMP3() throws Exception { + SNMPCrawler c = new SNMPCrawler(); + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/snmp/examplev3.json").getFile(); + + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + Map result = c.get(config); + + printResult(result); + + } + + @Ignore + @Test + public void testSNMP2c() throws Exception { + SNMPCrawler c = new SNMPCrawler(); + + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/snmp/examplev2.json").getFile(); + + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + Map result = c.get(config); + + printResult(result); + } + + private void printResult(Map resultList) { + for (Map.Entry item : resultList.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerTest.java b/src/test/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerTest.java new file mode 100644 index 0000000..d5efa0e --- /dev/null +++ b/src/test/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerTest.java @@ -0,0 +1,294 @@ +package com.loafle.overflow.container.general.crawler.impl.wmi; + +import com.google.gson.Gson; +import com.loafle.overflow.container.general.crawler.CrawlerTest; +import com.loafle.overflow.model.sensorconfig.ResultSet; +import com.loafle.overflow.model.sensorconfig.SensorConfig; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.*; + +import static org.junit.Assert.*; + +public class WMICrawlerTest extends CrawlerTest { + @Before + public void setUp() throws Exception { + + } + + @After + public void tearDown() throws Exception { + + } + + @Ignore + @Test + public void testLinuxExe() throws Exception { + + String command = "/home/snoop/temp/wmic"; + + ProcessBuilder builder = new ProcessBuilder(command, "-U", "administrator%dbseogns18", "//192.168.1.106", + "SELECT Caption FROM Win32_LogicalDisk", "--namespace=root/cimv2", "--delimiter=||"); + Process process = builder.start(); + + byte[] msg = new byte[1024]; + + StringBuffer buf = new StringBuffer(); + + while (process.getInputStream().read(msg) > 0) { + buf.append(new String(msg)); + Arrays.fill(msg, (byte) 0); + } + + System.out.println(buf.toString()); + } + + @Test + public void testWMI() throws Exception { + WMICrawler wmiCrawler = new WMICrawler(); + + Map map = new HashMap(); + + // String id = "administrator"; + // String pw = "!@#$qwer1234"; + // String nameSpace = "root/cimv2"; + // String query = "select * from Win32_OperatingSystem"; + // String ip = "192.168.1.1"; + + // map.put("id", "administrator"); + // map.put("pw", "!@#$qwer1234"); + // map.put("nameSpace", "root/cimv2"); + // map.put("query", "select * from Win32_OperatingSystem"); + // map.put("ip", "192.168.1.1"); + + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/wmi").getFile(); + System.out.println(filePath); + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + // Config c = mapper.readValue(new File(classLoader.getResource("config").getFile()),Config.class); + + // List> resultList = (List>)wmiCrawler.getInternal(map); + // + // + // for( Map rMap : resultList) { + // for( String key : rMap.keySet() ){ + // System.out.println( String.format("key : %s ||| value : %s", key, rMap.get(key)) ); + // } + // } + + } + + @Test + public void testOS() { + System.out.println(System.getProperty("os.name")); + + } + + @Ignore + @Test + public void testConfig() throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/wmi/example.json").getFile(); + System.out.println(filePath); + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + + SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + System.out.println(config); + } + + @Ignore + @Test + public void testWMIJson() throws Exception { + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/wmi/meta/meta_network.json").getFile(); + + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + // Map map = new HashMap<>(); + // map.put("id", "administrator"); + // map.put("pw", "!@#$qwer1234"); + + // c.getTarget().setAuth(map); + + // c.getTarget().getAuth().put("id", "administrator"); + // c.getTarget().getAuth().put("pw", "!@#$qwer1234"); + + WMICrawler wmiCrawler = new WMICrawler(); + + Map resultList = wmiCrawler.get(config); + + PrintResultList(resultList); + // for(int indexI = 0 ; indexI < resultList.size(); ++indexI) { + // Map resultMap = resultList.get(indexI).getData(); + // System.out.println("============================================"); + // for( String key : resultMap.keySet() ){ + // System.out.println( String.format("key : %s ||| value : %s", key, resultMap.get(key)) ); + // } + // System.out.println("============================================"); + // } + + } + + public void PrintResultList(Map m) { + for (Map.Entry item : m.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + } + + @Ignore + @Test + public void testMetaProcess() throws Exception { + + // get targetinfo + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource("config/wmi/test.json").getFile(); + + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath))); + SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class); + + List metaConfigList = loadMetaConfig(); + + Map retlist = new HashMap<>(); + WMICrawlerOS os = WMICrawlerOS.getInstance(); + ResultSet ofResultSet = null; + for (SensorConfig metaConfig : metaConfigList) { + + for (int indexI = 0; indexI < metaConfig.getItems().size(); ++indexI) { + ofResultSet = os.processWMI(config, metaConfig.getItems().get(indexI)); + if (ofResultSet != null) { + retlist.putAll(ofResultSet.getData()); + } + } + } + + PrintResultList(retlist); + + } + + public List loadMetaConfig() throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + + URL url = classLoader.getResource("config/wmi/meta"); + if (url == null) { + return null; + } + + String path = url.getFile(); + File pathFile = new File(path); + + System.out.println(path); + String[] metaFiles = pathFile.list(); + List retList = new ArrayList<>(); + + for (String fi : metaFiles) { + if (fi.indexOf("meta_") > -1) { + InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(path + "/" + fi))); + SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class); + if (config != null) { + retList.add(config); + } + } + } + + return retList; + } + + @Test + public void testInt() { + + Integer a = 1; + + aaa(a); + + System.out.println(a); + + } + + public void aaa(Integer a) { + ++a; + + } + + @Test + public void testString() { + + String str = "cpu[].usage.system"; + + int idx = str.indexOf("["); + int arrIdx = 0; + + String ret = ""; + ret += str.substring(0, idx + 1); + ret += String.valueOf(arrIdx); + ret += str.substring(idx + 1); + + System.out.println(ret); + + } + + @Test + public void testReplace() { + + String aaa = "cpu[$0].usage.system"; + + String bbb = "$"; + String ccc = bbb + String.valueOf(0); + + String ddd = aaa.replace(ccc, "asdfasdf"); + + System.out.println(ddd); + + } + + @Test + public void testMap() { + + Map aa = new HashMap<>(); + + aa.put("111", "123123123"); + aa.put("222", "123123123"); + + Map bb = new HashMap<>(); + + bb.put("333", "123123123"); + bb.put("444", "123123123"); + + aa.putAll(bb); + + for (String key : aa.keySet()) { + System.out.println(String.format("key : %s ||| value : %s", key, aa.get(key))); + } + + } + + @Test + public void testRes() throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + + URL url = classLoader.getResource("config/wmi/meta"); + + File file = new File(url.getFile()); + + String[] fl = file.list(); + + for (String f : fl) { + System.out.println(f); + } + + } + +} diff --git a/src/test/resources/_ b/src/test/resources/_ new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/config/mongodb/example.json b/src/test/resources/config/mongodb/example.json new file mode 100644 index 0000000..cb4c423 --- /dev/null +++ b/src/test/resources/config/mongodb/example.json @@ -0,0 +1,43 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.215", + "port" : "27017", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"mongodb", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + {"metric":"memory.usage.bits", "key":"bits"}, + {"metric":"memory.usage.rss", "key":"resident"}, + {"metric":"memory.usage.vmem", "key":"virtual"}, + {"metric":"memory.usage.supported", "key":"supported"}, + {"metric":"memory.usage.mapped", "key":"mapped"}, + {"metric":"memory.usage.mappedWithJournal", "key":"mappedWithJournal"} + ], + "queryInfo" : { + "query": "mem", + "extend" : { + "dataBaseName":"admin", + "statusCommand": "serverStatus" + } + }, + "mappingInfo" : { + "parseDirection" : "col" + } + } + ] +} diff --git a/src/test/resources/config/mysql/mysql-test.json b/src/test/resources/config/mysql/mysql-test.json new file mode 100644 index 0000000..7689231 --- /dev/null +++ b/src/test/resources/config/mysql/mysql-test.json @@ -0,0 +1,395 @@ +{ + "id": "3", + "target": { + "auth": { + "pw": "qwer5795QWER", + "id": "docker", + "url": "jdbc:mysql://192.168.1.15:33067" + }, + "connection": { + "ip": "192.168.1.15", + "port": "33067", + "portType": "TCP", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "MYSQL_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "Performance.mysql.schema.users.lost", + "key": "Performance_schema_users_lost" + }, + { + "metric": "Performance.mysql.schema.thread.instances.lost", + "key": "Performance_schema_thread_instances_lost" + }, + { + "metric": "Performance.mysql.schema.thread.classes.lost", + "key": "Performance_schema_thread_classes_lost" + }, + { + "metric": "Performance.mysql.schema.table.lock.stat.lost", + "key": "Performance_schema_table_lock_stat_lost" + }, + { + "metric": "Performance.mysql.schema.table.instances.lost", + "key": "Performance_schema_table_instances_lost" + }, + { + "metric": "Performance.mysql.schema.table.handles.lost", + "key": "Performance_schema_table_handles_lost" + }, + { + "metric": "Performance.mysql.schema.statement.classes.lost", + "key": "Performance_schema_statement_classes_lost" + }, + { + "metric": "Performance.mysql.schema.stage.classes.lost", + "key": "Performance_schema_stage_classes_lost" + }, + { + "metric": "Performance.mysql.schema.socket.instances.lost", + "key": "Performance_schema_socket_instances_lost" + }, + { + "metric": "Performance.mysql.schema.socket.classes.lost", + "key": "Performance_schema_socket_classes_lost" + }, + { + "metric": "Performance.mysql.schema.session.connect.attrs.lost", + "key": "Performance_schema_session_connect_attrs_lost" + }, + { + "metric": "Performance.mysql.schema.rwlock.instances.lost", + "key": "Performance_schema_rwlock_instances_lost" + }, + { + "metric": "Performance.mysql.schema.rwlock.classes.lost", + "key": "Performance_schema_rwlock_classes_lost" + }, + { + "metric": "Performance.mysql.schema.program.lost", + "key": "Performance_schema_program_lost" + }, + { + "metric": "Performance.mysql.schema.prepared.statements.lost", + "key": "Performance_schema_prepared_statements_lost" + }, + { + "metric": "Performance.mysql.schema.nested.statement.lost", + "key": "Performance_schema_nested_statement_lost" + }, + { + "metric": "Performance.mysql.schema.mutex.instances.lost", + "key": "Performance_schema_mutex_instances_lost" + }, + { + "metric": "Performance.mysql.schema.mutex.classes.lost", + "key": "Performance_schema_mutex_classes_lost" + }, + { + "metric": "Performance.mysql.schema.metadata.lock.lost", + "key": "Performance_schema_metadata_lock_lost" + }, + { + "metric": "Performance.mysql.schema.memory.classes.lost", + "key": "Performance_schema_memory_classes_lost" + }, + { + "metric": "Performance.mysql.schema.locker.lost", + "key": "Performance_schema_locker_lost" + }, + { + "metric": "Performance.mysql.schema.index.stat.lost", + "key": "Performance_schema_index_stat_lost" + }, + { + "metric": "Performance.mysql.schema.hosts.lost", + "key": "Performance_schema_hosts_lost" + }, + { + "metric": "Performance.mysql.schema.file.instances.lost", + "key": "Performance_schema_file_instances_lost" + }, + { + "metric": "Performance.mysql.schema.file.handles.lost", + "key": "Performance_schema_file_handles_lost" + }, + { + "metric": "Performance.mysql.schema.file.classes.lost", + "key": "Performance_schema_file_classes_lost" + }, + { + "metric": "Performance.mysql.schema.digest.lost", + "key": "Performance_schema_digest_lost" + }, + { + "metric": "Performance.mysql.schema.cond.instances.lost", + "key": "Performance_schema_cond_instances_lost" + }, + { + "metric": "Performance.mysql.schema.cond.classes.lost", + "key": "Performance_schema_cond_classes_lost" + }, + { + "metric": "Performance.mysql.schema.accounts.lost", + "key": "Performance_schema_accounts_lost" + }, + { + "metric": "Connection.mysql.Max.used.connections.time", + "key": "Max_used_connections_time" + }, + { + "metric": "Connection.mysql.Max.used.connections", + "key": "Max_used_connections" + }, + { + "metric": "Connection.mysql.connections", + "key": "Connections" + }, + { + "metric": "Connection.mysql.errors.tcpwrap", + "key": "Connection_errors_tcpwrap" + }, + { + "metric": "Connection.mysql.errors.select", + "key": "Connection_errors_select" + }, + { + "metric": "Connection.mysql.errors.peer.address", + "key": "Connection_errors_peer_address" + }, + { + "metric": "Connection.mysql.errors.max.connections", + "key": "Connection_errors_max_connections" + }, + { + "metric": "Connection.mysql.errors.internal", + "key": "Connection_errors_internal" + }, + { + "metric": "Connection.mysql.errors.accept", + "key": "Connection_errors_accept" + }, + { + "metric": "Innodb.mysql.available.undo.logs", + "key": "Innodb_available_undo_logs" + }, + { + "metric": "Innodb.mysql.truncated.status.writes", + "key": "Innodb_truncated_status_writes" + }, + { + "metric": "Innodb.mysql.num.open.files", + "key": "Innodb_num_open_files" + }, + { + "metric": "Innodb.mysql.rows.updated", + "key": "Innodb_rows_updated" + }, + { + "metric": "Innodb.mysql.rows.read", + "key": "Innodb_rows_read" + }, + { + "metric": "Innodb.mysql.rows.inserted", + "key": "Innodb_rows_inserted" + }, + { + "metric": "Innodb.mysql.rows.deleted", + "key": "Innodb_rows_deleted" + }, + { + "metric": "Innodb.mysql.row.lock.waits", + "key": "Innodb_row_lock_waits" + }, + { + "metric": "Innodb.mysql.row.lock.time.max", + "key": "Innodb_row_lock_time_max" + }, + { + "metric": "Innodb.mysql.row.lock.time.avg", + "key": "Innodb_row_lock_time_avg" + }, + { + "metric": "Innodb.mysql.row.lock.time", + "key": "Innodb_row_lock_time" + }, + { + "metric": "Innodb.mysql.row.lock.current.waits", + "key": "Innodb_row_lock_current_waits" + }, + { + "metric": "Innodb.mysql.pages.written", + "key": "Innodb_pages_written" + }, + { + "metric": "Innodb.mysql.pages.read", + "key": "Innodb_pages_read" + }, + { + "metric": "Innodb.mysql.pages.created", + "key": "Innodb_pages_created" + }, + { + "metric": "Innodb.mysql.page.size", + "key": "Innodb_page_size" + }, + { + "metric": "Innodb.mysql.os.log.written", + "key": "Innodb_os_log_written" + }, + { + "metric": "Innodb.mysql.os.log.pending.writes", + "key": "Innodb_os_log_pending_writes" + }, + { + "metric": "Innodb.mysql.os.log.pending.fsyncs", + "key": "Innodb_os_log_pending_fsyncs" + }, + { + "metric": "Innodb.mysql.os.log.fsyncs", + "key": "Innodb_os_log_fsyncs" + }, + { + "metric": "Innodb.mysql.log.writes", + "key": "Innodb_log_writes" + }, + { + "metric": "Innodb.mysql.log.write.requests", + "key": "Innodb_log_write_requests" + }, + { + "metric": "Innodb.mysql.log.waits", + "key": "Innodb_log_waits" + }, + { + "metric": "Innodb.mysql.dblwr.writes", + "key": "Innodb_dblwr_writes" + }, + { + "metric": "Innodb.mysql.dblwr.pages.written", + "key": "Innodb_dblwr_pages_written" + }, + { + "metric": "Innodb.mysql.data.written", + "key": "Innodb_data_written" + }, + { + "metric": "Innodb.mysql.data.writes", + "key": "Innodb_data_writes" + }, + { + "metric": "Innodb.mysql.data.reads", + "key": "Innodb_data_reads" + }, + { + "metric": "Innodb.mysql.data.read", + "key": "Innodb_data_read" + }, + { + "metric": "Innodb.mysql.data.pending.writes", + "key": "Innodb_data_pending_writes" + }, + { + "metric": "Innodb.mysql.data.pending.reads", + "key": "Innodb_data_pending_reads" + }, + { + "metric": "Innodb.mysql.data.pending.fsyncs", + "key": "Innodb_data_pending_fsyncs" + }, + { + "metric": "Innodb.mysql.data.fsyncs", + "key": "Innodb_data_fsyncs" + }, + { + "metric": "Innodb.mysql.buffer.pool.write.requests", + "key": "Innodb_buffer_pool_write_requests" + }, + { + "metric": "Innodb.mysql.buffer.pool.wait.free", + "key": "Innodb_buffer_pool_wait_free" + }, + { + "metric": "Innodb.mysql.buffer.pool.reads", + "key": "Innodb_buffer_pool_reads" + }, + { + "metric": "Innodb.mysql.buffer.pool.read.requests", + "key": "Innodb_buffer_pool_read_requests" + }, + { + "metric": "Innodb.mysql.buffer.pool.read.ahead.evicted", + "key": "Innodb_buffer_pool_read_ahead_evicted" + }, + { + "metric": "Innodb.mysql.buffer.pool.read.ahead", + "key": "Innodb_buffer_pool_read_ahead" + }, + { + "metric": "Innodb.mysql.buffer.pool.read.ahead.rnd", + "key": "Innodb_buffer_pool_read_ahead_rnd" + }, + { + "metric": "Innodb.mysql.buffer.pool.pages.total", + "key": "Innodb_buffer_pool_pages_total" + }, + { + "metric": "Innodb.mysql.buffer.pool.pages.misc", + "key": "Innodb_buffer_pool_pages_misc" + }, + { + "metric": "Innodb.mysql.buffer.pool.pages.free", + "key": "Innodb_buffer_pool_pages_free" + }, + { + "metric": "Innodb.mysql.buffer.pool.pages.flushed", + "key": "Innodb_buffer_pool_pages_flushed" + }, + { + "metric": "Innodb.mysql.buffer.pool.bytes.dirty", + "key": "Innodb_buffer_pool_bytes_dirty" + }, + { + "metric": "Innodb.mysql.buffer.pool.pages.dirty", + "key": "Innodb_buffer_pool_pages_dirty" + }, + { + "metric": "Innodb.mysql.buffer.pool.bytes.data", + "key": "Innodb_buffer_pool_bytes_data" + }, + { + "metric": "Innodb.mysql.buffer.pool.pages.data", + "key": "Innodb_buffer_pool_pages_data" + }, + { + "metric": "Innodb.mysql.buffer.pool.resize.status", + "key": "Innodb_buffer_pool_resize_status" + }, + { + "metric": "Innodb.mysql.buffer.pool.load.status", + "key": "Innodb_buffer_pool_load_status" + }, + { + "metric": "Innodb.mysql.buffer.pool.dump.status", + "key": "Innodb_buffer_pool_dump_status" + }], + "queryInfo": { + "query": "show status where variable_name = 'Performance_schema_users_lost' or variable_name = 'Performance_schema_thread_instances_lost' or variable_name = 'Performance_schema_thread_classes_lost' or variable_name = 'Performance_schema_table_lock_stat_lost' or variable_name = 'Performance_schema_table_instances_lost' or variable_name = 'Performance_schema_table_handles_lost' or variable_name = 'Performance_schema_statement_classes_lost' or variable_name = 'Performance_schema_stage_classes_lost' or variable_name = 'Performance_schema_socket_instances_lost' or variable_name = 'Performance_schema_socket_classes_lost' or variable_name = 'Performance_schema_session_connect_attrs_lost' or variable_name = 'Performance_schema_rwlock_instances_lost' or variable_name = 'Performance_schema_rwlock_classes_lost' or variable_name = 'Performance_schema_program_lost' or variable_name = 'Performance_schema_prepared_statements_lost' or variable_name = 'Performance_schema_nested_statement_lost' or variable_name = 'Performance_schema_mutex_instances_lost' or variable_name = 'Performance_schema_mutex_classes_lost' or variable_name = 'Performance_schema_metadata_lock_lost' or variable_name = 'Performance_schema_memory_classes_lost' or variable_name = 'Performance_schema_locker_lost' or variable_name = 'Performance_schema_index_stat_lost' or variable_name = 'Performance_schema_hosts_lost' or variable_name = 'Performance_schema_file_instances_lost' or variable_name = 'Performance_schema_file_handles_lost' or variable_name = 'Performance_schema_file_classes_lost' or variable_name = 'Performance_schema_digest_lost' or variable_name = 'Performance_schema_cond_instances_lost' or variable_name = 'Performance_schema_cond_classes_lost' or variable_name = 'Performance_schema_accounts_lost' or variable_name = 'Max_used_connections_time' or variable_name = 'Max_used_connections' or variable_name = 'Connections' or variable_name = 'Connection_errors_tcpwrap' or variable_name = 'Connection_errors_select' or variable_name = 'Connection_errors_peer_address' or variable_name = 'Connection_errors_max_connections' or variable_name = 'Connection_errors_internal' or variable_name = 'Connection_errors_accept' or variable_name = 'Innodb_available_undo_logs' or variable_name = 'Innodb_truncated_status_writes' or variable_name = 'Innodb_num_open_files' or variable_name = 'Innodb_rows_updated' or variable_name = 'Innodb_rows_read' or variable_name = 'Innodb_rows_inserted' or variable_name = 'Innodb_rows_deleted' or variable_name = 'Innodb_row_lock_waits' or variable_name = 'Innodb_row_lock_time_max' or variable_name = 'Innodb_row_lock_time_avg' or variable_name = 'Innodb_row_lock_time' or variable_name = 'Innodb_row_lock_current_waits' or variable_name = 'Innodb_pages_written' or variable_name = 'Innodb_pages_read' or variable_name = 'Innodb_pages_created' or variable_name = 'Innodb_page_size' or variable_name = 'Innodb_os_log_written' or variable_name = 'Innodb_os_log_pending_writes' or variable_name = 'Innodb_os_log_pending_fsyncs' or variable_name = 'Innodb_os_log_fsyncs' or variable_name = 'Innodb_log_writes' or variable_name = 'Innodb_log_write_requests' or variable_name = 'Innodb_log_waits' or variable_name = 'Innodb_dblwr_writes' or variable_name = 'Innodb_dblwr_pages_written' or variable_name = 'Innodb_data_written' or variable_name = 'Innodb_data_writes' or variable_name = 'Innodb_data_reads' or variable_name = 'Innodb_data_read' or variable_name = 'Innodb_data_pending_writes' or variable_name = 'Innodb_data_pending_reads' or variable_name = 'Innodb_data_pending_fsyncs' or variable_name = 'Innodb_data_fsyncs' or variable_name = 'Innodb_buffer_pool_write_requests' or variable_name = 'Innodb_buffer_pool_wait_free' or variable_name = 'Innodb_buffer_pool_reads' or variable_name = 'Innodb_buffer_pool_read_requests' or variable_name = 'Innodb_buffer_pool_read_ahead_evicted' or variable_name = 'Innodb_buffer_pool_read_ahead' or variable_name = 'Innodb_buffer_pool_read_ahead_rnd' or variable_name = 'Innodb_buffer_pool_pages_total' or variable_name = 'Innodb_buffer_pool_pages_misc' or variable_name = 'Innodb_buffer_pool_pages_free' or variable_name = 'Innodb_buffer_pool_pages_flushed' or variable_name = 'Innodb_buffer_pool_bytes_dirty' or variable_name = 'Innodb_buffer_pool_pages_dirty' or variable_name = 'Innodb_buffer_pool_bytes_data' or variable_name = 'Innodb_buffer_pool_pages_data' or variable_name = 'Innodb_buffer_pool_resize_status' or variable_name = 'Innodb_buffer_pool_load_status' or variable_name = 'Innodb_buffer_pool_dump_status'", + "extend": null + }, + "mappingInfo": { + "parseDirection": "row", + "arrayColumns": null, + "keyColumns": ["Variable_name"], + "valueColumn": "Value" + } + }] +} diff --git a/src/test/resources/config/mysql/mysql.json b/src/test/resources/config/mysql/mysql.json new file mode 100644 index 0000000..85496b6 --- /dev/null +++ b/src/test/resources/config/mysql/mysql.json @@ -0,0 +1,44 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.104", + "port" : "6379", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "url":"jdbc:mysql://192.168.1.215:3306", + "id":"root", + "pw":"qwe123" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"mysql", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + { + "metric":"net.connection_count", + "key":"Connections" + } + + ], + "queryInfo" : { + "query":"show status where `variable_name` = 'Connections'" + }, + "mappingInfo" : { + "parseDirection" : "row", + "valueColumn" : "Value", + "keyColumns" : [ + "Variable_name" + ] + } + } + ] +} diff --git a/src/test/resources/config/postgresql/postgresql.json b/src/test/resources/config/postgresql/postgresql.json new file mode 100644 index 0000000..cf9e4fd --- /dev/null +++ b/src/test/resources/config/postgresql/postgresql.json @@ -0,0 +1,36 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.107", + "port" : "5432", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "url":"jdbc:postgresql://192.168.1.107:5432/postgres", + "id":"postgres", + "pw":"!@#$qwer1234" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"pgsql", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + { + "metric":"net.connection_count", + "key" : "connection_count" + } + ], + "queryInfo":{ + "query" : "select count(pid) as connection_count from pg_catalog.pg_stat_activity where state <> 'idle'" + } + } + ] +} diff --git a/src/test/resources/config/redis/example.json b/src/test/resources/config/redis/example.json new file mode 100644 index 0000000..4371d00 --- /dev/null +++ b/src/test/resources/config/redis/example.json @@ -0,0 +1,67 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.104", + "port" : "6379", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"redis_protocol_crawler", + "container":"network_crawler" + }, + "items" : [ + { + "keys" : [ + { + "metric":"cpu.usage.system", + "key":"used_cpu_sys" + }, + { + "metric":"cpu.usage.user", + "key":"used_cpu_user" + }, + { + "metric":"cpu.usage.system_children", + "key":"used_cpu_sys_children" + }, + { + "metric":"cpu.usage.user_children", + "key":"used_cpu_user_children" + } + ], + "queryInfo" : { + "query" : "CPU" + }, + "mappingInfo" : {} + }, + { + "keys" : [ + { + "metric":"memory.usage.used", + "key":"used_memory" + }, + { + "metric":"memory.usage.rss", + "key":"used_memory_rss" + }, + { + "metric":"memory.usage.peak", + "key":"used_memory_peak" + } + ], + "queryInfo" : { + "query" : "Memory" + }, + "mappingInfo" : {} + } + ] +} diff --git a/src/test/resources/config/snmp/examplev2.json b/src/test/resources/config/snmp/examplev2.json new file mode 100644 index 0000000..d53f370 --- /dev/null +++ b/src/test/resources/config/snmp/examplev2.json @@ -0,0 +1,38 @@ +{ + "id" : "insanity", + "target" : { + "connection" : { + "ip" : "192.168.1.254", + "port" : "161", + "ssl" : false, + "portType" : "udp" + }, + "auth" : { + "version":"v2c", + "community" : "loafle" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"snmp_crawler", + "container":"java" + }, + "items" : [ + { + "keys" : [ + {"metric":"system.uptime", "key":"1.3.6.1.2.1.1.3.0"} + ], + "queryInfo" : { + "query": "mem", + "extend" : { + "method": "get" + } + }, + "mappingInfo" : { + "parseDirection" : "col" + } + } + ] +} diff --git a/src/test/resources/config/snmp/examplev3.json b/src/test/resources/config/snmp/examplev3.json new file mode 100644 index 0000000..ef2e2b2 --- /dev/null +++ b/src/test/resources/config/snmp/examplev3.json @@ -0,0 +1,42 @@ +{ + "id" : "insanity", + "target" : { + "connection" : { + "ip" : "192.168.1.215", + "port" : "161", + "ssl" : false, + "portType" : "udp" + }, + "auth" : { + "version" : "v3", + "user" : "loafle", + "authType" : "MD5", + "authPass" : "qwer5795", + "privType" : "DES", + "privPass" : "qweqwe123" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"snmp_crawler", + "container":"java" + }, + "items" : [ + { + "keys" : [ + {"metric":"system.uptime", "key":"1.3.6.1.2.1.1.3.0"} + ], + "queryInfo" : { + "query": "mem", + "extend" : { + "method": "get" + } + }, + "mappingInfo" : { + "parseDirection" : "col" + } + } + ] +} diff --git a/src/test/resources/config/sqlserver/sqlserver_connection_count.json b/src/test/resources/config/sqlserver/sqlserver_connection_count.json new file mode 100644 index 0000000..f3f0362 --- /dev/null +++ b/src/test/resources/config/sqlserver/sqlserver_connection_count.json @@ -0,0 +1,38 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "1433", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "url":"jdbc:sqlserver://192.168.1.106:1433;", + "id":"sa", + "pw":"qwe123" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"mssql", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + { + "metric" :"net.connection_count", + "key" : "connection_count" + } + ], + "queryInfo" : { + "query": "select count(session_id) as connection_count from sys.dm_exec_connections where session_id = @@SPID" + }, + "mappingInfo" : {} + } + + ] +} diff --git a/src/test/resources/config/sqlserver/sqlserver_multiple_key_array.json b/src/test/resources/config/sqlserver/sqlserver_multiple_key_array.json new file mode 100644 index 0000000..4548709 --- /dev/null +++ b/src/test/resources/config/sqlserver/sqlserver_multiple_key_array.json @@ -0,0 +1,50 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "1433", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "url":"jdbc:sqlserver://192.168.1.106:1433;", + "id":"sa", + "pw":"qwe123", + "query" : "select * from master.dbo.sysprocesses" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"mssql", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + { + "metric" : "object[$0].db[$1].datafile_size", + "key" : "Data File(s) Size (KB)" + }, + { + "metric" : "object[$0].db[$1].logfile_size", + "key" : "Log File(s) Size (KB)" + } + ], + "queryInfo" : { + "query": "select object_name,instance_name, counter_name, cntr_value from sys.dm_os_performance_counters where ( counter_name = 'Data File(s) Size (KB)' or counter_name = 'Log File(s) Size (KB)' ) AND object_name = 'SQLServer:Databases'", + "extend" : { + + } + }, + "mappingInfo" : { + "parseDirection" : "row", + "arrayColumns" : [ "object_name","instance_name"], + "keyColumns" : ["counter_name"], + "valueColumn" : "cntr_value" + } + } + ] +} diff --git a/src/test/resources/config/tomcat/example.json b/src/test/resources/config/tomcat/example.json new file mode 100644 index 0000000..f2a9393 --- /dev/null +++ b/src/test/resources/config/tomcat/example.json @@ -0,0 +1,46 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "9840", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "id": "jmxuser", + "pw": "tomcat" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"jmx", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + {"metric" : "net.connector[$0].requestCount", "key" : "requestCount"}, + {"metric" : "net.connector[$0].loadOnStartup", "key" : "loadOnStartup"}, + {"metric" : "net.connector[$0].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$0].objectName", "key" : "objectName"} + ], + "queryInfo" : { + "query": "*Catalina:j2eeType=Servlet,*", + "extend" : { + "aliases" : [ + { + "key": "WebModule", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "Servlet" ] + } + } + ] +} diff --git a/src/test/resources/config/tomcat/example1.json b/src/test/resources/config/tomcat/example1.json new file mode 100644 index 0000000..9d9a394 --- /dev/null +++ b/src/test/resources/config/tomcat/example1.json @@ -0,0 +1,130 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "9840", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "id": "jmxuser", + "pw": "tomcat" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"jmx", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + {"metric" : "net.connector[$0].maxThreads", "key" : "maxThreads"}, + {"metric" : "net.connector[$0].currentThreadCount", "key" : "currentThreadCount"}, + {"metric" : "net.connector[$0].currentThreadsBusy", "key" : "currentThreadsBusy"} + ], + "queryInfo" : { + "query": "*Catalina:type=ThreadPool,*", + "extend" : { + "aliases" : [ + { + "key": "name", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "ThreadPool" ] + } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].bytesSent", "key" : "bytesSent"}, + {"metric" : "net.connector[$0].bytesReceived", "key" : "bytesReceived"}, + {"metric" : "net.connector[$0].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$0].requestCount", "key" : "requestCount"}, + {"metric" : "net.connector[$0].maxTime", "key" : "maxTime"}, + {"metric" : "net.connector[$0].processingTime", "key" : "processingTime"} + ], + "queryInfo" : { + "query": "*Catalina:type=GlobalRequestProcessor,*", + "extend" : { + "aliases" : [ + { + "key": "WebModule", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "GlobalRequestProcessor" ] + } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].processingTime", "key" : "processingTime"}, + {"metric" : "net.connector[$0].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$0].requestCount", "key" : "requestCount"} + ], + "queryInfo" : { + "query": "*Catalina:j2eeType=Servlet,*", + "extend" : { + "aliases" : [ + { + "key": "WebModule", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "Servlet" ] + } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].accessCount", "key" : "accessCount"}, + {"metric" : "net.connector[$0].hitCount", "key" : "hitCount"} + ], + "queryInfo" : { + "query": "*Catalina:type=StringCache,*", + "extend" : { + "aliases" : [ + { + "key": "StringCache", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "StringCache" ] + } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].jspCount", "key" : "jspCount"}, + {"metric" : "net.connector[$0].jspReloadCount", "key" : "jspReloadCount"} + ], + "queryInfo" : { + "query": "*Catalina:type=JspMonitor,*", + "extend" : { + "aliases" : [ + { + "key": "WebModule", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "JspMonitor" ] + } + } + ] +} diff --git a/src/test/resources/config/tomcat/example2.json b/src/test/resources/config/tomcat/example2.json new file mode 100644 index 0000000..bf439a6 --- /dev/null +++ b/src/test/resources/config/tomcat/example2.json @@ -0,0 +1,47 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "9840", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"jmx", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + {"metric" : "net.connector[$1].bytesSent", "key" : "bytesSent"}, + {"metric" : "net.connector[$1].bytesReceived", "key" : "bytesReceived"}, + {"metric" : "net.connector[$1].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$1].requestCount", "key" : "requestCount"}, + {"metric" : "net.connector[$1].maxTime", "key" : "maxTime"}, + {"metric" : "net.connector[$1].processingTime", "key" : "processingTime"} + ], + "queryInfo" : { + "query": "*Catalina:j2eeType=GlobalRequestProcessor,*", + "extend" : { + "aliases" : [ + { + "key": "Catalina:type", + "index":1 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "GlobalRequestProcessor" ] + } + } + ] +} diff --git a/src/test/resources/config/tomcat/generate1.json b/src/test/resources/config/tomcat/generate1.json new file mode 100644 index 0000000..dc4e9d1 --- /dev/null +++ b/src/test/resources/config/tomcat/generate1.json @@ -0,0 +1,106 @@ +{ + "id":"5", + "target":{ + "auth":{ + "pw":"tomcat", + "id":"jmxxuser" + }, + "connection":{ + "ip":"192.168.1.204", + "port":"9840", + "portType":"TCP", + "ssl":false + } + }, + "schedule":{ + "interval":"5" + }, + "crawler":{ + "name":"JMX_CRAWLER", + "container":"java_proxy" + }, + "items":[ + { + "keys":[ + { + "metric":"global.request.processing_time[$0]", + "key":"processingTime" + }, + { + "metric":"global.request.max_time[$0]", + "key":"maxTime" + }, + { + "metric":"global.request.request_count[$0]", + "key":"requestCount" + }, + { + "metric":"global.request.error_count[$0]", + "key":"errorCount" + }, + { + "metric":"global.request.bytes_rcvd[$0]", + "key":"bytesReceived" + }, + { + "metric":"global.request.bytes_sent[$0]", + "key":"bytesSent" + } + ], + "queryInfo":{ + "query":"*Catalina:type=GlobalRequestProcessor,*", + "extend":{ + "aliases":[ + { + "key":"Catalina:type", + "index":0 + } + ] + } + }, + "mappingInfo":{ + "parseDirection":null, + "arrayColumns":[ + "GlobalRequestProcessor" + ], + "keyColumns":null, + "valueColumn":null + } + }, + { + "keys":[ + { + "metric":"thread.busy[$0]", + "key":"currentThreadsBusy" + }, + { + "metric":"thread.count[$0]", + "key":"currentThreadCount" + }, + { + "metric":"thread.max[$0]", + "key":"maxThreads" + } + ], + "queryInfo":{ + "query":"*Catalina:type=ThreadPool,*", + "extend":{ + "aliases":[ + { + "key":"Catalina:type", + "index":0 + } + ] + } + }, + "mappingInfo":{ + "parseDirection":null, + "arrayColumns":[ + "ThreadPool" + ], + "keyColumns":null, + "valueColumn":null + } + } + ] +} diff --git a/src/test/resources/config/wmi/example.json b/src/test/resources/config/wmi/example.json new file mode 100644 index 0000000..60351e6 --- /dev/null +++ b/src/test/resources/config/wmi/example.json @@ -0,0 +1,63 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.1", + "port" : "135", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + "id":"administrator", + "pw":"!@#$qwer1234" + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"wmi_crawler", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + {"metric" : "cpu[$0].usage.system", "key":"PercentProcessorTime"}, + {"metric" : "cpu[$0].usage.idle", "key":"PercentIdleTime"}, + {"metric" : "cpu[$0].usage.user", "key":"PercentUserTime"} + ], + "queryInfo" : { + "query": "select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor", + "extend" : { + "nameSpace":"root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo" : { + "parseDirection" : "col", + "arrayColumns" : [ "Name"] + } + } + , + { + "keys" : [ + {"metric" : "cpu.usage.system", "key":"PercentProcessorTime"}, + {"metric" : "cpu.usage.idle", "key":"PercentIdleTime"}, + {"metric" : "cpu.usage.user", "key":"PercentUserTime"} + ], + "queryInfo" : { + "query": "select PercentProcessorTime, PercentIdleTime, PercentUserTime,Name from Win32_PerfFormattedData_PerfOS_Processor where Name='_Total'", + "extend" : { + "nameSpace":"root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo" : { + "parseDirection" : "col", + "arrayColumns" : [ "Name"] + } + } + + ] + +} diff --git a/src/test/resources/config/wmi/meta/meta_cpu.json b/src/test/resources/config/wmi/meta/meta_cpu.json new file mode 100644 index 0000000..74288c6 --- /dev/null +++ b/src/test/resources/config/wmi/meta/meta_cpu.json @@ -0,0 +1,49 @@ +{ + "id": "4", + "schedule": { + "interval": "5" + }, + "items": [{ + "keys": [{ + "metric": "cpu.caption", + "key": "Caption" + }, + { + "metric": "cpu.Manufacturer", + "key": "Manufacturer" + }, + { + "metric": "cpu.MaxClockSpeed", + "key": "MaxClockSpeed" + }, + { + "metric": "cpu.CurrentClockSpeed", + "key": "CurrentClockSpeed" + }, + { + "metric": "cpu.AddressWidth", + "key": "AddressWidth" + }, + { + "metric": "cpu.DataWidth", + "key": "DataWidth" + }, + { + "metric": "cpu.Architecture", + "key": "Architecture" + }], + "queryInfo": { + "query": "SELECT Caption, Manufacturer, MaxClockSpeed, CurrentClockSpeed, AddressWidth, DataWidth, Architecture from Win32_Processor ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/test/resources/config/wmi/meta/meta_filesystem.json b/src/test/resources/config/wmi/meta/meta_filesystem.json new file mode 100644 index 0000000..11dbf76 --- /dev/null +++ b/src/test/resources/config/wmi/meta/meta_filesystem.json @@ -0,0 +1,61 @@ +{ + "id": "4", + "target": { + "auth": { + "pw": "dbseogns18", + "id": "administrator" + }, + "connection": { + "ip": "192.168.1.106", + "port": "135", + "portType": "tcp", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "WMI_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "filesystem[$0].InterfaceType", + "key": "InterfaceType" + }, + { + "metric": "filesystem[$0].Status", + "key": "Status" + }, + { + "metric": "filesystem[$0].Manufacturer", + "key": "Manufacturer" + }, + { + "metric": "filesystem[$0].Model", + "key": "Model" + }, + { + "metric": "filesystem[$0].MediaType", + "key": "MediaType" + }, + { + "metric": "filesystem[$0].Size", + "key": "Size" + }], + "queryInfo": { + "query": "SELECT InterfaceType, Status, Manufacturer, Model, MediaType, Size from Win32_DiskDrive ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": ["Model"], + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/test/resources/config/wmi/meta/meta_memory.json b/src/test/resources/config/wmi/meta/meta_memory.json new file mode 100644 index 0000000..a3f111a --- /dev/null +++ b/src/test/resources/config/wmi/meta/meta_memory.json @@ -0,0 +1,53 @@ +{ + "id": "4", + "target": { + "auth": { + "pw": "dbseogns18", + "id": "administrator" + }, + "connection": { + "ip": "192.168.1.106", + "port": "135", + "portType": "tcp", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "WMI_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "memory.BankLabel", + "key": "BankLabel" + }, + { + "metric": "memory.Capacity", + "key": "Capacity" + }, + { + "metric": "memory.MemoryType", + "key": "MemoryType" + }, + { + "metric": "memory.DataWidth", + "key": "DataWidth" + }], + "queryInfo": { + "query": "SELECT BankLabel, Capacity, MemoryType, DataWidth from Win32_PhysicalMemory ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/test/resources/config/wmi/meta/meta_network.json b/src/test/resources/config/wmi/meta/meta_network.json new file mode 100644 index 0000000..1c08a00 --- /dev/null +++ b/src/test/resources/config/wmi/meta/meta_network.json @@ -0,0 +1,53 @@ +{ + "id": "4", + "target": { + "auth": { + "pw": "dbseogns18", + "id": "administrator" + }, + "connection": { + "ip": "192.168.1.106", + "port": "135", + "portType": "tcp", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "WMI_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "network[$0].MACAddress", + "key": "MACAddress" + }, + { + "metric": "network[$0].AdapterType", + "key": "AdapterType" + }, + { + "metric": "network[$0].Manufacturer", + "key": "Manufacturer" + }, + { + "metric": "network[$0].Description", + "key": "Description" + }], + "queryInfo": { + "query": "SELECT MACAddress, AdapterType, Manufacturer, Description, NetConnectionID from Win32_NetworkAdapter WHERE PhysicalAdapter='TRUE'", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": ["NetConnectionID"], + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/test/resources/config/wmi/test.json b/src/test/resources/config/wmi/test.json new file mode 100644 index 0000000..00c66ef --- /dev/null +++ b/src/test/resources/config/wmi/test.json @@ -0,0 +1,130 @@ +{ + "id": "4", + "target": { + "auth": { + "pw": "dbseogns18", + "id": "administrator" + }, + "connection": { + "ip": "192.168.1.106", + "port": "135", + "portType": "tcp", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "WMI_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "cpu.usage.total.privilege", + "key": "PercentPrivilegedTime" + }, + { + "metric": "cpu.usage.total.user", + "key": "PercentUserTime" + }, + { + "metric": "cpu.usage.total.processor", + "key": "PercentProcessorTime" + }, + { + "metric": "cpu.usage.total.idle", + "key": "PercentIdleTime" + }], + "queryInfo": { + "query": "SELECT PercentPrivilegedTime, PercentUserTime, PercentProcessorTime, PercentIdleTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name='_Total'", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }, + { + "keys": [{ + "metric": "disk.usage.free[$0]", + "key": "FreeSpace" + }, + { + "metric": "disk.usage.total[$0]", + "key": "Size" + }], + "queryInfo": { + "query": "SELECT FreeSpace, Size, Caption FROM Win32_LogicalDisk", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": ["Caption"], + "keyColumns": null, + "valueColumn": null + } + }, + { + "keys": [{ + "metric": "mem.usage.free.paging", + "key": "FreeSpaceInPagingFiles" + }], + "queryInfo": { + "query": "SELECT FreeSpaceInPagingFiles FROM Win32_OperatingSystem ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }, + { + "keys": [{ + "metric": "mem.usage.free.physical", + "key": "FreePhysicalMemory" + }, + { + "metric": "mem.usage.free.virtual", + "key": "FreeVirtualMemory" + }, + { + "metric": "mem.usage.total.paging", + "key": "SizeStoredInPagingFiles" + }, + { + "metric": "mem.usage.total.physical", + "key": "TotalVisibleMemorySize" + }, + { + "metric": "mem.usage.total.virtual", + "key": "TotalVirtualMemorySize" + }], + "queryInfo": { + "query": "SELECT FreePhysicalMemory, FreeVirtualMemory, SizeStoredInPagingFiles, TotalVisibleMemorySize, TotalVirtualMemorySize FROM Win32_OperatingSystem", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }] +}