|
@@ -1,78 +1,78 @@
|
|
|
-package cn.com.qmth.examcloud.web.mongodb;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
-import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
-import com.google.common.collect.Maps;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.boot.ApplicationArguments;
|
|
|
-import org.springframework.boot.ApplicationRunner;
|
|
|
-import org.springframework.core.annotation.Order;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.lang.reflect.Method;
|
|
|
-import java.net.Inet4Address;
|
|
|
-import java.net.InetAddress;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * mongodb 侦察器
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @date 2018年11月29日
|
|
|
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
- */
|
|
|
-@Component
|
|
|
-@Order(99)
|
|
|
-public class MongodbDetector implements ApplicationRunner {
|
|
|
-
|
|
|
- private static final Logger LOG = LoggerFactory.getLogger(MongodbDetector.class);
|
|
|
-
|
|
|
- public void start() {
|
|
|
- Class<?> mongoTemplateClass;
|
|
|
- Object mongoTemplateObject;
|
|
|
-
|
|
|
- try {
|
|
|
- mongoTemplateClass = Class.forName("org.springframework.data.mongodb.core.MongoTemplate");
|
|
|
- mongoTemplateObject = SpringContextHolder.getBean(mongoTemplateClass);
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.info("mongodb disabled...");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- String ip = null;
|
|
|
- try {
|
|
|
- InetAddress localHost = Inet4Address.getLocalHost();
|
|
|
- ip = localHost.getHostAddress();
|
|
|
- } catch (Exception e) {
|
|
|
- // ignore
|
|
|
- }
|
|
|
-
|
|
|
- String appName = PropertyHolder.getString("spring.application.name");
|
|
|
-
|
|
|
- try {
|
|
|
- Method getDbMethod = mongoTemplateClass.getMethod("getDb");
|
|
|
- Object mongoDatabaseObject = getDbMethod.invoke(mongoTemplateObject);
|
|
|
- Method getNameMethod = mongoDatabaseObject.getClass().getMethod("getName");
|
|
|
- Object dbName = getNameMethod.invoke(mongoDatabaseObject);
|
|
|
- LOG.info("mongodb database is " + dbName);
|
|
|
-
|
|
|
- Map<String, String> data = Maps.newHashMap();
|
|
|
- data.put("startupTime", DateUtil.chinaNow());
|
|
|
- data.put("appName", appName);
|
|
|
- data.put("ip", ip);
|
|
|
-
|
|
|
- Method insertMethod = mongoTemplateClass.getMethod("insert", Object.class, String.class);
|
|
|
- insertMethod.invoke(mongoTemplateObject, data, "startup");
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.error("mongodb detector fail...");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run(ApplicationArguments args) throws Exception {
|
|
|
- start();
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+// package cn.com.qmth.examcloud.web.mongodb;
|
|
|
+//
|
|
|
+// import cn.com.qmth.examcloud.commons.util.DateUtil;
|
|
|
+// import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
+// import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
+// import com.google.common.collect.Maps;
|
|
|
+// import org.slf4j.Logger;
|
|
|
+// import org.slf4j.LoggerFactory;
|
|
|
+// import org.springframework.boot.ApplicationArguments;
|
|
|
+// import org.springframework.boot.ApplicationRunner;
|
|
|
+// import org.springframework.core.annotation.Order;
|
|
|
+// import org.springframework.stereotype.Component;
|
|
|
+//
|
|
|
+// import java.lang.reflect.Method;
|
|
|
+// import java.net.Inet4Address;
|
|
|
+// import java.net.InetAddress;
|
|
|
+// import java.util.Map;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * mongodb 侦察器
|
|
|
+// *
|
|
|
+// * @author WANGWEI
|
|
|
+// * @date 2018年11月29日
|
|
|
+// * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+// */
|
|
|
+// @Component
|
|
|
+// @Order(99)
|
|
|
+// public class MongodbDetector implements ApplicationRunner {
|
|
|
+//
|
|
|
+// private static final Logger LOG = LoggerFactory.getLogger(MongodbDetector.class);
|
|
|
+//
|
|
|
+// public void start() {
|
|
|
+// Class<?> mongoTemplateClass;
|
|
|
+// Object mongoTemplateObject;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// mongoTemplateClass = Class.forName("org.springframework.data.mongodb.core.MongoTemplate");
|
|
|
+// mongoTemplateObject = SpringContextHolder.getBean(mongoTemplateClass);
|
|
|
+// } catch (Exception e) {
|
|
|
+// LOG.info("mongodb disabled...");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// String ip = null;
|
|
|
+// try {
|
|
|
+// InetAddress localHost = Inet4Address.getLocalHost();
|
|
|
+// ip = localHost.getHostAddress();
|
|
|
+// } catch (Exception e) {
|
|
|
+// // ignore
|
|
|
+// }
|
|
|
+//
|
|
|
+// String appName = PropertyHolder.getString("spring.application.name");
|
|
|
+//
|
|
|
+// try {
|
|
|
+// Method getDbMethod = mongoTemplateClass.getMethod("getDb");
|
|
|
+// Object mongoDatabaseObject = getDbMethod.invoke(mongoTemplateObject);
|
|
|
+// Method getNameMethod = mongoDatabaseObject.getClass().getMethod("getName");
|
|
|
+// Object dbName = getNameMethod.invoke(mongoDatabaseObject);
|
|
|
+// LOG.info("mongodb database is " + dbName);
|
|
|
+//
|
|
|
+// Map<String, String> data = Maps.newHashMap();
|
|
|
+// data.put("startupTime", DateUtil.chinaNow());
|
|
|
+// data.put("appName", appName);
|
|
|
+// data.put("ip", ip);
|
|
|
+//
|
|
|
+// Method insertMethod = mongoTemplateClass.getMethod("insert", Object.class, String.class);
|
|
|
+// insertMethod.invoke(mongoTemplateObject, data, "startup");
|
|
|
+// } catch (Exception e) {
|
|
|
+// LOG.error("mongodb detector fail...");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void run(ApplicationArguments args) throws Exception {
|
|
|
+// start();
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|