Commit 1ac9266f authored by tywldx's avatar tywldx

Merge branch 'master' of http://git.quantgroup.cn/QA/qaHome

parents 13a2d60f 2c75b1e6
......@@ -107,8 +107,48 @@ exports.save = async function () {
console.log(req)
if (req._id) {
this.body = await this.mongo("dbconfig").updateById(req._id, new_db);
try {
this.logger.info(
{
active: "update_dbconfig",
microservice_name: req.dbname.trim(),
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
detail: {
dbname: req.dbname.trim(),
ip: req.ip.trim(),
port: parseInt(req.port),
username: req.username.trim() || "",
passwd: req.passwd.trim() || "",
table_list: req.table_list.trim() || "",
update_at: req.update_at
}
});
} catch (error) {
console.log(error)
}
} else {
this.body = await this.mongo("dbconfig", new_db).saveByName(req.dbname, req);
try {
this.logger.info(
{
active: "new_dbconfig",
microservice_name: req.dbname.trim(),
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
detail: {
dbname: req.dbname.trim(),
ip: req.ip.trim(),
port: parseInt(req.port),
username: req.username.trim() || "",
passwd: req.passwd.trim() || "",
table_list: req.table_list.trim() || "",
update_at: req.update_at
}
});
} catch (error) {
console.log(error)
}
}
} catch (error) {
console.log(error)
......@@ -137,8 +177,6 @@ exports.get_db_config = async function () {
if (db.passwd === default_passwd) {
db.passwd = ''
}
// process.env.TZ = 'Asia/Shanghai';
// db.update_at = db.update_at.toLocaleString()
}
this.body = db_configs;
}
......@@ -147,6 +185,17 @@ exports.delete = async function () {
await this.bindDefault();
try {
await this.mongo("dbconfig").delete(this.request.query._id)
try {
this.logger.info(
{
active: "delete_dbconfig",
microservice_name: this.request.query.dbname.trim(),
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
});
} catch (error) {
console.log(error)
}
this.body = { code: "0002" }
} catch (error) {
//执行不到这里,即使删除前将要删除的记录手动删除了,也不会报错
......@@ -283,12 +332,18 @@ exports.db_sync = async function () {
try {
this.logger.info(
" active:", "db_sync",
"namespace:", req.name_space,
"sync_db_name:", req.sync_db_name,
"not_delete_business_data:", req.not_delete_business_data,
"use_cache:", req.use_cache,
" user:", this.user);
{
namespace: req.name_space,
active: "sync_db",
microservice_name: req.sync_db_name,
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
detail: {
"sync_db_name:": req.sync_db_name,
"not_delete_business_data:": req.not_delete_business_data,
"use_cache:": req.use_cache,
}
});
} catch (error) {
}
......@@ -344,28 +399,19 @@ exports.reset_binlog = async function () {
} catch (error) {
}
try {
this.logger.info(
{
active: "reset_binlog",
namespace: req.name_space,
active: "reset_binlog",
microservice_name: "",
user: `${this.user.name}`,
user_email: `${this.user.mail}`,
user_mail: `${this.user.mail}`,
}
// "| active:", "reset_binlog",
// "| namespace:", req.name_space,
// "| microservice_name:", "",
// "| user:", `${this.user.name}`,
// "| user_email:", `${this.user.mail}`,
// "~"
);
} catch (error) {
console.log(error)
}
}
exports.binlog_to_sql = async function () {
......
......@@ -485,10 +485,18 @@ exports.restart_system = async function () {
}
try {
this.logger.info(
"namespace:", this.request.body.namespace,
" microservice_name:", this.request.body.system_name,
" active:", "restart_microservice",
" user:", this.user);
{
namespace: this.request.body.namespace,
active: "restart_microservice",
microservice_name: this.request.body.system_name,
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
}
// "namespace:", this.request.body.namespace,
// " microservice_name:", this.request.body.system_name,
// " active:", "restart_microservice",
// " user:", this.user);
)
} catch (error) {
console.log(this.logger)
}
......@@ -511,10 +519,18 @@ exports.delete_system = async function () {
}
try {
this.logger.info(
"namespace:", this.request.body.namespace,
" name:", this.request.body.system_name,
" active:", "delete_microservice",
" user:", this.user);
{
namespace: this.request.body.namespace,
active: "delete_microservice",
microservice_name: this.request.body.system_name,
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
}
// "namespace:", this.request.body.namespace,
// " name:", this.request.body.system_name,
// " active:", "delete_microservice",
// " user:", this.user
);
} catch (error) {
}
......@@ -766,9 +782,17 @@ exports.create_system = async function () {
this.body = res;
try {
this.logger.info(
"namespace:", temp,
" active:", "create_microservice",
" user:", this.user);
{
namespace: this.request.body.namespace,
active: "create_microservice",
microservice_name: this.request.body.name,
// user: `${this.user.name}`,
// user_mail: `${this.user.mail}`,
}
// "namespace:", temp,
// " active:", "create_microservice",
// " user:", this.user
);
} catch (error) {
}
......@@ -790,11 +814,20 @@ exports.update_system = async function () {
this.body = res;
try {
this.logger.info(
"namespace:", temp,
" active:", "update_microservice",
" user:", this.user);
{
namespace: this.request.body.namespace,
active: "update_microservice",
microservice_name: this.request.body.name,
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
detail: temp
}
// "namespace:", temp,
// " active:", "update_microservice",
// " user:", this.user
);
} catch (error) {
console.log(error)
}
return
......@@ -921,9 +954,17 @@ exports.reload_mq = async function () {
this.body = { code: "0000" };
try {
this.logger.info(
// {
// namespace: req.name_space,
// active: "reset_binlog",
// microservice_name: "",
// user: `${this.user.name}`,
// user_mail: `${this.user.mail}`,
// }
"namespace:", this.request.body.host,
" active:", "reload_mq",
" user:", this.user);
" user:", this.user
);
} catch (error) {
}
......@@ -1060,9 +1101,16 @@ exports.flush_redis = async function () {
try {
this.logger.info(
"namespace:", req.namespace,
" active:", "flush_redis",
" user:", this.user);
{
namespace: req.namespace,
active: "flush_redis",
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
}
// "namespace:", req.namespace,
// " active:", "flush_redis",
// " user:", this.user
);
} catch (error) {
}
......
exports.get_log = async function () {
await this.bindDefault();
let item = await this.mongo("statisticslog").getLog({
namespace: this.request.body.query.namespace,
active: this.request.body.query.active,
microservice_name: this.request.body.query.microservice_name,
// create_time: {
// $gt: new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000)
// }
}, { create_time: -1 }, this.request.body.query.num, this.request.body.query.count);
this.body = item
return
}
exports.get_log_count = async function () {
await this.bindDefault();
let item = await this.mongo("statisticslog").getLogCount({
namespace: this.request.body.query.namespace,
active: this.request.body.query.active,
microservice_name: this.request.body.query.microservice_name,
});
this.body = item
return
}
\ No newline at end of file
......@@ -60,8 +60,32 @@ exports.save = async function () {
console.log(req)
if (req._id) {
this.body = await this.mongo("ProConfig").updateById(req._id, new_pro);
try {
this.logger.info(
{
active: "update_proconfig",
microservice_name: project_name.trim(),
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
detail: new_pro
});
} catch (error) {
console.log(error)
}
} else {
this.body = await this.mongo("ProConfig", new_pro).saveByPath(req.git_path, req);
try {
this.logger.info(
{
active: "new_proconfig",
microservice_name: project_name.trim(),
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
detail: new_pro
});
} catch (error) {
console.log(error)
}
}
} catch (error) {
console.log(error)
......@@ -135,6 +159,17 @@ exports.delete = async function () {
await this.bindDefault();
let item = await this.mongo("ProConfig").delete(this.request.query._id);
this.body = item
try {
this.logger.info(
{
active: "delete_proconfig",
microservice_name: this.request.query.project_name.trim(),
user: `${this.user.name}`,
user_mail: `${this.user.mail}`,
});
} catch (error) {
console.log(error)
}
return
}
exports.delete.__method__ = 'get';
'use strict';
// model名称,即表名
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
exports.model = 'dbconfig';
// 表结构
......
exports.model = 'statisticslog';
exports.schema = [{
}, {
autoIndex: false,
versionKey: false
}];
exports.methods = {
getLog: async function (query, sort, num, count) {
if (query.namespace || query.namespace === '') {
query.namespace = new RegExp(query.namespace);
}
if (query.active || query.active === '') {
query.active = new RegExp(query.active);
}
if (query.microservice_name || query.microservice_name === '') {
query.microservice_name = new RegExp(query.microservice_name);
}
return await this.model("statisticslog").find(query).sort(sort).skip(num * count).limit(count)
},
getLogCount: async function (query) {
if (query.namespace || query.namespace === '') {
query.namespace = new RegExp(query.namespace);
}
if (query.active || query.active === '') {
query.active = new RegExp(query.active);
}
if (query.microservice_name || query.microservice_name === '') {
query.microservice_name = new RegExp(query.microservice_name);
}
return await this.model("statisticslog").find(query).count()
}
}
'use strict';
var extend = require('extend');
const path = require('path');
const koa = require('koa');
const Middles = require('../middleware/')
var request = require('request');
var log4js = require('log4js');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
let session = {};
const app = new koa();
......@@ -15,25 +17,56 @@ log4js.configure({
const _logger = log4js.getLogger('cheese');
var StatisticsSchema = new Schema({
namespace: String,
active: String,
microservice_name: String,
user: String,
user_mail: String,
detail: Object,
create_time: Date
});
// mongo 链接操作。 moogose
// mongoose.connect('mongodb://192.168.28.179:27017/qaHome')
mongoose.connect('mongodb://172.30.220.22:27017/qaHome', { useMongoClient: true })
var StatisticsLogModel = mongoose.model('StatisticsLog', StatisticsSchema);
var logger = {
info: ()=>{
info: (...args) => {
// mongo操作
_logger.info(arguments)
},debug: ()=>{
let _log = {
namespace: "",
active: "",
microservice_name: "",
user: "",
user_mail: "",
detail: undefined,
create_time: new Date()
}
if (typeof args[0] === "string") {
console.log(1111)
_logger.info(args)
} else {
console.log(222)
extend(_log, args[0]);
var log = new StatisticsLogModel(_log)
log.save(function (err) {
if (err) {
console.log('save error:' + err);
}
console.log('save sucess');
});
_logger.info(_log)
}
}, debug: () => {
// mongo操作
_logger.debug(arguments)
},error: () =>{
}, error: () => {
// mongo操作
_logger.error(arguments)
}
};
// compress(gzip)
app.use(Middles.compress());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment