ing
This commit is contained in:
commit
67144d0f82
73
.gitignore
vendored
Normal file
73
.gitignore
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
### Go template
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
vendor/
|
||||
glide.lock
|
||||
.DS_Store
|
||||
dist/
|
||||
debug
|
||||
|
||||
target
|
||||
.settings
|
||||
.project
|
||||
.classpath
|
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug",
|
||||
"request": "launch",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "internalConsole",
|
||||
"stopOnEntry": false,
|
||||
"mainClass": "com.loafle.overflow.container.general.GeneralContainer",
|
||||
"projectName": "container_general",
|
||||
"args": "${workspaceFolder}/general.pid"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug (Attach)",
|
||||
"request": "attach",
|
||||
"hostName": "localhost",
|
||||
"port": 0
|
||||
}
|
||||
]
|
||||
}
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
}
|
190
pom.xml
Normal file
190
pom.xml
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.loafle</groupId>
|
||||
<artifactId>maven_parent_jar</artifactId>
|
||||
<version>1.0.0-RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>container_general</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>com.loafle.overflow.container_general</name>
|
||||
<description>container_general project</description>
|
||||
|
||||
<properties>
|
||||
<server-java.version>1.0.0-SNAPSHOT</server-java.version>
|
||||
<rpc-java.version>1.0.0-SNAPSHOT</rpc-java.version>
|
||||
|
||||
<overflow.commons-java.version>1.0.0-SNAPSHOT</overflow.commons-java.version>
|
||||
<overflow.crawler-java.version>1.0.0-SNAPSHOT</overflow.crawler-java.version>
|
||||
<overflow.container-java.version>1.0.0-SNAPSHOT</overflow.container-java.version>
|
||||
|
||||
<netty.version>4.1.17.Final</netty.version>
|
||||
<gson.version>2.8.2</gson.version>
|
||||
<spring.version>5.0.5.RELEASE</spring.version>
|
||||
|
||||
<mysql-connector-java.version>6.0.6</mysql-connector-java.version>
|
||||
<postgresql.version>42.1.4</postgresql.version>
|
||||
<mssql-jdbc.version>6.2.2.jre8</mssql-jdbc.version>
|
||||
|
||||
<jacob.version>1.18</jacob.version>
|
||||
|
||||
<jedis.version>2.9.0</jedis.version>
|
||||
|
||||
<mongo-java-driver.version>3.6.0</mongo-java-driver.version>
|
||||
|
||||
<snmp4j.version>2.5.8</snmp4j.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.loafle.commons</groupId>
|
||||
<artifactId>server-java</artifactId>
|
||||
<version>${server-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.loafle.commons</groupId>
|
||||
<artifactId>rpc-java</artifactId>
|
||||
<version>${rpc-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>commons-java</artifactId>
|
||||
<version>${overflow.commons-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>crawler-java</artifactId>
|
||||
<version>${overflow.crawler-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>container-java</artifactId>
|
||||
<version>${overflow.container-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>${netty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SQL -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql-connector-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${postgresql.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>${mssql-jdbc.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- WMI -->
|
||||
<dependency>
|
||||
<groupId>com.hynnet</groupId>
|
||||
<artifactId>jacob</artifactId>
|
||||
<version>${jacob.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Redis -->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>${jedis.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- MongoDB -->
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongo-java-driver</artifactId>
|
||||
<version>${mongo-java-driver.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SNMP -->
|
||||
<dependency>
|
||||
<groupId>org.snmp4j</groupId>
|
||||
<artifactId>snmp4j</artifactId>
|
||||
<version>${snmp4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Copy Maven dependencies into target/lib/ -->
|
||||
<!--<plugin>-->
|
||||
<!--<artifactId>maven-dependency-plugin</artifactId>-->
|
||||
<!--<executions>-->
|
||||
<!--<execution>-->
|
||||
<!--<phase>package</phase>-->
|
||||
<!--<goals>-->
|
||||
<!--<goal>copy-dependencies</goal>-->
|
||||
<!--</goals>-->
|
||||
<!--<configuration>-->
|
||||
<!--<overWriteReleases>false</overWriteReleases>-->
|
||||
<!--<includeScope>runtime</includeScope>-->
|
||||
<!--<outputDirectory>${project.build.directory}/lib</outputDirectory>-->
|
||||
<!--</configuration>-->
|
||||
<!--</execution>-->
|
||||
<!--</executions>-->
|
||||
<!--</plugin>-->
|
||||
|
||||
<!--<plugin>-->
|
||||
<!--<groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!--<artifactId>maven-jar-plugin</artifactId>-->
|
||||
<!--<configuration>-->
|
||||
<!--<archive>-->
|
||||
<!--<manifest>-->
|
||||
<!--<mainClass>com.loafle.overflow.container.general.Container</mainClass>-->
|
||||
<!--</manifest>-->
|
||||
<!--</archive>-->
|
||||
<!--</configuration>-->
|
||||
<!--</plugin>-->
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.loafle.overflow.container.general.Container</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,24 @@
|
|||
package com.loafle.overflow.container.general;
|
||||
|
||||
import com.loafle.overflow.container.general.server.GeneralContainerServer;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class GeneralContainer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length <= 0) {
|
||||
System.out.println("first parameter is path of pid file");
|
||||
return;
|
||||
}
|
||||
String pidFilePath = args[0];
|
||||
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
"com.loafle.overflow")) {
|
||||
context.registerShutdownHook();
|
||||
context.getBeanFactory().registerSingleton("pidFilePath", pidFilePath);
|
||||
GeneralContainerServer server = context.getBean(GeneralContainerServer.class);
|
||||
server.start();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.loafle.overflow.container.general.crawler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.mysql.MySQLCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.oracle.OracleCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.postgresql.PostgreSQLCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.sqlserver.SQLServerCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.mongodb.MongoDBCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.redis.RedisCralwer;
|
||||
import com.loafle.overflow.container.general.crawler.impl.snmp.SNMPCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.wmi.WMICrawler;
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
|
||||
public abstract class Crawlers {
|
||||
private static Map<String, Crawler> crawlers = new HashMap<>();
|
||||
|
||||
static {
|
||||
addCrawler(new MySQLCrawler());
|
||||
addCrawler(new OracleCrawler());
|
||||
addCrawler(new PostgreSQLCrawler());
|
||||
addCrawler(new SQLServerCrawler());
|
||||
addCrawler(new JMXCrawler());
|
||||
addCrawler(new MongoDBCrawler());
|
||||
addCrawler(new RedisCralwer());
|
||||
addCrawler(new SNMPCrawler());
|
||||
addCrawler(new WMICrawler());
|
||||
|
||||
}
|
||||
|
||||
private static void addCrawler(Crawler crawler) {
|
||||
String name = crawler.name();
|
||||
crawlers.put(name, crawler);
|
||||
}
|
||||
|
||||
public Map<String, Crawler> getCrawlers() {
|
||||
return Crawlers.crawlers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSetRow;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
public abstract class DatabaseCrawler implements Crawler {
|
||||
|
||||
public DatabaseCrawler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auth(Map<String, Object> authInfoMap) throws OverflowException {
|
||||
Connection conn = null;
|
||||
|
||||
String url = (String) authInfoMap.get("url");
|
||||
String id = (String) authInfoMap.get("id");
|
||||
String pw = (String) authInfoMap.get("pw");
|
||||
|
||||
try {
|
||||
loadDriverClass();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new OverflowException("DatabaseCrawler", e);
|
||||
}
|
||||
|
||||
try {
|
||||
conn = java.sql.DriverManager.getConnection(url, id, pw);
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("DatabaseCrawler", e);
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException {
|
||||
Connection conn = null;
|
||||
Statement stmt = null;
|
||||
|
||||
java.sql.ResultSet rs = null;
|
||||
|
||||
String url = (String) sensorConfig.getTarget().getAuth().get("url");
|
||||
String id = (String) sensorConfig.getTarget().getAuth().get("id");
|
||||
String pw = (String) sensorConfig.getTarget().getAuth().get("pw");
|
||||
|
||||
try {
|
||||
loadDriverClass();
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new OverflowException("DatabaseCrawler", e);
|
||||
}
|
||||
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
|
||||
try {
|
||||
conn = java.sql.DriverManager.getConnection(url, id, pw);
|
||||
stmt = conn.createStatement();
|
||||
|
||||
for (Item item : sensorConfig.getItems()) {
|
||||
|
||||
ResultSet resultSet = ResultSetRow.newInstance(item);
|
||||
Map<String, Integer> meta = resultSet.getMeta();
|
||||
|
||||
rs = stmt.executeQuery((String) item.getQueryInfo().getQuery());
|
||||
|
||||
while (rs.next()) {
|
||||
List<String> row = new ArrayList<>(Arrays.asList(new String[meta.size()]));
|
||||
for (Map.Entry<String, Integer> info : meta.entrySet()) {
|
||||
String data = rs.getString(info.getKey());
|
||||
data = data.trim();
|
||||
row.set(info.getValue().intValue(), data);
|
||||
}
|
||||
resultSet.addRow(row);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
resultMap.putAll(resultSet.getData());
|
||||
}
|
||||
return resultMap;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("DatabaseCrawler", e);
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void loadDriverClass() throws ClassNotFoundException;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database;
|
||||
|
||||
public class DatabaseMetaInfo {
|
||||
private String name;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.mysql;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler;
|
||||
|
||||
public class MySQLCrawler extends DatabaseCrawler {
|
||||
@Override
|
||||
public String name() {
|
||||
return "MYSQL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MySQL Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDriverClass() throws ClassNotFoundException {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.oracle;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler;
|
||||
|
||||
public class OracleCrawler extends DatabaseCrawler {
|
||||
@Override
|
||||
public String name() {
|
||||
return "ORACLE";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Oracle Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDriverClass() throws ClassNotFoundException {
|
||||
Class.forName("oracle.jdbc.driver.OracleDriver");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.postgresql;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler;
|
||||
|
||||
public class PostgreSQLCrawler extends DatabaseCrawler {
|
||||
@Override
|
||||
public String name() {
|
||||
return "POSTGRESQL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PostgreSQL Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDriverClass() throws ClassNotFoundException {
|
||||
Class.forName("org.postgresql.Driver");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.sqlserver;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawler;
|
||||
|
||||
public class SQLServerCrawler extends DatabaseCrawler {
|
||||
@Override
|
||||
public String name() {
|
||||
return "SQLSERVER";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SQL Server Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadDriverClass() throws ClassNotFoundException {
|
||||
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,225 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.jmx;
|
||||
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
|
||||
import javax.management.*;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXConnectorFactory;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
import javax.management.remote.rmi.RMIConnectorServer;
|
||||
import javax.naming.Context;
|
||||
import javax.rmi.ssl.SslRMIClientSocketFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class JMXCrawler implements Crawler {
|
||||
private static final Logger logger = Logger.getLogger(JMXCrawler.class.getName());
|
||||
|
||||
public JMXCrawler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "JMX";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JMX Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auth(Map<String, Object> authInfoMap) throws OverflowException {
|
||||
String hostIp = (String) authInfoMap.get("ip");
|
||||
Integer port = (Integer) authInfoMap.get("port");
|
||||
|
||||
String jmxUrl = "service:jmx:rmi:///jndi/rmi://" + hostIp + ":" + port + "/jmxrmi";
|
||||
String username = (String) authInfoMap.get("id");
|
||||
String password = (String) authInfoMap.get("pw");
|
||||
Boolean useSSL = (Boolean) authInfoMap.get("ssl");
|
||||
|
||||
// connection
|
||||
JMXConnector jmxconn = null;
|
||||
try {
|
||||
Map<String, Object> environment = getAuthority(useSSL, username, password);
|
||||
jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl), environment);
|
||||
jmxconn.getMBeanServerConnection();
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("JMXCrawler", e);
|
||||
} finally {
|
||||
if (jmxconn != null) {
|
||||
try {
|
||||
jmxconn.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException {
|
||||
String hostIp = sensorConfig.getTarget().getConnection().getIp();
|
||||
int port = sensorConfig.getTarget().getConnection().getPort();
|
||||
|
||||
String jmxUrl = "service:jmx:rmi:///jndi/rmi://" + hostIp + ":" + port + "/jmxrmi";
|
||||
String username = (String) sensorConfig.getTarget().getAuth().get("id");
|
||||
String password = (String) sensorConfig.getTarget().getAuth().get("pw");
|
||||
boolean useSSL = sensorConfig.getTarget().getConnection().isSsl();
|
||||
|
||||
// connection
|
||||
MBeanServerConnection beanCon;
|
||||
JMXConnector jmxconn = null;
|
||||
try {
|
||||
Map<String, Object> environment = getAuthority(useSSL, username, password);
|
||||
jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl), environment);
|
||||
beanCon = jmxconn.getMBeanServerConnection();
|
||||
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
|
||||
List<ObjectName> objectNames = new LinkedList<ObjectName>();
|
||||
objectNames.add(null);
|
||||
ObjectName on = null;
|
||||
|
||||
for (Item item : sensorConfig.getItems()) {
|
||||
|
||||
ResultSet resultSet = ResultSet.newInstance(item);
|
||||
|
||||
// get object
|
||||
String query = item.getQueryInfo().getQuery();
|
||||
on = new ObjectName(query);
|
||||
Set<ObjectInstance> names = beanCon.queryMBeans(on, null);
|
||||
|
||||
List<Map<String, Object>> keys = (List<Map<String, Object>>) item.getQueryInfo().getExtend().get("aliases");
|
||||
|
||||
for (ObjectInstance name : names) {
|
||||
|
||||
Map<String, String> attrs = parseAttribute(beanCon, name.getObjectName());
|
||||
if (keys != null) {
|
||||
for (Map<String, Object> keyMap : keys) {
|
||||
String key = (String) keyMap.get("key");
|
||||
int index = (int) keyMap.get("index");
|
||||
String objectName = parseObjectName(name.toString(), key);
|
||||
String alias = item.getMappingInfo().getArrayColumns().get(index);
|
||||
attrs.put(alias, objectName);
|
||||
}
|
||||
}
|
||||
|
||||
resultSet.addRow(parse(attrs, resultSet.getMeta()));
|
||||
}
|
||||
|
||||
resultMap.putAll(resultSet.getData());
|
||||
}
|
||||
|
||||
return resultMap;
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("JMXCrawler", e);
|
||||
} finally {
|
||||
if (jmxconn != null) {
|
||||
try {
|
||||
jmxconn.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> parse(Map<String, String> dataMap, Map<String, Integer> meta) {
|
||||
|
||||
List<String> row = new ArrayList<>(Arrays.asList(new String[meta.size()]));
|
||||
for (Map.Entry<String, Integer> info : meta.entrySet()) {
|
||||
String data = dataMap.get(info.getKey());
|
||||
data = data.trim();
|
||||
row.set(info.getValue().intValue(), data);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
private Map<String, String> parseAttribute(MBeanServerConnection beanCon, ObjectName mbeanName)
|
||||
throws IntrospectionException, ReflectionException, InstanceNotFoundException, IOException,
|
||||
AttributeNotFoundException, MBeanException {
|
||||
|
||||
Map<String, String> returnMap = new HashMap<>();
|
||||
MBeanInfo info = beanCon.getMBeanInfo(mbeanName);
|
||||
|
||||
for (MBeanAttributeInfo attr : info.getAttributes()) {
|
||||
|
||||
if (!attr.isReadable()) {
|
||||
logCrawler(mbeanName, attr, "not readable");
|
||||
continue;
|
||||
}
|
||||
|
||||
// System.out.println("========================================================================");
|
||||
// System.out.println("PropertyListString"+mbeanName.getCanonicalKeyPropertyListString());
|
||||
// System.out.println("canonicaName="+mbeanName.getCanonicalName());
|
||||
// System.out.println(mbeanName.getDomain());
|
||||
// System.out.println(mbeanName.getKeyPropertyListString().compareTo("http"));
|
||||
// System.out.println("========================================================================");
|
||||
Object att = null;
|
||||
|
||||
try {
|
||||
att = beanCon.getAttribute(mbeanName, attr.getName());
|
||||
} catch (Exception e) {
|
||||
logCrawler(mbeanName, attr, "fail: " + e);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (att != null)
|
||||
returnMap.put(attr.getName(), att.toString());
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
private String parseObjectName(String s, String key) {
|
||||
|
||||
int start = s.indexOf("[");
|
||||
int end = s.lastIndexOf("]");
|
||||
s = s.substring(start + 1, end);
|
||||
|
||||
String[] slices = s.split(",");
|
||||
String returnData = "";
|
||||
for (String item : slices) {
|
||||
String[] itemSplit = item.split("=");
|
||||
if (itemSplit == null || itemSplit.length != 2) {
|
||||
continue;
|
||||
}
|
||||
if (itemSplit[0].equals(key)) {
|
||||
returnData = itemSplit[1];
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
private Map<String, Object> getAuthority(boolean useSSL, String username, String password) {
|
||||
Map<String, Object> environment = new HashMap<String, Object>();
|
||||
|
||||
if (username != null && username.length() != 0 && password != null && password.length() != 0) {
|
||||
String[] credent = new String[] { username, password };
|
||||
environment.put(JMXConnector.CREDENTIALS, credent);
|
||||
}
|
||||
|
||||
if (useSSL) {
|
||||
environment.put(Context.SECURITY_PROTOCOL, "ssl");
|
||||
SslRMIClientSocketFactory clientSocketFactory = new SslRMIClientSocketFactory();
|
||||
environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, clientSocketFactory);
|
||||
environment.put("com.sun.jndi.rmi.factory.socket", clientSocketFactory);
|
||||
}
|
||||
|
||||
return environment;
|
||||
}
|
||||
|
||||
private static void logCrawler(String name, String msg) {
|
||||
logger.log(Level.FINE, "crawler : '" + name + "': " + msg);
|
||||
}
|
||||
|
||||
private static void logCrawler(ObjectName mbeanName, MBeanAttributeInfo attr, String msg) {
|
||||
logCrawler(mbeanName + "'_'" + attr.getName(), msg);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.mongodb;
|
||||
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientOptions;
|
||||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MongoDBCrawler implements Crawler {
|
||||
@Override
|
||||
public String name() {
|
||||
return "MONGODB";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MongoDB Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auth(Map<String, Object> authInfoMap) throws OverflowException {
|
||||
throw new OverflowException("Not implemented", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException {
|
||||
MongoClient mongoClient = null;
|
||||
Map<String, String> returnMap = new HashMap<String, String>();
|
||||
|
||||
String dataBaseName = null;
|
||||
String statusCommand = null;
|
||||
|
||||
String targetIP = sensorConfig.getTarget().getConnection().getIp();
|
||||
int targetPort = sensorConfig.getTarget().getConnection().getPort();
|
||||
|
||||
try {
|
||||
|
||||
mongoClient = new MongoClient(new ServerAddress(targetIP, targetPort),
|
||||
MongoClientOptions.builder().serverSelectionTimeout(1000).connectTimeout(1000).socketTimeout(1000).build());
|
||||
|
||||
ResultSet rs = null;
|
||||
List<Item> items = sensorConfig.getItems();
|
||||
List<String> row = null;
|
||||
for (Item item : items) {
|
||||
|
||||
rs = ResultSet.newInstance(item);
|
||||
Map<String, Integer> metaMap = rs.getMeta();
|
||||
row = new ArrayList<>(Arrays.asList(new String[metaMap.size()]));
|
||||
|
||||
dataBaseName = (String) item.getQueryInfo().getExtend().get("dataBaseName");
|
||||
statusCommand = (String) item.getQueryInfo().getExtend().get("statusCommand");
|
||||
|
||||
MongoDatabase database = mongoClient.getDatabase(dataBaseName);
|
||||
Document serverStatus = database.runCommand(new Document(statusCommand, 1));
|
||||
|
||||
Map<String, String> re = (Map<String, String>) serverStatus.get(item.getQueryInfo().getQuery());
|
||||
|
||||
for (Map.Entry<String, Integer> info : metaMap.entrySet()) {
|
||||
row.set(info.getValue().intValue(), String.valueOf(re.get(info.getKey())));
|
||||
}
|
||||
|
||||
rs.addRow(row);
|
||||
returnMap.putAll(rs.getData());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("MongoDBCrawler", e);
|
||||
} finally {
|
||||
if (mongoClient != null) {
|
||||
mongoClient.close();
|
||||
}
|
||||
}
|
||||
return returnMap;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.redis;
|
||||
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class RedisCralwer implements Crawler {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(RedisCralwer.class.getName());
|
||||
|
||||
public RedisCralwer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "REDIS";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Redis Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auth(Map<String, Object> authIMap) throws OverflowException {
|
||||
throw new OverflowException("Not implemented", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException {
|
||||
String targetIP = sensorConfig.getTarget().getConnection().getIp();
|
||||
int targetPort = sensorConfig.getTarget().getConnection().getPort();
|
||||
|
||||
String authpw = (String) sensorConfig.getTarget().getAuth().get("authpw");
|
||||
|
||||
Jedis jedis = null;
|
||||
List<Item> items = sensorConfig.getItems();
|
||||
|
||||
try {
|
||||
jedis = new Jedis(targetIP, targetPort, false);
|
||||
if (authpw != null && !authpw.equals("")) {
|
||||
String code = jedis.auth(authpw);
|
||||
if (!code.equals("")) {
|
||||
// set error auth
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> returnMap = new HashMap<String, String>();
|
||||
|
||||
for (Item item : items) {
|
||||
ResultSet resultSet = ResultSet.newInstance(item);
|
||||
|
||||
String queryString = (String) item.getQueryInfo().getQuery();
|
||||
String info = jedis.info(queryString);
|
||||
Map<String, String> resultMap = (Map<String, String>) parseToMap(info).get(queryString);
|
||||
|
||||
resultSet.addRow(parse(resultMap, resultSet.getMeta()));
|
||||
|
||||
returnMap.putAll(resultSet.getData());
|
||||
}
|
||||
|
||||
return returnMap;
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("RedisCralwer", e);
|
||||
} finally {
|
||||
if (jedis != null) {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> parse(Map<String, String> dataMap, Map<String, Integer> meta) {
|
||||
|
||||
List<String> row = new ArrayList<>(Arrays.asList(new String[meta.size()]));
|
||||
for (Map.Entry<String, Integer> info : meta.entrySet()) {
|
||||
String data = dataMap.get(info.getKey());
|
||||
data = data.trim();
|
||||
row.set(info.getValue().intValue(), data);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
public Map<String, Object> parseToMap(String source) {
|
||||
String[] categorys = source.split("\r\n\r\n");
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
|
||||
for (String category : categorys) {
|
||||
|
||||
if (category.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
Map<String, String> sm = new HashMap<String, String>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.snmp;
|
||||
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Connection;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
import com.loafle.overflow.container.general.crawler.impl.snmp.version.SNMPv2c;
|
||||
import com.loafle.overflow.container.general.crawler.impl.snmp.version.SNMPv3;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
|
||||
import org.snmp4j.Snmp;
|
||||
import org.snmp4j.TransportMapping;
|
||||
import org.snmp4j.smi.Address;
|
||||
import org.snmp4j.transport.DefaultUdpTransportMapping;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SNMPCrawler implements Crawler {
|
||||
@Override
|
||||
public String name() {
|
||||
return "SNMP";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SNMP Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auth(Map<String, Object> authIMap) throws OverflowException {
|
||||
throw new OverflowException("Not implemented", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException {
|
||||
Snmp snmp = null;
|
||||
TransportMapping<? extends Address> transport = null;
|
||||
|
||||
Map<String, String> returnMap = new HashMap<String, String>();
|
||||
|
||||
try {
|
||||
transport = new DefaultUdpTransportMapping();
|
||||
snmp = new Snmp(transport);
|
||||
transport.listen();
|
||||
|
||||
List<Item> items = sensorConfig.getItems();
|
||||
String[] oids = null;
|
||||
|
||||
Map<String, String> snmpResultMap = null;
|
||||
for (Item item : items) {
|
||||
oids = new String[item.getKeys().size()];
|
||||
for (int i = 0; i < item.getKeys().size(); i++) {
|
||||
oids[i] = item.getKeys().get(i).getKey();
|
||||
}
|
||||
|
||||
snmpResultMap = getSNMPV(snmp, sensorConfig, oids);
|
||||
returnMap.putAll(convertResultSet(snmpResultMap, item).getData());
|
||||
}
|
||||
return returnMap;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("RedisCralwer", e);
|
||||
} finally {
|
||||
if (snmp != null) {
|
||||
try {
|
||||
snmp.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (transport != null) {
|
||||
try {
|
||||
transport.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getSNMPV(Snmp snmp, SensorConfig sensorConfig, String[] oids) throws Exception {
|
||||
|
||||
String targetVer = (String) sensorConfig.getTarget().getAuth().get("version");
|
||||
switch (targetVer) {
|
||||
case "v2c":
|
||||
return getV2c(snmp, sensorConfig, oids);
|
||||
case "v3":
|
||||
return getV3(snmp, sensorConfig, oids);
|
||||
default:
|
||||
new Exception("Unknown SNMP protocol : " + targetVer).printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, String> getV2c(Snmp snmp, SensorConfig sensorConfig, String[] oids) throws Exception {
|
||||
|
||||
SNMPv2c snmpV2 = new SNMPv2c(snmp);
|
||||
|
||||
Map<String, Object> authInfo = sensorConfig.getTarget().getAuth();
|
||||
Connection connInfo = sensorConfig.getTarget().getConnection();
|
||||
|
||||
String ip = connInfo.getIp();
|
||||
int port = connInfo.getPort();
|
||||
String community = (String) authInfo.get("community");
|
||||
|
||||
return snmpV2.get(ip, port, community, oids);
|
||||
}
|
||||
|
||||
private Map<String, String> getV3(Snmp snmp, SensorConfig sensorConfig, String[] oids) throws Exception {
|
||||
SNMPv3 snmpV3 = new SNMPv3(snmp);
|
||||
|
||||
Map<String, Object> authInfo = sensorConfig.getTarget().getAuth();
|
||||
Connection connInfo = sensorConfig.getTarget().getConnection();
|
||||
|
||||
String ip = connInfo.getIp();
|
||||
int port = connInfo.getPort();
|
||||
// String method = sensorConfig.get;
|
||||
|
||||
String user = (String) authInfo.get("user");
|
||||
String authType = (String) authInfo.get("authType");
|
||||
String authPass = (String) authInfo.get("authPass");
|
||||
String privType = (String) authInfo.get("privType");
|
||||
String privPass = (String) authInfo.get("privPass");
|
||||
|
||||
return snmpV3.get(ip, port, user, authType, authPass, privType, privPass, oids);
|
||||
}
|
||||
|
||||
protected ResultSet convertResultSet(Map<String, String> map, Item item) {
|
||||
|
||||
ResultSet rs = ResultSet.newInstance(item);
|
||||
|
||||
List<String> row = new ArrayList<>(Arrays.asList(new String[map.size()]));
|
||||
|
||||
Map<String, Integer> metaMap = rs.getMeta();
|
||||
|
||||
for (Map.Entry<String, Integer> info : metaMap.entrySet()) {
|
||||
row.set(info.getValue().intValue(), map.get(info.getKey()));
|
||||
}
|
||||
rs.addRow(row);
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.snmp.version;
|
||||
|
||||
import org.snmp4j.PDU;
|
||||
import org.snmp4j.Snmp;
|
||||
import org.snmp4j.Target;
|
||||
import org.snmp4j.event.ResponseEvent;
|
||||
import org.snmp4j.smi.OID;
|
||||
import org.snmp4j.smi.VariableBinding;
|
||||
import org.snmp4j.util.TreeEvent;
|
||||
import org.snmp4j.util.TreeUtils;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by insanity on 17. 4. 10.
|
||||
*/
|
||||
public abstract class SNMP {
|
||||
|
||||
protected Map<String, String> 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<String, String> result = new LinkedHashMap<String, String>();
|
||||
for (VariableBinding varBinding : responsePDU.getVariableBindings()) {
|
||||
if (varBinding == null) {
|
||||
continue;
|
||||
}
|
||||
result.put(varBinding.getOid().toString(), varBinding.getVariable().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Map<String, String> walk(String oidStr, Target target, TreeUtils treeUtils) throws Exception {
|
||||
OID oid = new OID(oidStr);
|
||||
List<TreeEvent> events = treeUtils.getSubtree(target, oid);
|
||||
|
||||
if(events == null || events.size() == 0){
|
||||
throw new Exception("No data.");
|
||||
}
|
||||
|
||||
Map<String, String> result = new LinkedHashMap<String, String>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.snmp.version;
|
||||
|
||||
import org.snmp4j.CommunityTarget;
|
||||
import org.snmp4j.PDU;
|
||||
import org.snmp4j.Snmp;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
import org.snmp4j.smi.*;
|
||||
import org.snmp4j.util.DefaultPDUFactory;
|
||||
import org.snmp4j.util.TreeUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SNMPv2c extends SNMP {
|
||||
|
||||
private Snmp snmp = null;
|
||||
|
||||
public SNMPv2c(Snmp snmp) {
|
||||
this.snmp = snmp;
|
||||
}
|
||||
|
||||
private CommunityTarget getTarget(String addr, int port, String community) {
|
||||
UdpAddress address = new UdpAddress(addr + "/" + port);
|
||||
CommunityTarget target = new CommunityTarget();
|
||||
target.setCommunity(new OctetString(community));
|
||||
target.setAddress(address);
|
||||
target.setRetries(2);
|
||||
target.setTimeout(5000);
|
||||
target.setVersion(SnmpConstants.version2c);
|
||||
return target;
|
||||
}
|
||||
|
||||
public Boolean validate(String addr, int port, String community) throws Exception {
|
||||
String testOid = "1.3.6.1.2.1.1.3.0";
|
||||
Map<String, String> result = this.get(addr, port, community, new String[]{testOid});
|
||||
if (result.get(testOid) != null) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<String, String> walk(String addr, int port, String community, String oidStr) throws Exception {
|
||||
|
||||
TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory());
|
||||
CommunityTarget target = getTarget(addr, port, community);
|
||||
|
||||
return super.walk(oidStr, target, treeUtils);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> get(String addr, int port, String community, String[] oids) throws Exception {
|
||||
|
||||
CommunityTarget target = getTarget(addr, port, community);
|
||||
|
||||
PDU pdu = new PDU();
|
||||
for (String oid : oids) {
|
||||
pdu.add(new VariableBinding(new OID(oid)));
|
||||
}
|
||||
pdu.setType(PDU.GET);
|
||||
pdu.setRequestID(new Integer32(1));
|
||||
|
||||
return super.get(this.snmp, pdu, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.snmp.version;
|
||||
|
||||
import org.snmp4j.*;
|
||||
import org.snmp4j.mp.MPv3;
|
||||
import org.snmp4j.mp.MessageProcessingModel;
|
||||
import org.snmp4j.mp.SnmpConstants;
|
||||
import org.snmp4j.security.*;
|
||||
import org.snmp4j.smi.*;
|
||||
import org.snmp4j.transport.DefaultUdpTransportMapping;
|
||||
import org.snmp4j.util.PDUFactory;
|
||||
import org.snmp4j.util.TreeUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by insanity on 17. 4. 10.
|
||||
*/
|
||||
public class SNMPv3 extends SNMP {
|
||||
|
||||
private Snmp snmp = null;
|
||||
|
||||
public SNMPv3(Snmp snmp) {
|
||||
this.snmp = snmp;
|
||||
}
|
||||
|
||||
public Boolean validate(String addr, int port, String user, String authType, String authPass, String privType, String privPass) throws Exception {
|
||||
String testOid = "1.3.6.1.2.1.1.3.0";
|
||||
Map<String, String> result = this.get(addr, port, user, authType, authPass, privType, privPass, new String[]{testOid});
|
||||
if (result.get(testOid) != null) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<String, String> walk(String addr, int port, String user, String authType, String authPass, String privType, String privPass, String oidStr)
|
||||
throws Exception {
|
||||
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
|
||||
SecurityModels.getInstance().addSecurityModel(usm);
|
||||
|
||||
UsmUser usmUser = getUser(user, authType, authPass, privType, privPass);
|
||||
this.snmp.getUSM().addUser(new OctetString(user), usmUser);
|
||||
|
||||
|
||||
TreeUtils treeUtils = new TreeUtils(this.snmp, new PDUFactory() {
|
||||
public PDU createPDU(Target target) {
|
||||
ScopedPDU sp = new ScopedPDU();
|
||||
sp.setRequestID(new Integer32(1));
|
||||
return sp;
|
||||
}
|
||||
|
||||
public PDU createPDU(MessageProcessingModel messageProcessingModel) {
|
||||
return new ScopedPDU();
|
||||
}
|
||||
});
|
||||
|
||||
Target target = getTarget(addr, port, usmUser);
|
||||
return super.walk(oidStr, target, treeUtils);
|
||||
}
|
||||
|
||||
public Map<String, String> get(String addr, int port, String user, String authType, String authPass, String privType, String privPass, String[] oids)
|
||||
throws Exception {
|
||||
|
||||
TransportMapping<? extends Address> transport = new DefaultUdpTransportMapping();
|
||||
Snmp snmp = new Snmp(transport);
|
||||
transport.listen();
|
||||
|
||||
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
|
||||
SecurityModels.getInstance().addSecurityModel(usm);
|
||||
|
||||
UsmUser usmUser = getUser(user, authType, authPass, privType, privPass);
|
||||
this.snmp.getUSM().addUser(new OctetString(user), usmUser);
|
||||
|
||||
PDU pdu = new ScopedPDU();
|
||||
for (String oid : oids) {
|
||||
pdu.addOID(new VariableBinding(new OID(oid)));
|
||||
}
|
||||
pdu.setType(PDU.GET);
|
||||
pdu.setRequestID(new Integer32(1));
|
||||
|
||||
Target target = getTarget(addr, port, usmUser);
|
||||
|
||||
return super.get(snmp, pdu, target);
|
||||
}
|
||||
|
||||
private UserTarget getTarget(String addr, int port, UsmUser user) {
|
||||
|
||||
UdpAddress address = new UdpAddress(addr + "/" + port);
|
||||
UserTarget target = new UserTarget();
|
||||
target.setAddress(address);
|
||||
target.setRetries(2);
|
||||
target.setTimeout(5000);
|
||||
target.setVersion(SnmpConstants.version3);
|
||||
target.setSecurityModel(user.getSecurityModel());
|
||||
|
||||
int secLv;
|
||||
OID autyType = user.getAuthenticationProtocol();
|
||||
OID privType = user.getPrivacyProtocol();
|
||||
if (autyType != null && privType != null) {
|
||||
secLv = SecurityLevel.AUTH_PRIV;
|
||||
}else if (autyType != null && privType == null) {
|
||||
secLv = SecurityLevel.AUTH_NOPRIV;
|
||||
}else {
|
||||
secLv = SecurityLevel.NOAUTH_NOPRIV;
|
||||
}
|
||||
target.setSecurityLevel(secLv);
|
||||
target.setSecurityName(new OctetString(user.getSecurityName()));
|
||||
return target;
|
||||
}
|
||||
|
||||
private UsmUser getUser(String user, String authType, String authPass, String privType, String privPass) {
|
||||
OctetString octetUser = new OctetString(user);
|
||||
OctetString octetAuthPass = authPass.equals("") ? null : new OctetString(authPass);
|
||||
OctetString octetPrivPass = privPass.equals("") ? null : new OctetString(privPass);
|
||||
|
||||
UsmUser usmUser = new UsmUser(octetUser, getAuthOID(authType), octetAuthPass, getPrivOID(privType), octetPrivPass);
|
||||
return usmUser;
|
||||
}
|
||||
|
||||
private OID getAuthOID(String authType) {
|
||||
OID authOID = null;
|
||||
switch(authType) {
|
||||
case "":
|
||||
authOID = null;
|
||||
break;
|
||||
case "MD5":
|
||||
authOID = AuthMD5.ID;
|
||||
break;
|
||||
case "SHA":
|
||||
authOID = AuthSHA.ID;
|
||||
break;
|
||||
}
|
||||
return authOID;
|
||||
}
|
||||
|
||||
private OID getPrivOID(String privType) {
|
||||
OID privOID = null;
|
||||
switch(privType) {
|
||||
case "":
|
||||
privOID = null;
|
||||
break;
|
||||
case "DES":
|
||||
privOID = PrivDES.ID;
|
||||
break;
|
||||
case "AES":
|
||||
privOID = PrivAES128.ID;
|
||||
break;
|
||||
}
|
||||
return privOID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
||||
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.crawler.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class WMICrawler implements Crawler {
|
||||
@Override
|
||||
public String name() {
|
||||
return "WMI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WMI Crawler";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auth(Map<String, Object> authIMap) throws OverflowException {
|
||||
throw new OverflowException("Not implemented", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException {
|
||||
try {
|
||||
return WMICrawlerOS.getInstance().process(sensorConfig);
|
||||
} catch (Exception e) {
|
||||
throw new OverflowException("WMICrawler", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
public class WMICrawlerLinux extends WMICrawlerOS {
|
||||
private final String DELIMITER = "||";
|
||||
private final String DELIMITER_SPLIT = "\\|\\|";
|
||||
|
||||
public ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception {
|
||||
|
||||
List<String> argList = createCommand(sensorConfig, item);
|
||||
|
||||
String result = execute(argList.toArray(new String[argList.size()]));
|
||||
|
||||
ResultSet ofResultSet = parseResult(result, item);
|
||||
|
||||
return ofResultSet;
|
||||
}
|
||||
|
||||
public List<String> createCommand(SensorConfig sensorConfig, Item item) throws Exception {
|
||||
|
||||
String id = (String) sensorConfig.getTarget().getAuth().get("id");
|
||||
String pw = (String) sensorConfig.getTarget().getAuth().get("pw");
|
||||
String nameSpace = (String) item.getQueryInfo().getExtend().get("nameSpace");
|
||||
String ip = sensorConfig.getTarget().getConnection().getIp();
|
||||
String query = item.getQueryInfo().getQuery();
|
||||
|
||||
String wmicPath = (String) item.getQueryInfo().getExtend().get("wmicPath");
|
||||
//FIXME:: where is wmic ??
|
||||
List<String> argList = new ArrayList<String>();
|
||||
|
||||
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<String, Integer> metaMap = ofResultSet.getMeta();
|
||||
|
||||
List<String> columns = null;
|
||||
Map<String, String> tempMap = new HashMap<String, String>();
|
||||
List<String> 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<String, Integer> 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<String,String> map = new HashMap<>();
|
||||
|
||||
// map.put("ERROR", errStr);
|
||||
// resultMapList.add(map);
|
||||
// return resultMapList;
|
||||
retErrStr = errStr;
|
||||
}
|
||||
return retErrStr;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
public abstract class WMICrawlerOS {
|
||||
|
||||
private static WMICrawlerOS wmiCrawlerOS = null;
|
||||
|
||||
public static WMICrawlerOS getInstance() {
|
||||
|
||||
if(WMICrawlerOS.wmiCrawlerOS == null) {
|
||||
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
if(os.indexOf("linux") >= 0) {
|
||||
WMICrawlerOS.wmiCrawlerOS = new WMICrawlerLinux();
|
||||
} else if(os.indexOf("") >= 0) {
|
||||
WMICrawlerOS.wmiCrawlerOS = new WMICrawlerWindows();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return WMICrawlerOS.wmiCrawlerOS;
|
||||
}
|
||||
|
||||
public Map<String, String> process(SensorConfig sensorConfig) throws Exception {
|
||||
Map<String, String> returnMap = new HashMap<String, String>();
|
||||
|
||||
ResultSet ofResultSet = null;
|
||||
for(int cIndexI = 0 ; cIndexI < sensorConfig.getItems().size() ; ++cIndexI) {
|
||||
|
||||
ofResultSet = processWMI(sensorConfig, sensorConfig.getItems().get(cIndexI));
|
||||
returnMap.putAll(ofResultSet.getData());
|
||||
}
|
||||
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
public abstract ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception ;
|
||||
}
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.EnumVariant;
|
||||
import com.jacob.com.Variant;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WMICrawlerWindows extends WMICrawlerOS {
|
||||
|
||||
public ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception {
|
||||
|
||||
String query = "";
|
||||
ActiveXComponent wmiconnect = null;
|
||||
ResultSet ofResultSet = null;
|
||||
|
||||
query = item.getQueryInfo().getQuery();
|
||||
wmiconnect = connectServer(sensorConfig, item);
|
||||
|
||||
Variant vQuery = new Variant(query);
|
||||
Variant vCollection = wmiconnect.invoke("ExecQuery", vQuery);
|
||||
wmiconnect.safeRelease();
|
||||
vQuery.safeRelease();
|
||||
|
||||
Dispatch dConnection = vCollection.toDispatch();
|
||||
vCollection.safeRelease();
|
||||
// int count = getCount(dConnection);
|
||||
|
||||
EnumVariant enumVariant = new EnumVariant(dConnection);
|
||||
dConnection.safeRelease();
|
||||
|
||||
ofResultSet = getResultSet(enumVariant, item);
|
||||
enumVariant.safeRelease();
|
||||
return ofResultSet;
|
||||
}
|
||||
|
||||
protected ResultSet getResultSet(EnumVariant enumVariant, Item citem) {
|
||||
|
||||
ResultSet ofResultSet = ResultSet.newInstance(citem);
|
||||
|
||||
Variant vItem = null;
|
||||
Dispatch item = null;
|
||||
|
||||
Variant vValue = null;
|
||||
String value = null;
|
||||
|
||||
List<String> row = null;
|
||||
Map<String, Integer> metaMap = ofResultSet.getMeta();
|
||||
|
||||
while (enumVariant.hasMoreElements()) {
|
||||
|
||||
row = new ArrayList<>(Arrays.asList(new String[metaMap.size()]));
|
||||
|
||||
vItem = enumVariant.nextElement();
|
||||
item = vItem.toDispatch();
|
||||
|
||||
for (Map.Entry<String, Integer> 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<String, String> 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<String, String> 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<String> getColumns(Dispatch item) {
|
||||
|
||||
List<String> columns = new ArrayList<String>();
|
||||
|
||||
Variant propertyesa = Dispatch.call(item, "Properties_");
|
||||
|
||||
Dispatch disProperty = propertyesa.toDispatch();
|
||||
|
||||
Variant newEnum = Dispatch.call(disProperty, "_NewEnum");
|
||||
|
||||
propertyesa.safeRelease();
|
||||
disProperty.safeRelease();
|
||||
|
||||
EnumVariant enumv = newEnum.toEnumVariant();
|
||||
|
||||
newEnum.safeRelease();
|
||||
|
||||
Variant vElem = null;
|
||||
Dispatch disElem = null;
|
||||
Variant vName = null;
|
||||
|
||||
while (enumv.hasMoreElements()) {
|
||||
vElem = enumv.nextElement();
|
||||
disElem = vElem.toDispatch();
|
||||
|
||||
vName = Dispatch.call(disElem, "Name");
|
||||
String vs = vName.toString();
|
||||
|
||||
columns.add(vs);
|
||||
|
||||
disElem.safeRelease();
|
||||
vElem.safeRelease();
|
||||
vName.safeRelease();
|
||||
}
|
||||
|
||||
enumv.safeRelease();
|
||||
return columns;
|
||||
}
|
||||
|
||||
protected int getCount(Dispatch d) {
|
||||
|
||||
Variant c = Dispatch.call(d, "Count");
|
||||
|
||||
int retInt = Integer.valueOf(c.toString());
|
||||
|
||||
c.safeRelease();
|
||||
|
||||
return retInt;
|
||||
}
|
||||
|
||||
protected ActiveXComponent connectServer(SensorConfig sensorConfig, Item item) {
|
||||
|
||||
String id = (String) sensorConfig.getTarget().getAuth().get("id");
|
||||
String pw = (String) sensorConfig.getTarget().getAuth().get("pw");
|
||||
String nameSpace = (String) item.getQueryInfo().getExtend().get("nameSpace");
|
||||
// String query = (String)sensorConfig.get.get("query");
|
||||
|
||||
String ip = sensorConfig.getTarget().getConnection().getIp();
|
||||
|
||||
ActiveXComponent wmi = null;
|
||||
wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
|
||||
|
||||
Variant vIp = new Variant(ip);
|
||||
Variant vNs = new Variant(nameSpace);
|
||||
Variant vId = new Variant(id);
|
||||
Variant vPw = new Variant(pw);
|
||||
|
||||
Variant conRet = wmi.invoke("ConnectServer", vIp, vNs, vId, vPw);
|
||||
|
||||
vIp.safeRelease();
|
||||
vNs.safeRelease();
|
||||
vId.safeRelease();
|
||||
vPw.safeRelease();
|
||||
|
||||
Dispatch disConret = conRet.toDispatch();
|
||||
|
||||
ActiveXComponent wmiconnect = new ActiveXComponent(disConret);
|
||||
disConret.safeRelease();
|
||||
|
||||
wmi.safeRelease();
|
||||
conRet.safeRelease();
|
||||
|
||||
return wmiconnect;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.loafle.overflow.container.general.server;
|
||||
|
||||
import com.loafle.overflow.container.server.ContainerServer;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class GeneralContainerServer extends ContainerServer {
|
||||
|
||||
public GeneralContainerServer() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.loafle.overflow.container.general.util;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class Primitives {
|
||||
/** A map from primitive types to their corresponding wrapper types. */
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPE;
|
||||
/** A map from wrapper types to their corresponding primitive types. */
|
||||
private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPE;
|
||||
|
||||
static {
|
||||
Map<Class<?>, Class<?>> primToWrap = new HashMap<Class<?>, Class<?>>(16);
|
||||
Map<Class<?>, Class<?>> wrapToPrim = new HashMap<Class<?>, Class<?>>(16);
|
||||
|
||||
add(primToWrap, wrapToPrim, boolean.class, Boolean.class);
|
||||
add(primToWrap, wrapToPrim, byte.class, Byte.class);
|
||||
add(primToWrap, wrapToPrim, char.class, Character.class);
|
||||
add(primToWrap, wrapToPrim, double.class, Double.class);
|
||||
add(primToWrap, wrapToPrim, float.class, Float.class);
|
||||
add(primToWrap, wrapToPrim, int.class, Integer.class);
|
||||
add(primToWrap, wrapToPrim, long.class, Long.class);
|
||||
add(primToWrap, wrapToPrim, short.class, Short.class);
|
||||
add(primToWrap, wrapToPrim, void.class, Void.class);
|
||||
|
||||
PRIMITIVE_TO_WRAPPER_TYPE = Collections.unmodifiableMap(primToWrap);
|
||||
WRAPPER_TO_PRIMITIVE_TYPE = Collections.unmodifiableMap(wrapToPrim);
|
||||
}
|
||||
|
||||
private static void add(Map<Class<?>, Class<?>> forward,
|
||||
Map<Class<?>, Class<?>> backward, Class<?> key, Class<?> value) {
|
||||
forward.put(key, value);
|
||||
backward.put(value, key);
|
||||
}
|
||||
/**
|
||||
* Returns true if this type is a primitive.
|
||||
*/
|
||||
public static boolean isPrimitive(Type type) {
|
||||
return PRIMITIVE_TO_WRAPPER_TYPE.containsKey(type);
|
||||
}
|
||||
|
||||
}
|
0
src/main/resources/application.properties
Normal file
0
src/main/resources/application.properties
Normal file
|
@ -0,0 +1,10 @@
|
|||
package com.loafle.overflow.container.general.crawler;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
public abstract class CrawlerTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class DatabaseCrawlerTest extends CrawlerTest {
|
||||
// //MySQL
|
||||
// info.setUrl("jdbc:mysql://192.168.1.215:3306"); // ?useSSL=true&verifyServerCertificate=false
|
||||
// info.setId("root");
|
||||
// info.setPw("qwe123");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("show session status");
|
||||
// //MSSQL
|
||||
// info.setUrl("jdbc:sqlserver://192.168.1.103:1433;"); //encrypt=false;trustServerCertificate=true"
|
||||
// info.setId("sa");
|
||||
// info.setPw("qwer5795");
|
||||
// info.setSSL(true);
|
||||
// info.setQuery("select * from master.dbo.sysprocesses");
|
||||
// //PGSQL
|
||||
// info.setUrl("jdbc:postgresql://192.168.1.107:5432/postgres");
|
||||
// info.setId("postgres");
|
||||
// info.setPw("!@#$qwer1234");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("select * from pg_stat_activity");
|
||||
// //Oracle
|
||||
// info.setUrl("jdbc:oracle:thin:@192.168.1.30:1521/oracle.loafle.com");
|
||||
// info.setId("sys as sysdba");
|
||||
// info.setPw("qwer5795QWER");
|
||||
// info.setSSL(false);
|
||||
// info.setQuery("select * from v$sysstat");
|
||||
protected SensorConfig getSensorConfig(String path) throws IOException {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource(path).getFile();
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
return c;
|
||||
}
|
||||
|
||||
protected void print(String s, Map<String, String> m) {
|
||||
|
||||
System.out.println(s);
|
||||
|
||||
for (Map.Entry<String, String> item : m.entrySet()) {
|
||||
System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.mysql;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MySQLCrawlerTest extends DatabaseCrawlerTest {
|
||||
@Test
|
||||
public void testMySQL() throws Exception {
|
||||
Map<String, String> result = new MySQLCrawler().get(getSensorConfig("config/mysql/mysql-test.json"));
|
||||
print("MySQL row", result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.oracle;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class OracleCrawlerTest extends DatabaseCrawlerTest {
|
||||
@Ignore
|
||||
@Test
|
||||
public void testMySQL() throws Exception {
|
||||
Map<String, String> result = new OracleCrawler().get(getSensorConfig("config/oracle/oracle-test.json"));
|
||||
print("Oracle row", result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.postgresql;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PostgreSQLCrawlerTest extends DatabaseCrawlerTest {
|
||||
@Ignore
|
||||
@Test
|
||||
public void testPostgreSQL() throws Exception {
|
||||
Map<String, String> result = new PostgreSQLCrawler().get(getSensorConfig("config/postgresql/postgresql.json"));
|
||||
print("PostgreSQL", result);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.database.sqlserver;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.impl.database.DatabaseCrawlerTest;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SQLServerCrawlerTest extends DatabaseCrawlerTest {
|
||||
@Ignore
|
||||
@Test
|
||||
public void testConnection_Count() throws Exception {
|
||||
Map<String, String> result = new SQLServerCrawler().get(getSensorConfig("config/sqlserver/sqlserver_connection_count.json"));
|
||||
print("SQL Server Connection count", result);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testMultiKeyArray() throws Exception {
|
||||
Map<String, String> result = new SQLServerCrawler().get(getSensorConfig("config/sqlserver/sqlserver_multiple_key_array.json"));
|
||||
print("SQL Server MultiArray", result);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.jmx;
|
||||
|
||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||
|
||||
public class JMXCrawlerTest extends CrawlerTest {
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.jmx.tomcat;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawler;
|
||||
import com.loafle.overflow.container.general.crawler.impl.jmx.JMXCrawlerTest;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TomcatCrawlerTest extends JMXCrawlerTest {
|
||||
|
||||
@Test
|
||||
public void testSum() {
|
||||
assertEquals(1, 1);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void TestDoCrawler() throws Exception {
|
||||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
URL url = classLoader.getResource("config/tomcat/");
|
||||
String filePath = classLoader.getResource("config/tomcat/example1.json").getFile();
|
||||
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
JMXCrawler cr = new JMXCrawler();
|
||||
Map<String, String> result = cr.get(c);
|
||||
|
||||
print("", result);
|
||||
}
|
||||
|
||||
//keytool -export -alias alias_name -keystore path_to_keystore_file -rfc -file path_to_certificate_file
|
||||
private void print(String s, Map<String, String> m) {
|
||||
System.out.println(s);
|
||||
|
||||
for (Map.Entry<String, String> item : m.entrySet()) {
|
||||
System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testParseObject() {
|
||||
String s = "org.apache.catalina.mbeans.ConnectorMBean[Catalina:type=Connector,port=8080]";
|
||||
|
||||
int start = s.indexOf("[");
|
||||
int end = s.lastIndexOf("]");
|
||||
s = s.substring(start + 1, end);
|
||||
assertEquals("Catalina:type=Connector,port=8080", s);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.mongodb;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class MongoDBCrawlerTest extends CrawlerTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void TestCollectMetric() throws Exception {
|
||||
|
||||
// read test resources config/example.json
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/mongodb/example.json").getFile();
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
MongoDBCrawler cr = new MongoDBCrawler();
|
||||
Map<String, String> m = cr.get(c);
|
||||
|
||||
for (Map.Entry<String, String> item : m.entrySet()) {
|
||||
System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue());
|
||||
}
|
||||
|
||||
// assertEquals(6, m.size());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.redis;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class RedisCralwerTest extends CrawlerTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void collectMetric() throws Exception {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/redis/example.json").getFile();
|
||||
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig c = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
RedisCralwer rc = new RedisCralwer();
|
||||
print("", rc.get(c));
|
||||
}
|
||||
|
||||
private void print(String s, Map<String, String> m) {
|
||||
|
||||
System.out.println(s);
|
||||
|
||||
for (Map.Entry<String, String> item : m.entrySet()) {
|
||||
System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.snmp;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SNMPCrawlerTest extends CrawlerTest {
|
||||
/***
|
||||
* v2c test info
|
||||
* private static String addr = "192.168.1.215";
|
||||
* private static String port = "161";
|
||||
* private static String community = "public";
|
||||
*
|
||||
* v3 test info
|
||||
* loafle MD5 "qwer5795" DES "qweqwe123" : AUTHPRIV
|
||||
* loafle2 SHA "qwer5795" AES "qweqwe123" : AUTHPRIV
|
||||
* loafle3 MD5 "qwer5795" : AUTHNOPRIV
|
||||
* loafle4 :NOAUTHNOPRIV
|
||||
*/
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSNMP3() throws Exception {
|
||||
SNMPCrawler c = new SNMPCrawler();
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/snmp/examplev3.json").getFile();
|
||||
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
Map<String, String> result = c.get(config);
|
||||
|
||||
printResult(result);
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSNMP2c() throws Exception {
|
||||
SNMPCrawler c = new SNMPCrawler();
|
||||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/snmp/examplev2.json").getFile();
|
||||
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
Map<String, String> result = c.get(config);
|
||||
|
||||
printResult(result);
|
||||
}
|
||||
|
||||
private void printResult(Map<String, String> resultList) {
|
||||
for (Map.Entry<String, String> item : resultList.entrySet()) {
|
||||
System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,294 @@
|
|||
package com.loafle.overflow.container.general.crawler.impl.wmi;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.loafle.overflow.container.general.crawler.CrawlerTest;
|
||||
import com.loafle.overflow.model.sensorconfig.ResultSet;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class WMICrawlerTest extends CrawlerTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testLinuxExe() throws Exception {
|
||||
|
||||
String command = "/home/snoop/temp/wmic";
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder(command, "-U", "administrator%dbseogns18", "//192.168.1.106",
|
||||
"SELECT Caption FROM Win32_LogicalDisk", "--namespace=root/cimv2", "--delimiter=||");
|
||||
Process process = builder.start();
|
||||
|
||||
byte[] msg = new byte[1024];
|
||||
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
while (process.getInputStream().read(msg) > 0) {
|
||||
buf.append(new String(msg));
|
||||
Arrays.fill(msg, (byte) 0);
|
||||
}
|
||||
|
||||
System.out.println(buf.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWMI() throws Exception {
|
||||
WMICrawler wmiCrawler = new WMICrawler();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
// String id = "administrator";
|
||||
// String pw = "!@#$qwer1234";
|
||||
// String nameSpace = "root/cimv2";
|
||||
// String query = "select * from Win32_OperatingSystem";
|
||||
// String ip = "192.168.1.1";
|
||||
|
||||
// map.put("id", "administrator");
|
||||
// map.put("pw", "!@#$qwer1234");
|
||||
// map.put("nameSpace", "root/cimv2");
|
||||
// map.put("query", "select * from Win32_OperatingSystem");
|
||||
// map.put("ip", "192.168.1.1");
|
||||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/wmi").getFile();
|
||||
System.out.println(filePath);
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
// Config c = mapper.readValue(new File(classLoader.getResource("config").getFile()),Config.class);
|
||||
|
||||
// List<Map<String, String>> resultList = (List<Map<String, String>>)wmiCrawler.getInternal(map);
|
||||
//
|
||||
//
|
||||
// for( Map<String,String> rMap : resultList) {
|
||||
// for( String key : rMap.keySet() ){
|
||||
// System.out.println( String.format("key : %s ||| value : %s", key, rMap.get(key)) );
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOS() {
|
||||
System.out.println(System.getProperty("os.name"));
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testConfig() throws IOException {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/wmi/example.json").getFile();
|
||||
System.out.println(filePath);
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
|
||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
System.out.println(config);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testWMIJson() throws Exception {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/wmi/meta/meta_network.json").getFile();
|
||||
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("id", "administrator");
|
||||
// map.put("pw", "!@#$qwer1234");
|
||||
|
||||
// c.getTarget().setAuth(map);
|
||||
|
||||
// c.getTarget().getAuth().put("id", "administrator");
|
||||
// c.getTarget().getAuth().put("pw", "!@#$qwer1234");
|
||||
|
||||
WMICrawler wmiCrawler = new WMICrawler();
|
||||
|
||||
Map<String, String> resultList = wmiCrawler.get(config);
|
||||
|
||||
PrintResultList(resultList);
|
||||
// for(int indexI = 0 ; indexI < resultList.size(); ++indexI) {
|
||||
// Map<String,String> resultMap = resultList.get(indexI).getData();
|
||||
// System.out.println("============================================");
|
||||
// for( String key : resultMap.keySet() ){
|
||||
// System.out.println( String.format("key : %s ||| value : %s", key, resultMap.get(key)) );
|
||||
// }
|
||||
// System.out.println("============================================");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public void PrintResultList(Map<String, String> m) {
|
||||
for (Map.Entry<String, String> item : m.entrySet()) {
|
||||
System.out.println("key=" + item.getKey() + " ||||||||||| value=" + item.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testMetaProcess() throws Exception {
|
||||
|
||||
// get targetinfo
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String filePath = classLoader.getResource("config/wmi/test.json").getFile();
|
||||
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(filePath)));
|
||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
|
||||
List<SensorConfig> metaConfigList = loadMetaConfig();
|
||||
|
||||
Map<String, String> retlist = new HashMap<>();
|
||||
WMICrawlerOS os = WMICrawlerOS.getInstance();
|
||||
ResultSet ofResultSet = null;
|
||||
for (SensorConfig metaConfig : metaConfigList) {
|
||||
|
||||
for (int indexI = 0; indexI < metaConfig.getItems().size(); ++indexI) {
|
||||
ofResultSet = os.processWMI(config, metaConfig.getItems().get(indexI));
|
||||
if (ofResultSet != null) {
|
||||
retlist.putAll(ofResultSet.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrintResultList(retlist);
|
||||
|
||||
}
|
||||
|
||||
public List<SensorConfig> 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<SensorConfig> retList = new ArrayList<>();
|
||||
|
||||
for (String fi : metaFiles) {
|
||||
if (fi.indexOf("meta_") > -1) {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(new File(path + "/" + fi)));
|
||||
SensorConfig config = new Gson().fromJson(inputStreamReader, SensorConfig.class);
|
||||
if (config != null) {
|
||||
retList.add(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInt() {
|
||||
|
||||
Integer a = 1;
|
||||
|
||||
aaa(a);
|
||||
|
||||
System.out.println(a);
|
||||
|
||||
}
|
||||
|
||||
public void aaa(Integer a) {
|
||||
++a;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testString() {
|
||||
|
||||
String str = "cpu[].usage.system";
|
||||
|
||||
int idx = str.indexOf("[");
|
||||
int arrIdx = 0;
|
||||
|
||||
String ret = "";
|
||||
ret += str.substring(0, idx + 1);
|
||||
ret += String.valueOf(arrIdx);
|
||||
ret += str.substring(idx + 1);
|
||||
|
||||
System.out.println(ret);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplace() {
|
||||
|
||||
String aaa = "cpu[$0].usage.system";
|
||||
|
||||
String bbb = "$";
|
||||
String ccc = bbb + String.valueOf(0);
|
||||
|
||||
String ddd = aaa.replace(ccc, "asdfasdf");
|
||||
|
||||
System.out.println(ddd);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMap() {
|
||||
|
||||
Map<String, String> aa = new HashMap<>();
|
||||
|
||||
aa.put("111", "123123123");
|
||||
aa.put("222", "123123123");
|
||||
|
||||
Map<String, String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
0
src/test/resources/_
Normal file
0
src/test/resources/_
Normal file
43
src/test/resources/config/mongodb/example.json
Normal file
43
src/test/resources/config/mongodb/example.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
395
src/test/resources/config/mysql/mysql-test.json
Normal file
395
src/test/resources/config/mysql/mysql-test.json
Normal file
|
@ -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"
|
||||
}
|
||||
}]
|
||||
}
|
44
src/test/resources/config/mysql/mysql.json
Normal file
44
src/test/resources/config/mysql/mysql.json
Normal file
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
36
src/test/resources/config/postgresql/postgresql.json
Normal file
36
src/test/resources/config/postgresql/postgresql.json
Normal file
|
@ -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'"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
67
src/test/resources/config/redis/example.json
Normal file
67
src/test/resources/config/redis/example.json
Normal file
|
@ -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" : {}
|
||||
}
|
||||
]
|
||||
}
|
38
src/test/resources/config/snmp/examplev2.json
Normal file
38
src/test/resources/config/snmp/examplev2.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
42
src/test/resources/config/snmp/examplev3.json
Normal file
42
src/test/resources/config/snmp/examplev3.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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" : {}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
46
src/test/resources/config/tomcat/example.json
Normal file
46
src/test/resources/config/tomcat/example.json
Normal file
|
@ -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" ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
130
src/test/resources/config/tomcat/example1.json
Normal file
130
src/test/resources/config/tomcat/example1.json
Normal file
|
@ -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" ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
47
src/test/resources/config/tomcat/example2.json
Normal file
47
src/test/resources/config/tomcat/example2.json
Normal file
|
@ -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" ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
106
src/test/resources/config/tomcat/generate1.json
Normal file
106
src/test/resources/config/tomcat/generate1.json
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
63
src/test/resources/config/wmi/example.json
Normal file
63
src/test/resources/config/wmi/example.json
Normal file
|
@ -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"]
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
}
|
49
src/test/resources/config/wmi/meta/meta_cpu.json
Normal file
49
src/test/resources/config/wmi/meta/meta_cpu.json
Normal file
|
@ -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
|
||||
}
|
||||
}]
|
||||
}
|
61
src/test/resources/config/wmi/meta/meta_filesystem.json
Normal file
61
src/test/resources/config/wmi/meta/meta_filesystem.json
Normal file
|
@ -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
|
||||
}
|
||||
}]
|
||||
}
|
53
src/test/resources/config/wmi/meta/meta_memory.json
Normal file
53
src/test/resources/config/wmi/meta/meta_memory.json
Normal file
|
@ -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
|
||||
}
|
||||
}]
|
||||
}
|
53
src/test/resources/config/wmi/meta/meta_network.json
Normal file
53
src/test/resources/config/wmi/meta/meta_network.json
Normal file
|
@ -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
|
||||
}
|
||||
}]
|
||||
}
|
130
src/test/resources/config/wmi/test.json
Normal file
130
src/test/resources/config/wmi/test.json
Normal file
|
@ -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
|
||||
}
|
||||
}]
|
||||
}
|
Loading…
Reference in New Issue
Block a user