Skip to content

Commit

Permalink
Merge pull request #15 from ywlianghang/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ywlianghang authored Aug 25, 2021
2 parents 4b6143d + f7b175e commit 4bf31b0
Show file tree
Hide file tree
Showing 11 changed files with 1,178 additions and 944 deletions.
502 changes: 251 additions & 251 deletions InspectionItem/configurationParameter.go

Large diffs are not rendered by default.

792 changes: 419 additions & 373 deletions InspectionItem/databaseProperty.go

Large diffs are not rendered by default.

214 changes: 114 additions & 100 deletions InspectionItem/databaseSecurity.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
1.5.07 检查实例是否存在普通用户supr权限(WITH GRANT OPTION)(巡检项:normalUserSuperPrivilages)
1.5.08 检查实例是否使用默认端口(3306)(巡检项:databasePort)

2)mycheck下个版本改动:
2)mycheck下个版本改动(已完成)
(1)将配置参数检查外放,通过配置文件可进行自定义参数检测
(2)将巡检项进行外放,通过配置文件可进行巡检项控制(通过false、true选择是否检测该项)
(3)将巡检项阈值进行外放,通过配置文件可进行阈值调整(超过阈值才会出现在pdf巡检报告中)
Expand Down
4 changes: 2 additions & 2 deletions ResultOutput/PDF/OutPdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (out *OutputWayStruct) OutPdf() {
pdf.MultiCell(0, 5, string("3.4 巡检数据库基线"), "", "", false)
pdf = out.pdfTableBodyColorsFormat(pdf,w3,cd)
tmpCheckTypeSliect = []string{"tableCharset","tableEngine","tableForeign","tableNoPrimaryKey","tableAutoIncrement",
"tableBigColumns","indexColumnIsNull","indexColumnIsEnumSet","indexColumnIsBlobText","tableIncludeRepeatIndex",
"tableProcedure","tableFunc","tableTrigger"}
"tableBigColumns","indexColumnIsNull","indexColumnType","tableIncludeRepeatIndex",
"tableProcedureFunc","tableTrigger"}
tmpResultBaselineResult := out.tmpResultSummary(tmpCheckTypeSliect)
pdf = out.pdfTableInsert(pdf,w3,tmpResultBaselineResult)
pdf.Ln(-1)
Expand Down
239 changes: 73 additions & 166 deletions ResultOutput/PDF/ResultDateProcessing.go

Large diffs are not rendered by default.

121 changes: 93 additions & 28 deletions api/PublicClass/Global.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ type BaselineCheckColumnDesignResultStruct struct{
TableBigColumns []map[string]string
}
type BaselineCheckIndexColumnDesignResultStruct struct{
IndexColumnType []map[string]string
IndexColumnIsNull []map[string]string
IndexColumnIsEnumSet []map[string]string
IndexColumnIsBlobText []map[string]string
IndexColumnIsRepeatIndex []map[string]string
}
type BaselineCheckProcedureTriggerDesignResultStruct struct{
Expand Down Expand Up @@ -104,6 +103,8 @@ var Loggs loggs.LogOutputInterface
var DBexecInter DatabaseOperation
var Strea *Stream.StreamStruct
var ResultOutput *loggs.ResultOutputFileEntity
var InspectionConfSwitch *loggs.InspectionConfSwitchFileEntity
var InspectionConfInput *loggs.InspectionConfInputFileEntity

//巡检结果结构体初始化
//一级结构体初始化
Expand Down Expand Up @@ -185,11 +186,99 @@ func ConfigInit() {
InspectionPersonnel: getConf.ResultOutput.InspectionPersonnel,
InspectionLevel: getConf.ResultOutput.InspectionLevel,
}
InspectionConfSwitch = &loggs.InspectionConfSwitchFileEntity{
ConfigSwitch: getConf.InspectionConfSwitch.ConfigSwitch,
}
InspectionConfInput = &loggs.InspectionConfInputFileEntity{
DatabaseEnvironment: getConf.InspectionConfInput.DatabaseEnvironment,
DatabaseConfiguration: getConf.InspectionConfInput.DatabaseConfiguration,
DatabasePerformance: getConf.InspectionConfInput.DatabasePerformance,
DatabaseBaseline: getConf.InspectionConfInput.DatabaseBaseline,
DatabaseSecurity: getConf.InspectionConfInput.DatabaseSecurity,
DatabaseSpace: getConf.InspectionConfInput.DatabaseSpace,
}
Loggs = Logconfig
DBexecInter = Dbconfig
Strea = &Stream.StreamStruct{}
}

var (
ConfigurationCanCheck = make(map[string]string)
PerformanceCanCheck = make(map[string]string)
BaselineCanCheck = make(map[string]string)
SecurityCanCheck = make(map[string]string)
)
func YamlconfigInit(){
tmpStatusValCheck := "true false"
//检测配置开关参数是否设置合理,填写的true或false是否正确
for k,v := range InspectionConfSwitch.ConfigSwitch{
if !strings.Contains(tmpStatusValCheck, strings.ToLower(v)) {
fmt.Println(fmt.Sprintf("当前配置参数 %s 选项输入有误,只能输入是true或false", k))
os.Exit(1)
}
}
for k,v := range InspectionConfSwitch.ConfigSwitch{
//初始化配置参数,生成需要检测的列表
if strings.EqualFold(k,"databaseConfigurationSwitch") && strings.EqualFold(v,"true"){
for i := range InspectionConfInput.DatabaseConfiguration {
cc := InspectionConfInput.DatabaseConfiguration[i]
if !strings.Contains(tmpStatusValCheck, strings.ToLower(cc["subCheckSwitch"])) {
fmt.Println("当前配置参数subCheckSwitchch 选项输入有误,只能输入是true或false")
os.Exit(1)
}
if strings.EqualFold(cc["subCheckSwitch"], "true") {
key := strings.ToLower(cc["checkconfiguration"])
val := strings.ToLower(cc["checkThreshold"])
ConfigurationCanCheck[key] = val
}
}
}
//初始化性能列表,生成需要检测的列表
if strings.EqualFold(k,"databasePerformanceSwitch") && strings.EqualFold(v,"true"){
for i := range InspectionConfInput.DatabasePerformance {
cc := InspectionConfInput.DatabasePerformance[i]
if !strings.Contains(tmpStatusValCheck, strings.ToLower(cc["subCheckSwitch"])) {
fmt.Println("当前配置参数subCheckSwitchch 选项输入有误,只能输入是true或false")
os.Exit(1)
}
if strings.EqualFold(cc["subCheckSwitch"], "true") {
key := strings.ToLower(cc["checkconfiguration"])
val := strings.ToLower(cc["checkThreshold"])
PerformanceCanCheck[key] = val
}
}
}
//初始化基线检查列表,生成需要检测的列表
if strings.EqualFold(k,"databaseBaselineSwitch") && strings.EqualFold(v,"true"){
for i := range InspectionConfInput.DatabaseBaseline {
cc := InspectionConfInput.DatabaseBaseline[i]
if !strings.Contains(tmpStatusValCheck, strings.ToLower(cc["subCheckSwitch"])) {
fmt.Println("当前配置参数subCheckSwitchch 选项输入有误,只能输入是true或false")
os.Exit(1)
}
if strings.EqualFold(cc["subCheckSwitch"], "true") {
key := strings.ToLower(cc["checkconfiguration"])
val := strings.ToLower(cc["checkThreshold"])
BaselineCanCheck[key] = val
}
}
}
//初始化安全检查列表,生成需要检测的列表
if strings.EqualFold(k,"databaseSecuritySwitch") && strings.EqualFold(v,"true"){
for i := range InspectionConfInput.DatabaseSecurity {
cc := InspectionConfInput.DatabaseSecurity[i]
if !strings.Contains(tmpStatusValCheck, strings.ToLower(cc["subCheckSwitch"])) {
fmt.Println("当前配置参数subCheckSwitchch 选项输入有误,只能输入是true或false")
os.Exit(1)
}
if strings.EqualFold(cc["subCheckSwitch"], "true") {
key := strings.ToLower(cc["checkconfiguration"])
val := strings.ToLower(cc["checkThreshold"])
SecurityCanCheck[key] = val
}
}
}
}
}
func QueryDbDateInit(){
strSql = "show global variables"
a := DBexecInter.DBQueryDateMap(strSql)
Expand All @@ -216,29 +305,5 @@ func QueryDbDateInit(){
strSql = fmt.Sprintf("select user,host,authentication_string password from mysql.user")
MysqlUser = DBexecInter.DBQueryDateJson(strSql)


}
var Ccc = map[string]string {
"super_read_only" : "off",
"read_only" : "off",
"innodb_read_only": "off",
"binlog_format" : "row",
"character_set_server" : "utf8",
"default_authentication_plugin" : "mysql_native_password",
"default_storage_engine" : "innodb",
"default_tmp_storage_engine" : "innodb",
"innodb_flush_log_at_trx_commit" : "1",
"innodb_flush_method" : "O_DIRECT",
"innodb_deadlock_detect" : "on",
"internal_tmp_disk_storage_engine" : "innodb",
"query_cache_type" : "off",
"relay_log_purge" : "on",
"relay_log_recovery" : "on",
"sync_binlog" : "1",
"system_time_zone" : "CST",
"time_zone" : "system",
"transaction_isolation" : "READ-COMMITTED",
"transaction_read_only" : "off",
"tx_isolation" : "READ-COMMITTED",
"tx_read_only" : "off",
"unique_checks" : "on",
}
13 changes: 13 additions & 0 deletions api/loggs/logConfigInput.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type BaseInfo struct {
Logs LogsEntity `yaml:"logs"`
DBinfo DBinfoEntity `yaml:"dbinfo"`
ResultOutput ResultOutputFileEntity `yaml:"resultOutput"`
InspectionConfSwitch InspectionConfSwitchFileEntity `yaml:"inspectionConfSwitch"`
InspectionConfInput InspectionConfInputFileEntity `yaml:"inspectionConfInput"`
}
type DBinfoEntity struct {
DirverName string `yaml:"dirverName"`
Expand Down Expand Up @@ -43,6 +45,17 @@ type ResultOutputFileEntity struct {
InspectionPersonnel string `yaml:"inspectionPersonnel"`
InspectionLevel string `yaml:"inspectionLevel"`
}
type InspectionConfSwitchFileEntity struct {
ConfigSwitch map[string]string `yaml:"configSwitch"`
}
type InspectionConfInputFileEntity struct {
DatabaseEnvironment []map[string]string `yaml:"databaseEnvironment"`
DatabaseConfiguration []map[string]string `yaml:"databaseConfiguration"`
DatabasePerformance []map[string]string `yaml:"databasePerformance"`
DatabaseBaseline []map[string]string `yaml:"databaseBaseline"`
DatabaseSecurity []map[string]string `yaml:"databaseSecurity"`
DatabaseSpace []map[string]string `yaml:"databaseSpace"`
}

func (conf *BaseInfo) GetConf() BaseInfo {
yamlFile,err := ioutil.ReadFile(flag.CheckParameter.Config)
Expand Down
2 changes: 1 addition & 1 deletion flag/flaghelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func cliHelp(){
app.Usage = "In-depth inspection of MySQL for system guarantee and daily inspection during major festivals" //应用功能说明
app.Author = "lianghang" //作者
app.Email = "[email protected]" //邮箱
app.Version = "1.0" //版本
app.Version = "1.1" //版本
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config,c", //命令名称
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ func main() {
PublicClass.CheckBeginTime = time.Now().Format("2006-01-02 15:04:05")
flag.ParameterCheck()
PublicClass.ConfigInit()
PublicClass.YamlconfigInit()
//查询数据初始化,将用到的数据初始化到内存中
PublicClass.QueryDbDateInit()
InspectionItem.DatabaseConfigCheck(PublicClass.Ccc)
InspectionItem.DatabaseConfigCheck(PublicClass.ConfigurationCanCheck)
var c = &InspectionItem.DatabaseBaselineCheckStruct{}
c.BaselineCheckTablesDesign()
c.BaselineCheckColumnsDesign()
Expand Down
Loading

0 comments on commit 4bf31b0

Please sign in to comment.