diff --git a/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_11.xml b/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_2_3.xml similarity index 59% rename from .idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_11.xml rename to .idea/libraries/Maven__ch_qos_logback_logback_classic_1_2_3.xml index c6ea67e..6fec8f4 100644 --- a/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_11.xml +++ b/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_2_3.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_11.xml b/.idea/libraries/Maven__ch_qos_logback_logback_core_1_2_3.xml similarity index 61% rename from .idea/libraries/Maven__ch_qos_logback_logback_core_1_1_11.xml rename to .idea/libraries/Maven__ch_qos_logback_logback_core_1_2_3.xml index f538e36..9eb8596 100644 --- a/.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_11.xml +++ b/.idea/libraries/Maven__ch_qos_logback_logback_core_1_2_3.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_hynnet_jacob_1_18.xml b/.idea/libraries/Maven__com_hynnet_jacob_1_18.xml new file mode 100644 index 0000000..1362ca2 --- /dev/null +++ b/.idea/libraries/Maven__com_hynnet_jacob_1_18.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml b/.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml deleted file mode 100644 index 578b079..0000000 --- a/.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__com_microsoft_sqlserver_mssql_jdbc_6_2_2_jre8.xml b/.idea/libraries/Maven__com_microsoft_sqlserver_mssql_jdbc_6_2_2_jre8.xml new file mode 100644 index 0000000..c205dec --- /dev/null +++ b/.idea/libraries/Maven__com_microsoft_sqlserver_mssql_jdbc_6_2_2_jre8.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml b/.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml deleted file mode 100644 index b8581a6..0000000 --- a/.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__log4j_log4j_1_2_14.xml b/.idea/libraries/Maven__log4j_log4j_1_2_14.xml new file mode 100644 index 0000000..2825a67 --- /dev/null +++ b/.idea/libraries/Maven__log4j_log4j_1_2_14.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__mysql_mysql_connector_java_6_0_6.xml b/.idea/libraries/Maven__mysql_mysql_connector_java_6_0_6.xml new file mode 100644 index 0000000..10e7222 --- /dev/null +++ b/.idea/libraries/Maven__mysql_mysql_connector_java_6_0_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml b/.idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml deleted file mode 100644 index 88d626e..0000000 --- a/.idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml b/.idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml deleted file mode 100644 index 6c692c8..0000000 --- a/.idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_4_2.xml b/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_4_2.xml new file mode 100644 index 0000000..2970b5e --- /dev/null +++ b/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_4_2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml b/.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml deleted file mode 100644 index 58bdc9a..0000000 --- a/.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml deleted file mode 100644 index 78dbe45..0000000 --- a/.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml b/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml deleted file mode 100644 index a523703..0000000 --- a/.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mongodb_mongo_java_driver_3_6_0.xml b/.idea/libraries/Maven__org_mongodb_mongo_java_driver_3_6_0.xml new file mode 100644 index 0000000..7935f5c --- /dev/null +++ b/.idea/libraries/Maven__org_mongodb_mongo_java_driver_3_6_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml b/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml deleted file mode 100644 index 7ab319b..0000000 --- a/.idea/libraries/Maven__org_objenesis_objenesis_2_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml b/.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml deleted file mode 100644 index da69f6c..0000000 --- a/.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_postgresql_postgresql_42_1_4.xml b/.idea/libraries/Maven__org_postgresql_postgresql_42_1_4.xml new file mode 100644 index 0000000..9e59f23 --- /dev/null +++ b/.idea/libraries/Maven__org_postgresql_postgresql_42_1_4.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml b/.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml deleted file mode 100644 index f86d2c8..0000000 --- a/.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml deleted file mode 100644 index bae9949..0000000 --- a/.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml deleted file mode 100644 index 6073e53..0000000 --- a/.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_7_25.xml deleted file mode 100644 index a14ac63..0000000 --- a/.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_7_25.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_snmp4j_snmp4j_2_5_8.xml b/.idea/libraries/Maven__org_snmp4j_snmp4j_2_5_8.xml new file mode 100644 index 0000000..6db16f5 --- /dev/null +++ b/.idea/libraries/Maven__org_snmp4j_snmp4j_2_5_8.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_1_5_9_RELEASE.xml deleted file mode 100644 index 44dc419..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_9_RELEASE.xml deleted file mode 100644 index 4c3a2b7..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_5_9_RELEASE.xml deleted file mode 100644 index c6ba5e1..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_1_5_9_RELEASE.xml deleted file mode 100644 index 33c0b1c..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml deleted file mode 100644 index d7db397..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml deleted file mode 100644 index 9312efe..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml b/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml deleted file mode 100644 index 07d7bca..0000000 --- a/.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_9_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_aop_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_aop_4_3_13_RELEASE.xml deleted file mode 100644 index e06e71e..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_aop_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_beans_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_beans_4_3_13_RELEASE.xml deleted file mode 100644 index 0a8cafe..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_beans_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_context_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_context_4_3_13_RELEASE.xml deleted file mode 100644 index 8050852..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_context_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_core_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_core_4_3_13_RELEASE.xml deleted file mode 100644 index b95dd78..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_core_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_expression_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_expression_4_3_13_RELEASE.xml deleted file mode 100644 index 7a825ff..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_expression_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml b/.idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml deleted file mode 100644 index 0c0fcbf..0000000 --- a/.idea/libraries/Maven__org_springframework_spring_test_4_3_13_RELEASE.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml b/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml deleted file mode 100644 index 20e2920..0000000 --- a/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml b/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml new file mode 100644 index 0000000..77144ff --- /dev/null +++ b/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/jacob-1.18-x64.dll b/lib/jacob-1.18-x64.dll new file mode 100644 index 0000000..b09c633 Binary files /dev/null and b/lib/jacob-1.18-x64.dll differ diff --git a/lib/jacob-1.18-x86.dll b/lib/jacob-1.18-x86.dll new file mode 100644 index 0000000..a53cc77 Binary files /dev/null and b/lib/jacob-1.18-x86.dll differ diff --git a/overflow_probe_container_general.iml b/overflow_probe_container_general.iml index cc93fd1..e85028a 100644 --- a/overflow_probe_container_general.iml +++ b/overflow_probe_container_general.iml @@ -16,37 +16,19 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - - + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 83ead1b..1f4dd57 100644 --- a/pom.xml +++ b/pom.xml @@ -5,9 +5,8 @@ com.loafle - maven_parent_spring_boot - 1.5.9-RELEASE - + maven_parent_jar + 1.0.0-RELEASE com.loafle.overflow @@ -21,6 +20,18 @@ 4.1.17.Final 2.9.2 + + 6.0.6 + 42.1.4 + 6.2.2.jre8 + + 1.18 + + 2.9.0 + + 3.6.0 + + 2.5.8 @@ -40,6 +51,52 @@ ${jackson.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} + \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/probe/container/Application.java b/src/main/java/com/loafle/overflow/probe/container/Application.java deleted file mode 100644 index 1763122..0000000 --- a/src/main/java/com/loafle/overflow/probe/container/Application.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.loafle.overflow.probe.container; - -import com.loafle.overflow.probe.container.server.ContainerServer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.Banner; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application implements CommandLineRunner { - @Autowired - private ContainerServer containerServer; - - @Override - public void run(String... strings) throws Exception { - containerServer.start(); - } - - public static void main(String[] args) { - SpringApplication app = new SpringApplication(Application.class); - app.setBannerMode(Banner.Mode.OFF); - app.run(args); - } -} diff --git a/src/main/java/com/loafle/overflow/probe/container/Container.java b/src/main/java/com/loafle/overflow/probe/container/Container.java new file mode 100644 index 0000000..2d40adb --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/Container.java @@ -0,0 +1,12 @@ +package com.loafle.overflow.probe.container; + +import com.loafle.overflow.probe.container.server.ContainerServer; + +public class Container { + + public static void main(String[] args) throws Exception { + ContainerServer server = new ContainerServer(); + + server.start(); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/Crawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/Crawler.java new file mode 100644 index 0000000..b26faf9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/Crawler.java @@ -0,0 +1,60 @@ +package com.loafle.overflow.probe.container.crawler; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public abstract class Crawler { + protected ObjectMapper objectMapper; + private Map configs; + private String configPath; + + protected Crawler() { + objectMapper = new ObjectMapper(); + } + + public Config getConfig(String id) throws Exception { + return configs.get(id); + } + + public void putConfig(String id, Config config) throws Exception { + if (configs == null) { + configs = new HashMap<>(); + } + configs.put(id, config); + } + + public boolean add(Config config) throws Exception { + this.putConfig(config.getId(), config); + return true; + } + + public List get(String id) throws Exception { + + List rsList = (List)getInternal(getConfig(id)); + + return rsList; + } + + public boolean init(Config config) throws Exception { + add(config); + return true; + } + + public boolean remove(String id) throws Exception { + this.configs.remove(id); + return true; + } + + public abstract String name(); + public abstract List getInternal(Config c) throws Exception; + + public Object getInternalMeta(Config c) throws Exception { + return null; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/Config.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Config.java new file mode 100644 index 0000000..0caa4a6 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Config.java @@ -0,0 +1,53 @@ +package com.loafle.overflow.probe.container.crawler.config; + +import java.util.List; + +public class Config { + + private String id; + private Target target; + private Schedule schedule; + private Crawler crawler; + private List items; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Target getTarget() { + return target; + } + + public void setTarget(Target target) { + this.target = target; + } + + public Schedule getSchedule() { + return schedule; + } + + public void setSchedule(Schedule schedule) { + this.schedule = schedule; + } + + public Crawler getCrawler() { + return crawler; + } + + public void setCrawler(Crawler crawler) { + this.crawler = crawler; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/Connection.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Connection.java new file mode 100644 index 0000000..8d1a13b --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Connection.java @@ -0,0 +1,41 @@ +package com.loafle.overflow.probe.container.crawler.config; + +public class Connection { + private String ip; + private String port; + private String portType; + private boolean ssl; + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getPortType() { + return portType; + } + + public void setPortType(String portType) { + this.portType = portType; + } + + public boolean isSsl() { + return ssl; + } + + public void setSsl(boolean ssl) { + this.ssl = ssl; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/Crawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Crawler.java new file mode 100644 index 0000000..645f63d --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Crawler.java @@ -0,0 +1,22 @@ +package com.loafle.overflow.probe.container.crawler.config; + +public class Crawler { + private String name; + private String container; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getContainer() { + return container; + } + + public void setContainer(String container) { + this.container = container; + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/Item.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Item.java new file mode 100644 index 0000000..2ea58b0 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Item.java @@ -0,0 +1,35 @@ +package com.loafle.overflow.probe.container.crawler.config; + +import java.util.List; + +public class Item { + + private List keys; + private QueryInfo queryInfo; + private MappingInfo mappingInfo; + + public List getKeys() { + return keys; + } + + public void setKeys(List keys) { + this.keys = keys; + } + + public QueryInfo getQueryInfo() { + return queryInfo; + } + + public void setQueryInfo(QueryInfo queryInfo) { + this.queryInfo = queryInfo; + } + + public MappingInfo getMappingInfo() { + return mappingInfo; + } + + public void setMappingInfo(MappingInfo mappingInfo) { + this.mappingInfo = mappingInfo; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/Keys.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Keys.java new file mode 100644 index 0000000..f42b0a9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Keys.java @@ -0,0 +1,24 @@ +package com.loafle.overflow.probe.container.crawler.config; + +public class Keys { + + private String metric; + private String key; + + public String getMetric() { + return metric; + } + + public void setMetric(String metric) { + this.metric = metric; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/MappingInfo.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/MappingInfo.java new file mode 100644 index 0000000..faff14d --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/MappingInfo.java @@ -0,0 +1,44 @@ +package com.loafle.overflow.probe.container.crawler.config; + +import java.util.List; + +public class MappingInfo { + + private String parseDirection; + private List arrayColumns; + private List keyColumns; + private String valueColumn; + + public String getParseDirection() { + return parseDirection; + } + + public void setParseDirection(String parseDirection) { + this.parseDirection = parseDirection; + } + + public List getArrayColumns() { + return arrayColumns; + } + + public void setArrayColumns(List arrayColumns) { + this.arrayColumns = arrayColumns; + } + + public List getKeyColumns() { + return keyColumns; + } + + public void setKeyColumns(List keyColumns) { + this.keyColumns = keyColumns; + } + + public String getValueColumn() { + return valueColumn; + } + + public void setValueColumn(String valueColumn) { + this.valueColumn = valueColumn; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/QueryInfo.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/QueryInfo.java new file mode 100644 index 0000000..5ebda72 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/QueryInfo.java @@ -0,0 +1,25 @@ +package com.loafle.overflow.probe.container.crawler.config; + +import java.util.Map; + +public class QueryInfo { + private String query; + private Map extend; + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public Map getExtend() { + return extend; + } + + public void setExtend(Map extend) { + this.extend = extend; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/Schedule.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Schedule.java new file mode 100644 index 0000000..96f1587 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Schedule.java @@ -0,0 +1,14 @@ +package com.loafle.overflow.probe.container.crawler.config; + +public class Schedule { + private String interval; + + public String getInterval() { + return interval; + } + + public void setInterval(String interval) { + this.interval = interval; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/config/Target.java b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Target.java new file mode 100644 index 0000000..a03199a --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/config/Target.java @@ -0,0 +1,25 @@ +package com.loafle.overflow.probe.container.crawler.config; + +import java.util.Map; + +public class Target { + private Map auth; + private Connection connection; + + public Map getAuth() { + return auth; + } + + public void setAuth(Map auth) { + this.auth = auth; + } + + public Connection getConnection() { + return connection; + } + + public void setConnection(Connection connection) { + this.connection = connection; + } +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseCrawler.java new file mode 100644 index 0000000..b34fbb3 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseCrawler.java @@ -0,0 +1,78 @@ +package com.loafle.overflow.probe.container.crawler.impl.database; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import com.loafle.overflow.probe.container.crawler.result.ResultSetRow; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public abstract class DatabaseCrawler extends Crawler { + + public DatabaseCrawler() { + } + + @Override + public List getInternal(Config config) throws Exception { + return getMetrics(config); + } + + private List getMetrics(Config config) throws Exception { + + Connection conn = null; + Statement stmt = null; + java.sql.ResultSet rs = null; + + String url = (String)config.getTarget().getAuth().get("url"); + String id = (String)config.getTarget().getAuth().get("id"); + String pw = (String)config.getTarget().getAuth().get("pw"); + + loadDriverClass(); + + List resultSets = new ArrayList<>(); + + try { + conn = java.sql.DriverManager.getConnection(url, id, pw); + stmt = conn.createStatement(); + + for (Item item : config.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); + } + + resultSets.add(resultSet); + rs.close(); + } + return resultSets; + + } catch (Exception e) { + throw 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/probe/container/crawler/impl/database/DatabaseMetaInfo.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseMetaInfo.java new file mode 100644 index 0000000..4e3d8f0 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseMetaInfo.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.probe.container.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/probe/container/crawler/impl/database/mysql/MySQLCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/mysql/MySQLCrawler.java new file mode 100644 index 0000000..0d5f5c5 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/mysql/MySQLCrawler.java @@ -0,0 +1,13 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.mysql; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawler; + +public class MySQLCrawler extends DatabaseCrawler { + public String name() { + return "MYSQL_CRAWLER"; + } + + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("com.mysql.cj.jdbc.Driver"); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/oracle/OracleCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/oracle/OracleCrawler.java new file mode 100644 index 0000000..8ac3aaf --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/oracle/OracleCrawler.java @@ -0,0 +1,14 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.oracle; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawler; + +public class OracleCrawler extends DatabaseCrawler { + public String name() { + return "ORACLE_CRAWLER"; + } + + @Override + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("oracle.jdbc.driver.OracleDriver"); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/postgresql/PostgreSQLCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/postgresql/PostgreSQLCrawler.java new file mode 100644 index 0000000..9271808 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/postgresql/PostgreSQLCrawler.java @@ -0,0 +1,13 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.postgresql; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawler; + +public class PostgreSQLCrawler extends DatabaseCrawler { + public String name() { + return "POSTGRESQL_CRAWLER"; + } + + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("org.postgresql.Driver"); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/sqlserver/SQLServerCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/sqlserver/SQLServerCrawler.java new file mode 100644 index 0000000..6609031 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/database/sqlserver/SQLServerCrawler.java @@ -0,0 +1,13 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.sqlserver; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawler; + +public class SQLServerCrawler extends DatabaseCrawler { + public String name() { + return "SQLSERVER_CRAWLER"; + } + + protected void loadDriverClass() throws ClassNotFoundException { + Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/jmx/JMXCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/jmx/JMXCrawler.java new file mode 100644 index 0000000..a5ad30e --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/jmx/JMXCrawler.java @@ -0,0 +1,190 @@ +package com.loafle.overflow.probe.container.crawler.impl.jmx; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +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 extends Crawler { + private static final Logger logger = Logger.getLogger(JMXCrawler.class.getName()); + + private String jmxUrl; + private String username; + private String password; + private boolean ssl; + + public JMXCrawler() {} + + public String name() { + return "JMX_CRAWLER"; + } + + 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; + } + + @Override + public List getInternal(Config config) throws Exception { + + String hostIp = config.getTarget().getConnection().getIp(); + String port = config.getTarget().getConnection().getPort(); + + this.jmxUrl = "service:jmx:rmi:///jndi/rmi://" + hostIp + ":" +port + "/jmxrmi"; + this.username = (String) config.getTarget().getAuth().get("id"); + this.password = (String) config.getTarget().getAuth().get("pw"); + + // connection + MBeanServerConnection beanCon; + JMXConnector jmxconn = null; + try { + + + Map environment = getAuthority(); + jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(this.jmxUrl), environment); + beanCon = jmxconn.getMBeanServerConnection(); + + List resultSetList = new ArrayList<>(); + List objectNames = new LinkedList(); + objectNames.add(null); + ObjectName on = null; + + for (Item item : config.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())); + } + + resultSetList.add(resultSet); + } + + return resultSetList; + } catch(Exception e) { + e.printStackTrace(); + throw e; + } finally { + if (jmxconn != null) { + jmxconn.close(); + } + } + } + + 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() { + + Map environment = new HashMap(); + + if (this.username != null && this.username.length() != 0 && this.password != null && this.password.length() != 0) { + String[] credent = new String[] {this.username, this.password}; + environment.put(JMXConnector.CREDENTIALS, credent); + } + + if (this.ssl) { + 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/probe/container/crawler/impl/mongodb/MongoDBCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/mongodb/MongoDBCrawler.java new file mode 100644 index 0000000..8b56ab1 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/mongodb/MongoDBCrawler.java @@ -0,0 +1,88 @@ +package com.loafle.overflow.probe.container.crawler.impl.mongodb; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +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.List; +import java.util.Map; + +public class MongoDBCrawler extends Crawler { + public String name() { + return "MONGODB_CRAWLER"; + } + + public List collectMetric(Config c) throws Exception { + + MongoClient mongoClient = null; +// Map returnMap = new HashMap(); + + String dataBaseName = null; + String statusCommand = null; + + String targetIP = c.getTarget().getConnection().getIp(); + short targetPort = Short.parseShort(c.getTarget().getConnection().getPort()); + List ofResultSets = null; + try { + + mongoClient = new MongoClient(new ServerAddress(targetIP, targetPort), + MongoClientOptions.builder() + .serverSelectionTimeout(1000) + .connectTimeout(1000) + .socketTimeout(1000).build() + ); + + ofResultSets = new ArrayList<>(); + ResultSet ofResultSet = null; + List items = c.getItems(); + List row = null; + for (Item item : items) { + + ofResultSet = ResultSet.newInstance(item); + Map metaMap = ofResultSet.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()))); + } + + ofResultSet.addRow(row); + ofResultSets.add(ofResultSet); + + } + }catch (Exception e) { + throw e; + }finally { + if (mongoClient != null) { + mongoClient.close(); + } + } + return ofResultSets; + } + + @Override + public List getInternal(Config config) throws Exception { + return this.collectMetric(config); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/redis/RedisCralwer.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/redis/RedisCralwer.java new file mode 100644 index 0000000..5523b61 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/redis/RedisCralwer.java @@ -0,0 +1,110 @@ +package com.loafle.overflow.probe.container.crawler.impl.redis; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import redis.clients.jedis.Jedis; + +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class RedisCralwer extends Crawler { + + private static final Logger LOGGER = Logger.getLogger(RedisCralwer.class.getName()); + + public RedisCralwer() { + + } + + public String name() { + return "REDIS_CRAWLER"; + } + + @Override + public List getInternal(Config c) throws Exception { + LOGGER.log(Level.INFO ,"getInternal call"); + return collectMetric(c); + } + + protected List collectMetric(Config c) { + + String targetIP = c.getTarget().getConnection().getIp(); + int targetPort = Integer.valueOf(c.getTarget().getConnection().getPort()); + + String authpw = (String)c.getTarget().getAuth().get("authpw"); + + Jedis jedis = null; + List items = c.getItems(); + + try { + jedis = new Jedis(targetIP, targetPort,false); + if (authpw != null && !authpw.equals("")) { + String code = jedis.auth(authpw); + if (!code.equals("")) { + // set error auth + } + } + + List resultSetList = new ArrayList<>(); + 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())); + resultSetList.add(resultSet); + } + + return resultSetList; + } catch (Exception e) { + throw 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/probe/container/crawler/impl/snmp/SNMPCrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/snmp/SNMPCrawler.java new file mode 100644 index 0000000..e1cc279 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/snmp/SNMPCrawler.java @@ -0,0 +1,309 @@ +package com.loafle.overflow.probe.container.crawler.impl.snmp; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Connection; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.impl.snmp.version.SNMPv2c; +import com.loafle.overflow.probe.container.crawler.impl.snmp.version.SNMPv3; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +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.List; +import java.util.Map; + +public class SNMPCrawler extends Crawler { + public String name() { + return "SNMP_CRAWLER"; + } + + @Override + public List getInternal(Config config) { + + +// String targetVer = (String)config.getTarget().getAuth().get("version"); +// switch (targetVer) { +// case "v2c": +// retObj = getByV2c(config); +// break; +// case "v3": +// retObj = getByV3(config); +// break; +// default: +// new Exception("Unknown SNMP protocol : " + targetVer).printStackTrace(); +// } + + return getSNMP(config); + } + + private List getSNMP(Config config) { + + Snmp snmp = null; + TransportMapping transport = null; + + List rslist = null; + + try { + transport = new DefaultUdpTransportMapping(); + snmp = new Snmp(transport); + transport.listen(); + + rslist = new ArrayList<>(); + + List items = config.getItems(); + String[] oids = null; + + Map snmpResultMap = null; + for (Item item : items) { + oids = new String[item.getKeys().size()]; + for (int i=0; i getSNMPV(Snmp snmp, Config config, String[] oids) throws Exception { + + String targetVer = (String)config.getTarget().getAuth().get("version"); + switch (targetVer) { + case "v2c": + return getV2c(snmp, config, oids); + case "v3": + return getV3(snmp, config, oids); + default: + new Exception("Unknown SNMP protocol : " + targetVer).printStackTrace(); + } + + + return null; + } + + private Map getV2c(Snmp snmp, Config config, String[] oids) throws Exception { + + SNMPv2c snmpV2 = new SNMPv2c(snmp); + + Map authInfo = config.getTarget().getAuth(); + Connection connInfo = config.getTarget().getConnection(); + + String ip = connInfo.getIp(); + String port = connInfo.getPort(); + String community = (String)authInfo.get("community"); + + return snmpV2.get(ip, port, community, oids); + } + + private Map getV3(Snmp snmp, Config config, String[] oids) throws Exception { + SNMPv3 snmpV3 = new SNMPv3(snmp); + + Map authInfo = config.getTarget().getAuth(); + Connection connInfo = config.getTarget().getConnection(); + + String ip = connInfo.getIp(); + String port = connInfo.getPort(); +// String method = config.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; + } +// +// private List getByV2c(Config config) { +// Snmp snmp = null; +// TransportMapping transport = null; +// +// List rslist = null; +// +// try { +// transport = new DefaultUdpTransportMapping(); +// snmp = new Snmp(transport); +// transport.listen(); +// SNMPv2c snmpV2 = new SNMPv2c(snmp); +// +// rslist = new ArrayList<>(); +// +// Map authInfo = config.getTarget().getAuth(); +// Connection connInfo = config.getTarget().getConnection(); +// +// String ip = connInfo.getIp(); +// String port = connInfo.getPort(); +// String community = (String)authInfo.get("community"); +// +// List items = config.getItems(); +// String[] oids = null; +// for (Item item : items) { +// oids = new String[item.getKeys().size()]; +//// List queries = item.getQueries(); +// for (int i=0; i transport = null; +// +// List rslist = null; +// +// try { +// transport = new DefaultUdpTransportMapping(); +// snmp = new Snmp(transport); +// transport.listen(); +// SNMPv3 snmpV3 = new SNMPv3(snmp); +// +// rslist = new ArrayList<>(); +// +// Map authInfo = config.getTarget().getAuth(); +// Connection connInfo = config.getTarget().getConnection(); +// +// String ip = connInfo.getIp(); +// String port = connInfo.getPort(); +//// String method = config.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"); +// +// List items = config.getItems(); +// String[] oids = null; +// for (Item item : items) { +// oids = new String[item.getKeys().size()]; +//// List queries = item.getQueries(); +// for (int i=0; i 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/probe/container/crawler/impl/snmp/version/SNMPv2c.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/snmp/version/SNMPv2c.java new file mode 100644 index 0000000..08f07a5 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/snmp/version/SNMPv2c.java @@ -0,0 +1,63 @@ +package com.loafle.overflow.probe.container.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, String 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, String 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, String 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, String 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/probe/container/crawler/impl/snmp/version/SNMPv3.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/snmp/version/SNMPv3.java new file mode 100644 index 0000000..67b0adc --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/snmp/version/SNMPv3.java @@ -0,0 +1,148 @@ +package com.loafle.overflow.probe.container.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, String 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, String 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, String 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, String 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/probe/container/crawler/impl/wmi/WMICrawler.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawler.java new file mode 100644 index 0000000..36b09b8 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawler.java @@ -0,0 +1,74 @@ +package com.loafle.overflow.probe.container.crawler.impl.wmi; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +public class WMICrawler extends Crawler { + public String name() { + return "WMI_CRAWLER"; + } + + @Override + public List getInternal(Config config) throws Exception { + + return WMICrawlerOS.getInstance().process(config); + } + + @Override + public Object getInternalMeta(Config c) throws Exception { + + List metaConfigList = loadMetaConfig(); + + + List retlist = new ArrayList<>(); + WMICrawlerOS os = WMICrawlerOS.getInstance(); + ResultSet ofResultSet = null; + for(Config metaConfig : metaConfigList) { + + for(int indexI = 0; indexI < metaConfig.getItems().size(); ++indexI) { + ofResultSet = os.processWMI(c, metaConfig.getItems().get(indexI)); + if(ofResultSet != null) { + retlist.add(ofResultSet); + } + } + } + + return null; + } + + + private List loadMetaConfig() throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + + URL url = classLoader.getResource("config/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<>(); + Config metaConfig = null; + for(String fi : metaFiles) { + if(fi.indexOf("meta_") > -1) { + metaConfig = objectMapper.readValue(new File(path+"/"+fi), Config.class); + if(metaConfig != null) { + retList.add(metaConfig); + } + } + } + + return retList; + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerLinux.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerLinux.java new file mode 100644 index 0000000..92262e9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerLinux.java @@ -0,0 +1,153 @@ +package com.loafle.overflow.probe.container.crawler.impl.wmi; + +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +import java.util.*; + +public class WMICrawlerLinux extends WMICrawlerOS { + + private final String DELIMITER = "||"; + private final String DELIMITER_SPLIT = "\\|\\|"; + + public ResultSet processWMI(Config config, Item item) throws Exception { + + List argList = createCommand(config, item); + + String result = execute(argList.toArray(new String[argList.size()])); + + ResultSet ofResultSet = parseResult(result, item); + + return ofResultSet; + } + + public List createCommand(Config config, Item item) throws Exception { + + String id = (String)config.getTarget().getAuth().get("id"); + String pw = (String)config.getTarget().getAuth().get("pw"); + String nameSpace = (String)item.getQueryInfo().getExtend().get("nameSpace"); + String ip = config.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/probe/container/crawler/impl/wmi/WMICrawlerOS.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerOS.java new file mode 100644 index 0000000..540457e --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerOS.java @@ -0,0 +1,47 @@ +package com.loafle.overflow.probe.container.crawler.impl.wmi; + +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +import java.util.ArrayList; +import java.util.List; + +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 List process(Config config) throws Exception { + + List retlist = new ArrayList<>(); + ResultSet ofResultSet = null; + for(int cIndexI = 0 ; cIndexI < config.getItems().size() ; ++cIndexI) { + + ofResultSet = processWMI(config, config.getItems().get(cIndexI)); + retlist.add(ofResultSet); + } + + + return retlist; + } + + public abstract ResultSet processWMI(Config config, Item item) throws Exception ; +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerWindows.java b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerWindows.java new file mode 100644 index 0000000..5e63bce --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerWindows.java @@ -0,0 +1,254 @@ +package com.loafle.overflow.probe.container.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.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class WMICrawlerWindows extends WMICrawlerOS { + + public ResultSet processWMI(Config config, Item item) throws Exception { + + String query = ""; + ActiveXComponent wmiconnect = null; + ResultSet ofResultSet = null; + + + query = item.getQueryInfo().getQuery(); + wmiconnect = connectServer(config, 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(Config config, Item item) { + + String id = (String)config.getTarget().getAuth().get("id"); + String pw = (String)config.getTarget().getAuth().get("pw"); + String nameSpace = (String)item.getQueryInfo().getExtend().get("nameSpace"); +// String query = (String)config.get.get("query"); + + String ip = config.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/probe/container/crawler/result/ResultSet.java b/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSet.java new file mode 100644 index 0000000..5b2a0a9 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSet.java @@ -0,0 +1,75 @@ +package com.loafle.overflow.probe.container.crawler.result; + +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.config.MappingInfo; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public abstract class ResultSet { + // properties + protected Item item; + protected List> rows; + protected Map meta = null; + + public Map getMeta() { + return meta; + } + + public void setMeta(Map meta) { + this.meta = meta; + } + + public List> getRows() { + return rows; + } + + public void setRows(List> rows) { + this.rows = rows; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } + + // methods + static public ResultSet newInstance(Item item) { + if (item.getMappingInfo() == null) { + item.setMappingInfo(new MappingInfo()); + } + String type = (String) item.getMappingInfo().getParseDirection(); + if (type != null && type.equals("row")) { + return new ResultSetRow(item); + } else { + return new ResultSetCol(item); + } + } + + + public ResultSet(Item item) { + this.item = item; + this.rows = new ArrayList<>(); + this.setMeta(); + } + + public void addRow(List row) { + rows.add(row); + } + + + public Map getData() { + return parse(); + } + + // abstracts + public abstract void setMeta(); + public abstract Map parse(); + + +} + diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSetCol.java b/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSetCol.java new file mode 100644 index 0000000..343c146 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSetCol.java @@ -0,0 +1,106 @@ +package com.loafle.overflow.probe.container.crawler.result; + +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.config.Keys; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ResultSetCol extends ResultSet{ + + public ResultSetCol(Item item) { + super(item); + } + + public void setMeta() { + + List meta = this.item.getKeys(); + List arrayColumns = this.item.getMappingInfo().getArrayColumns(); + + if(this.meta == null) { + this.meta = new HashMap<>(); + } + + for(int indexI = 0; indexI < meta.size(); ++indexI) { + this.meta.put(meta.get(indexI).getKey(), indexI); + } + + if( arrayColumns != null) { + for( int indexI = 0 ; indexI < arrayColumns.size(); ++indexI) { + if(this.meta.containsKey(arrayColumns.get(indexI))) { + continue; + } + this.meta.put(arrayColumns.get(indexI), indexI+ meta.size()); + } + } + + + + } + + public Map parse() { + + List metrics = this.item.getKeys(); + List arrayColumns = this.item.getMappingInfo().getArrayColumns(); + + Map resultMap = new HashMap<>(); + + List row = null; + + String metric = null; + List arrayValue = new ArrayList<>(); + + + int columnIdx = 0; + + for(int indexI = 0; indexI < this.rows.size(); ++indexI) { + + row = this.rows.get(indexI); + for (int indexJ= 0; indexJ < row.size(); ++indexJ) { + + arrayValue.clear(); + + if(arrayColumns != null ) { + for(int indexL =0; indexL < arrayColumns.size(); ++indexL) { + columnIdx = this.meta.get(arrayColumns.get(indexL)); + + arrayValue.add(row.get(columnIdx)); + } + } + + for(int indexK = 0 ; indexK < metrics.size(); ++indexK) { + metric = metrics.get(indexK).getMetric(); + metric = convertMetric(metric, arrayValue); + resultMap.put(metric, row.get(indexK)); + } + + } + + } + + return resultMap; + + } + + private String convertMetric(String metric, List arrayValue) { + + if(arrayValue == null || arrayValue.size() <= 0) { + return metric; + } + + String convertChar = "$"; + String convertStr = null; + + for(int indexI = 0 ; indexI < arrayValue.size(); ++indexI) { + + convertStr = convertChar + String.valueOf(indexI); + + metric = metric.replace(convertStr, arrayValue.get(indexI)); + + } + + return metric; + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSetRow.java b/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSetRow.java new file mode 100644 index 0000000..38559a7 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/crawler/result/ResultSetRow.java @@ -0,0 +1,104 @@ +package com.loafle.overflow.probe.container.crawler.result; + +import com.loafle.overflow.probe.container.crawler.config.Item; +import com.loafle.overflow.probe.container.crawler.config.Keys; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ResultSetRow extends ResultSet{ + + public ResultSetRow(Item item) { + super(item); + } + + public void setMeta() { + + List meta = new ArrayList<>(); + + List arrayColumns = (List) this.item.getMappingInfo().getArrayColumns(); + List keyColumns = (List) this.item.getMappingInfo().getKeyColumns(); + String valueColumn = (String) this.item.getMappingInfo().getValueColumn(); + if (arrayColumns != null) { + for (String c : arrayColumns) { + meta.add(c); + } + } + + if (keyColumns != null) { + for (String c: keyColumns) { + meta.add(c); + } + } + + if (valueColumn != null && !valueColumn.equals("")) + meta.add(valueColumn); + + if(this.meta == null) { + this.meta = new HashMap<>(); + } + + for(int indexI = 0; indexI < meta.size(); ++indexI) { + this.meta.put(meta.get(indexI), indexI); + } + + } + + public Map parse() { + + Map returnMap = new HashMap<>(); + + String valueColumn = (String) this.item.getMappingInfo().getValueColumn(); + + for (List row : this.rows) { + String key = makeKey(row); + if(key == null) continue; + returnMap.put(key,row.get(this.meta.get(valueColumn))); + } + + return returnMap; + } + + private String makeKey(List data) { + + List metrics = this.item.getKeys(); + + List arrayColumns = (List) this.item.getMappingInfo().getArrayColumns(); + List keyColumns = (List) this.item.getMappingInfo().getKeyColumns(); + List keys = this.item.getKeys(); + + boolean find = false; + int findIndex = -1; + for (String keyColumn: keyColumns) { + String row = data.get(this.meta.get(keyColumn)); + for (int i =0 ; i < keys.size() ; ++i) { + if (row.equals(keys.get(i).getKey())) { + findIndex = i; + find = true; + break; + } + } + if (find == true) {break;} + } + + if(findIndex < 0) { + return null; + } + + String metric = metrics.get(findIndex).getMetric(); + + if (arrayColumns != null) { + for (int i =0 ; i< arrayColumns.size() ; ++i) { + // replace + String k = "$" + i; + int dataIndex = this.meta.get(arrayColumns.get(i)); + String replaceString = data.get(dataIndex); + metric = metric.replace(k,"'" + replaceString + "'"); + } + } + return metric; + } + +} diff --git a/src/main/java/com/loafle/overflow/probe/container/rpc/invoker/spring/SpringInvoker.java b/src/main/java/com/loafle/overflow/probe/container/rpc/invoker/impl/SimpleInvoker.java similarity index 81% rename from src/main/java/com/loafle/overflow/probe/container/rpc/invoker/spring/SpringInvoker.java rename to src/main/java/com/loafle/overflow/probe/container/rpc/invoker/impl/SimpleInvoker.java index cd8e2c1..52184a1 100644 --- a/src/main/java/com/loafle/overflow/probe/container/rpc/invoker/spring/SpringInvoker.java +++ b/src/main/java/com/loafle/overflow/probe/container/rpc/invoker/impl/SimpleInvoker.java @@ -1,14 +1,9 @@ -package com.loafle.overflow.probe.container.rpc.invoker.spring; +package com.loafle.overflow.probe.container.rpc.invoker.impl; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.loafle.overflow.probe.container.rpc.invoker.Invoker; import com.loafle.overflow.probe.container.util.Primitives; -import org.springframework.aop.support.AopUtils; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; import java.io.IOException; import java.lang.reflect.Method; @@ -18,17 +13,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -@Component -public class SpringInvoker implements Invoker { - @Autowired - private ApplicationContext applicationContext; - @Autowired +public class SimpleInvoker implements Invoker { private ObjectMapper objectMapper; + private Map services; private Map serviceCacheMap; - public SpringInvoker() { + public SimpleInvoker(ObjectMapper objectMapper, Map services) { + this.objectMapper = objectMapper; + this.services = services; serviceCacheMap = new HashMap<>(); } @@ -36,15 +30,15 @@ public class SpringInvoker implements Invoker { private ServiceCache serviceCache; private Map methodCacheMap; - private Cache(Object bean) { + private Cache(Object service) { serviceCache = new ServiceCache(); - serviceCache.bean = bean; + serviceCache.service = service; methodCacheMap = new HashMap<>(10); } - private Object getBean() { - return serviceCache.bean; + private Object getService() { + return serviceCache.service; } private MethodCache getMethodCache(String methodName) throws NoSuchMethodException { @@ -74,7 +68,7 @@ public class SpringInvoker implements Invoker { } private Method getMethod(String methodName) { - Class clazz = AopUtils.getTargetClass(serviceCache.bean); + Class clazz = serviceCache.service.getClass(); Method[] methods = clazz.getMethods(); Method targetMethod = null; @@ -88,7 +82,7 @@ public class SpringInvoker implements Invoker { } private static class ServiceCache { - private Object bean; + private Object service; private Map methodCacheMap; } private static class MethodCache { @@ -103,13 +97,13 @@ public class SpringInvoker implements Invoker { if (null != serviceCache) { return serviceCache; } - try { - Object bean = applicationContext.getBean(serviceName); - serviceCache = new Cache(bean); - serviceCacheMap.put(serviceName, serviceCache); - } catch (BeansException e) { - throw new Exception(); + + Object service = services.get(serviceName); + if (null == service) { + throw new Exception(String.format("Invoker: Service[%s] is not exist", serviceName)); } + serviceCache = new Cache(service); + serviceCacheMap.put(serviceName, serviceCache); return serviceCache; } @@ -171,7 +165,7 @@ public class SpringInvoker implements Invoker { Object result = null; try { - result = methodCache.method.invoke(serviceCache.getBean(), parameters); + result = methodCache.method.invoke(serviceCache.getService(), parameters); } catch (Exception e) { throw e; } diff --git a/src/main/java/com/loafle/overflow/probe/container/server/ContainerChannelInitializer.java b/src/main/java/com/loafle/overflow/probe/container/server/ContainerChannelInitializer.java index 84d52af..7034d6f 100644 --- a/src/main/java/com/loafle/overflow/probe/container/server/ContainerChannelInitializer.java +++ b/src/main/java/com/loafle/overflow/probe/container/server/ContainerChannelInitializer.java @@ -1,26 +1,17 @@ package com.loafle.overflow.probe.container.server; import io.netty.channel.Channel; -import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.json.JsonObjectDecoder; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; import io.netty.util.CharsetUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; -@Component -@Qualifier("containerChannelInitializer") public class ContainerChannelInitializer extends ChannelInitializer { private static final StringDecoder STRING_DECODER = new StringDecoder(CharsetUtil.UTF_8); private static final StringEncoder STRING_ENCODER = new StringEncoder(CharsetUtil.UTF_8); - @Autowired - @Qualifier("containerJSONHandler") - private ChannelInboundHandlerAdapter containerJSONHandler; @Override protected void initChannel(Channel channel) throws Exception { @@ -30,7 +21,7 @@ public class ContainerChannelInitializer extends ChannelInitializer { .addLast(new JsonObjectDecoder(Integer.MAX_VALUE)) .addLast(STRING_DECODER) .addLast(STRING_ENCODER) - .addLast(containerJSONHandler); + .addLast(ContainerConfiguration.channelInboundHandlerAdapter()); } } diff --git a/src/main/java/com/loafle/overflow/probe/container/server/ContainerConfiguration.java b/src/main/java/com/loafle/overflow/probe/container/server/ContainerConfiguration.java index 503834b..9dd055c 100644 --- a/src/main/java/com/loafle/overflow/probe/container/server/ContainerConfiguration.java +++ b/src/main/java/com/loafle/overflow/probe/container/server/ContainerConfiguration.java @@ -1,52 +1,86 @@ package com.loafle.overflow.probe.container.server; import com.fasterxml.jackson.databind.ObjectMapper; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.impl.database.mysql.MySQLCrawler; +import com.loafle.overflow.probe.container.crawler.impl.database.oracle.OracleCrawler; +import com.loafle.overflow.probe.container.crawler.impl.database.postgresql.PostgreSQLCrawler; +import com.loafle.overflow.probe.container.crawler.impl.database.sqlserver.SQLServerCrawler; +import com.loafle.overflow.probe.container.crawler.impl.jmx.JMXCrawler; +import com.loafle.overflow.probe.container.crawler.impl.mongodb.MongoDBCrawler; +import com.loafle.overflow.probe.container.crawler.impl.redis.RedisCralwer; +import com.loafle.overflow.probe.container.crawler.impl.snmp.SNMPCrawler; +import com.loafle.overflow.probe.container.crawler.impl.wmi.WMICrawler; +import com.loafle.overflow.probe.container.rpc.invoker.Invoker; +import com.loafle.overflow.probe.container.rpc.invoker.impl.SimpleInvoker; +import com.loafle.overflow.probe.container.service.ConfigService; +import com.loafle.overflow.probe.container.service.DataService; +import com.loafle.overflow.probe.container.service.StateService; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.ChannelInitializer; -import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.Map; -@Configuration -public class ContainerConfiguration { - private int port = 19390; +public abstract class ContainerConfiguration { + private static ObjectMapper objectMapper; + private static ContainerChannelInitializer channelInitializer; + private static ChannelInboundHandlerAdapter channelInboundHandlerAdapter; + private static Invoker invoker; + private static Map crawlers = new HashMap<>(); + private static Map services = new HashMap<>(); - @Autowired - private ContainerChannelInitializer containerChannelInitializer; + 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()); - @Bean(destroyMethod = "shutdownGracefully") - public NioEventLoopGroup bossGroup() { - return new NioEventLoopGroup(); + addService(new ConfigService(crawlers)); + addService(new DataService(crawlers)); + addService(new StateService(crawlers)); } - @Bean(destroyMethod = "shutdownGracefully") - public NioEventLoopGroup workerGroup() { - return new NioEventLoopGroup(); - + private static void addCrawler(Crawler crawler) { + String name = crawler.name(); + crawlers.put(name, crawler); } - @Bean - public InetSocketAddress socketAddress() { - return new InetSocketAddress("127.0.0.1", port); + private static void addService(Object service) { + String name = service.getClass().getSimpleName(); + services.put(name, service); } - @Bean - public ServerBootstrap serverBootstrap() { - ServerBootstrap serverBootstrap = new ServerBootstrap(); - - serverBootstrap - .group(bossGroup(), workerGroup()) - .channel(NioServerSocketChannel.class) - .childHandler(containerChannelInitializer); - - return serverBootstrap; + public static ObjectMapper objectMapper() { + if (null == objectMapper) { + objectMapper = new ObjectMapper(); + } + return objectMapper; } - @Bean - public ObjectMapper objectMapper() { - return new ObjectMapper(); + public static ChannelInitializer channelInitializer() { + if (null == channelInitializer) { + channelInitializer = new ContainerChannelInitializer(); + } + return channelInitializer; + } + + public static ChannelInboundHandlerAdapter channelInboundHandlerAdapter() { + if (null == channelInboundHandlerAdapter) { + channelInboundHandlerAdapter = new ContainerJSONHandler(); + } + return channelInboundHandlerAdapter; + } + + public static Invoker invoker() { + if (null == invoker) { + invoker = new SimpleInvoker(objectMapper(), services); + } + return invoker; } } diff --git a/src/main/java/com/loafle/overflow/probe/container/server/ContainerJSONHandler.java b/src/main/java/com/loafle/overflow/probe/container/server/ContainerJSONHandler.java index 7b0f88b..11fa327 100644 --- a/src/main/java/com/loafle/overflow/probe/container/server/ContainerJSONHandler.java +++ b/src/main/java/com/loafle/overflow/probe/container/server/ContainerJSONHandler.java @@ -8,23 +8,15 @@ import com.loafle.overflow.probe.container.rpc.protocol.json.ServerResponse; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; -import java.io.IOException; - -@Component -@Qualifier("containerJSONHandler") @ChannelHandler.Sharable public class ContainerJSONHandler extends SimpleChannelInboundHandler { - @Autowired - private ObjectMapper objectMapper; - @Autowired - private Invoker invoker; @Override protected void channelRead0(ChannelHandlerContext ctx, String s) throws Exception { + ObjectMapper objectMapper = ContainerConfiguration.objectMapper(); + Invoker invoker = ContainerConfiguration.invoker(); + ServerRequest req = objectMapper.readValue(s, ServerRequest.class); ServerResponse res = null; try { diff --git a/src/main/java/com/loafle/overflow/probe/container/server/ContainerServer.java b/src/main/java/com/loafle/overflow/probe/container/server/ContainerServer.java index 0a822b2..ab9ebd2 100644 --- a/src/main/java/com/loafle/overflow/probe/container/server/ContainerServer.java +++ b/src/main/java/com/loafle/overflow/probe/container/server/ContainerServer.java @@ -1,34 +1,39 @@ package com.loafle.overflow.probe.container.server; import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.Channel; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import io.netty.channel.*; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; -import javax.annotation.PreDestroy; import java.net.InetSocketAddress; -@Component public class ContainerServer { - @Autowired - private ServerBootstrap serverBootstrap; - - @Autowired - private InetSocketAddress socketAddress; - - private Channel channel; + private int port = 19390; public ContainerServer() { - } public void start() throws Exception { - channel = serverBootstrap.bind(socketAddress).sync().channel().closeFuture().sync().channel(); + InetSocketAddress socketAddress = new InetSocketAddress("127.0.0.1", port); + + EventLoopGroup bossGroup = new NioEventLoopGroup(1); + EventLoopGroup workerGroup = new NioEventLoopGroup(10); + try { + ServerBootstrap b = new ServerBootstrap(); + + b.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .childHandler(ContainerConfiguration.channelInitializer()) + .option(ChannelOption.SO_BACKLOG, 128) + .childOption(ChannelOption.SO_KEEPALIVE, true); + + ChannelFuture f = b.bind(socketAddress).sync(); + + f.channel().closeFuture().sync(); + } finally { + workerGroup.shutdownGracefully(); + bossGroup.shutdownGracefully(); + } } - @PreDestroy - public void stop() throws Exception { - channel.close(); - channel.parent().close(); - } } diff --git a/src/main/java/com/loafle/overflow/probe/container/service/ConfigService.java b/src/main/java/com/loafle/overflow/probe/container/service/ConfigService.java new file mode 100644 index 0000000..8219bde --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/service/ConfigService.java @@ -0,0 +1,27 @@ +package com.loafle.overflow.probe.container.service; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.config.Config; + +import java.util.Map; + +public class ConfigService extends Service { + public ConfigService(Map crawlers) { + super(crawlers); + } + + public boolean init(String crawlerName, Config config) throws Exception { + Crawler crawler = getCrawler(crawlerName); + return crawler.init(config); + } + + public boolean add(String crawlerName, Config config) throws Exception { + Crawler crawler = getCrawler(crawlerName); + return crawler.add(config); + } + + public boolean remove(String crawlerName, String id) throws Exception { + Crawler crawler = getCrawler(crawlerName); + return crawler.remove(id); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/service/DataService.java b/src/main/java/com/loafle/overflow/probe/container/service/DataService.java new file mode 100644 index 0000000..30a1fb0 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/service/DataService.java @@ -0,0 +1,18 @@ +package com.loafle.overflow.probe.container.service; + +import com.loafle.overflow.probe.container.crawler.Crawler; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +import java.util.List; +import java.util.Map; + +public class DataService extends Service { + public DataService(Map crawlers) { + super(crawlers); + } + + public List get(String crawlerName, String id) throws Exception { + Crawler crawler = getCrawler(crawlerName); + return crawler.get(id); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/service/Service.java b/src/main/java/com/loafle/overflow/probe/container/service/Service.java new file mode 100644 index 0000000..0cc56b0 --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/service/Service.java @@ -0,0 +1,19 @@ +package com.loafle.overflow.probe.container.service; + +import com.loafle.overflow.probe.container.crawler.Crawler; + +import java.util.Map; + +public abstract class Service { + private Map crawlers; + protected Service(Map crawlers) { + this.crawlers = crawlers; + } + + protected Crawler getCrawler(String crawlerName) throws Exception { + if (!this.crawlers.containsKey(crawlerName)) { + throw new Exception(String.format("Container: Crawler[%s] is not exist", crawlerName)); + } + return this.crawlers.get(crawlerName); + } +} diff --git a/src/main/java/com/loafle/overflow/probe/container/service/StateService.java b/src/main/java/com/loafle/overflow/probe/container/service/StateService.java new file mode 100644 index 0000000..34f7d3a --- /dev/null +++ b/src/main/java/com/loafle/overflow/probe/container/service/StateService.java @@ -0,0 +1,15 @@ +package com.loafle.overflow.probe.container.service; + +import com.loafle.overflow.probe.container.crawler.Crawler; + +import java.util.Map; + +public class StateService extends Service { + public StateService(Map crawlers) { + super(crawlers); + } + + public boolean status() throws Exception { + return true; + } +} diff --git a/src/test/java/com/loafle/overflow/probe/container/ApplicationTests.java b/src/test/java/com/loafle/overflow/probe/container/ApplicationTests.java deleted file mode 100644 index 01b85a0..0000000 --- a/src/test/java/com/loafle/overflow/probe/container/ApplicationTests.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.loafle.overflow.probe.container; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = Application.class) -public class ApplicationTests { - - @Autowired - private ApplicationContext applicationContext; - - @Test - public void testStart() throws Exception { - - } - -} - - - diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/CrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/CrawlerTest.java new file mode 100644 index 0000000..9168554 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/CrawlerTest.java @@ -0,0 +1,13 @@ +package com.loafle.overflow.probe.container.crawler; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; + +public abstract class CrawlerTest { + protected ObjectMapper objectMapper; + @Before + public void setUp() throws Exception { + objectMapper = new ObjectMapper(); + } + +} diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseCrawlerTest.java new file mode 100644 index 0000000..9b10106 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/DatabaseCrawlerTest.java @@ -0,0 +1,62 @@ +package com.loafle.overflow.probe.container.crawler.impl.database; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.loafle.overflow.probe.container.crawler.CrawlerTest; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; + +import java.io.File; +import java.io.IOException; +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 Config getConfig(String path) throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + String filePath = classLoader.getResource(path).getFile(); + + Config c = objectMapper.readValue(new File(filePath),Config.class); + return c; + } + + protected void print(String s, List mm) { + + System.out.println(s); + + Map m = new HashMap<>(); + for(ResultSet r : mm) { + m.putAll(r.getData()); + } + + for (Map.Entry item : m.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + } + + +} diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/mysql/MySQLCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/mysql/MySQLCrawlerTest.java new file mode 100644 index 0000000..faa48b2 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/mysql/MySQLCrawlerTest.java @@ -0,0 +1,15 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.mysql; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawlerTest; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Test; + +import java.util.List; + +public class MySQLCrawlerTest extends DatabaseCrawlerTest { + @Test + public void testMySQL() throws Exception { + Object result = new MySQLCrawler().getInternal( getConfig("config/mysql/mysql-test.json")); + print("MySQL row", (List) result); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/oracle/OracleCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/oracle/OracleCrawlerTest.java new file mode 100644 index 0000000..6c82da1 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/oracle/OracleCrawlerTest.java @@ -0,0 +1,15 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.oracle; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawlerTest; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Test; + +import java.util.List; + +public class OracleCrawlerTest extends DatabaseCrawlerTest { + @Test + public void testMySQL() throws Exception { + Object result = new OracleCrawler().getInternal( getConfig("config/oracle/oracle-test.json")); + print("Oracle row", (List) result); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/postgresql/PostgreSQLCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/postgresql/PostgreSQLCrawlerTest.java new file mode 100644 index 0000000..b8e8669 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/postgresql/PostgreSQLCrawlerTest.java @@ -0,0 +1,15 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.postgresql; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawlerTest; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Test; + +import java.util.List; + +public class PostgreSQLCrawlerTest extends DatabaseCrawlerTest { + @Test + public void testPostgreSQL() throws Exception { + Object result = new PostgreSQLCrawler().getInternal( getConfig("config/postgresql/postgresql.json")); + print("PostgreSQL", (List) result); + } +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/sqlserver/SQLServerCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/sqlserver/SQLServerCrawlerTest.java new file mode 100644 index 0000000..90cd197 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/database/sqlserver/SQLServerCrawlerTest.java @@ -0,0 +1,22 @@ +package com.loafle.overflow.probe.container.crawler.impl.database.sqlserver; + +import com.loafle.overflow.probe.container.crawler.impl.database.DatabaseCrawlerTest; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Test; + +import java.util.List; + +public class SQLServerCrawlerTest extends DatabaseCrawlerTest { + @Test + public void testConnection_Count() throws Exception { + Object result = new SQLServerCrawler().getInternal( getConfig("config/sqlserver/sqlserver_connection_count.json")); + print("SQL Server Connection count", (List) result); + } + + @Test + public void testMultiKeyArray() throws Exception { + Object result = new SQLServerCrawler().getInternal( getConfig("config/sqlserver/sqlserver_multiple_key_array.json")); + print("SQL Server MultiArray", (List) result); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/jmx/JMXCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/jmx/JMXCrawlerTest.java new file mode 100644 index 0000000..39d03e8 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/jmx/JMXCrawlerTest.java @@ -0,0 +1,6 @@ +package com.loafle.overflow.probe.container.crawler.impl.jmx; + +import com.loafle.overflow.probe.container.crawler.CrawlerTest; + +public class JMXCrawlerTest extends CrawlerTest { +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/jmx/tomcat/TomcatCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/jmx/tomcat/TomcatCrawlerTest.java new file mode 100644 index 0000000..0f8881c --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/jmx/tomcat/TomcatCrawlerTest.java @@ -0,0 +1,65 @@ +package com.loafle.overflow.probe.container.crawler.impl.jmx.tomcat; + +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.impl.jmx.JMXCrawler; +import com.loafle.overflow.probe.container.crawler.impl.jmx.JMXCrawlerTest; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class TomcatCrawlerTest extends JMXCrawlerTest { + + @Test + public void testSum() { + assertEquals(1,1); + } + + @Test + public void TestDoCrawler() throws Exception { + + ClassLoader classLoader = getClass().getClassLoader(); + URL url = classLoader.getResource("config/tomcat/"); + String path = classLoader.getResource("config/tomcat/example1.json").getFile(); + + Config c = objectMapper.readValue(new File(path),Config.class); + + JMXCrawler cr = new JMXCrawler(); + List result = (List) cr.getInternal(c); + + print("",result); + } + + + //keytool -export -alias alias_name -keystore path_to_keystore_file -rfc -file path_to_certificate_file + private void print(String s, List mm) { + + System.out.println(s); + + Map m = new HashMap<>(); + for(ResultSet r : mm) { + m.putAll(r.getData()); + } + + for (Map.Entry item : m.entrySet()) { + System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue()); + } + } + + @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/probe/container/crawler/impl/mongodb/MongoDBCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/mongodb/MongoDBCrawlerTest.java new file mode 100644 index 0000000..e30091f --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/mongodb/MongoDBCrawlerTest.java @@ -0,0 +1,45 @@ +package com.loafle.overflow.probe.container.crawler.impl.mongodb; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.loafle.overflow.probe.container.crawler.CrawlerTest; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.util.List; +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 path = classLoader.getResource("config/mongodb/example.json").getFile(); + + Config c = objectMapper.readValue(new File(path),Config.class); + + MongoDBCrawler cr = new MongoDBCrawler(); + List rl = (List)cr.collectMetric(c); + + for(int indexI = 0 ; indexI < rl.size(); ++indexI) { + Map m = rl.get(indexI).getData(); + for( String key : m.keySet()) { + System.out.print("key : " + key); + System.out.print("|| value : "); + System.out.println(m.get(key)); + } + } + + +// assertEquals(6, m.size()); + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/redis/RedisCralwerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/redis/RedisCralwerTest.java new file mode 100644 index 0000000..bbfe332 --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/redis/RedisCralwerTest.java @@ -0,0 +1,47 @@ +package com.loafle.overflow.probe.container.crawler.impl.redis; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.loafle.overflow.probe.container.crawler.CrawlerTest; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +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 path = classLoader.getResource("config/redis/example.json").getFile(); + + Config c = objectMapper.readValue(new File(path),Config.class); + + RedisCralwer rc = new RedisCralwer(); + List result = (List) rc.getInternal(c); + print("",result); + } + + + private void print(String s, List mm) { + + System.out.println(s); + + Map m = new HashMap<>(); + for(ResultSet r : mm) { + m.putAll(r.getData()); + } + + 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/probe/container/crawler/impl/snmp/SNMPCrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/snmp/SNMPCrawlerTest.java new file mode 100644 index 0000000..27659fd --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/snmp/SNMPCrawlerTest.java @@ -0,0 +1,79 @@ +package com.loafle.overflow.probe.container.crawler.impl.snmp; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.loafle.overflow.probe.container.crawler.CrawlerTest; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.Ignore; +import org.junit.Test; + +import java.io.File; +import java.util.List; +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 p = classLoader.getResource("config/snmp/examplev3.json").getFile(); + Config config = objectMapper.readValue(new File(p),Config.class); + + Object result = c.getInternal(config); + + if(result instanceof Boolean) { + System.out.println("validate : " + result); + }else { + printResult((List)result); + } + + } + + @Ignore + @Test + public void testSNMP2c() throws Exception { + SNMPCrawler c = new SNMPCrawler(); + + ClassLoader classLoader = getClass().getClassLoader(); + String p = classLoader.getResource("config/snmp/examplev2.json").getFile(); + Config config = objectMapper.readValue(new File(p),Config.class); + + Object result = c.getInternal(config); + + if(result instanceof Boolean) { + System.out.println("validate : " + result); + }else { + printResult((List)result); + } + + } + + private void printResult(List 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("============================================"); + } + + } + +} \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerTest.java b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerTest.java new file mode 100644 index 0000000..9037bca --- /dev/null +++ b/src/test/java/com/loafle/overflow/probe/container/crawler/impl/wmi/WMICrawlerTest.java @@ -0,0 +1,313 @@ +package com.loafle.overflow.probe.container.crawler.impl.wmi; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.loafle.overflow.probe.container.crawler.CrawlerTest; +import com.loafle.overflow.probe.container.crawler.config.Config; +import com.loafle.overflow.probe.container.crawler.result.ResultSet; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +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"); + + Config config = new Config(); + + ClassLoader classLoader = getClass().getClassLoader(); + + String s = classLoader.getResource("config/wmi").getFile(); + System.out.println(s); + +// 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")); + + } + + @Test + public void testConfig() throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + String p = classLoader.getResource("config/wmi/example.json").getFile(); + + System.out.println(p); + + + Config c = objectMapper.readValue(new File(p),Config.class); + + System.out.println(c); + } + + // @Ignore + @Test + public void testWMIJson() throws Exception { + ClassLoader classLoader = getClass().getClassLoader(); + String p = classLoader.getResource("config/wmi/meta/meta_network.json").getFile(); + Config c = objectMapper.readValue(new File(p),Config.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(); + + + List resultList = (List)wmiCrawler.getInternal(c); + + 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(List 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("============================================"); + } + } + + @Test + public void testMetaProcess() throws Exception { + + // get targetinfo + ClassLoader classLoader = getClass().getClassLoader(); + String p = classLoader.getResource("config/wmi/test.json").getFile(); + Config c = objectMapper.readValue(new File(p),Config.class); + + List metaConfigList = loadMetaConfig(); + + + List retlist = new ArrayList<>(); + WMICrawlerOS os = WMICrawlerOS.getInstance(); + ResultSet ofResultSet = null; + for(Config metaConfig : metaConfigList) { + + for(int indexI = 0; indexI < metaConfig.getItems().size(); ++indexI) { + ofResultSet = os.processWMI(c, metaConfig.getItems().get(indexI)); + if(ofResultSet != null) { + retlist.add(ofResultSet); + } + } + } + + + + + + 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<>(); + Config metaConfig = null; + for(String fi : metaFiles) { + if(fi.indexOf("meta_") > -1) { + metaConfig = objectMapper.readValue(new File(path+"/"+fi), Config.class); + if(metaConfig != null) { + retList.add(metaConfig); + } + } + } + + 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/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 + } + }] +}