From a6c3d61ea36e5a7459de98ce238889b115a024bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BE=99?= Date: Wed, 12 Jul 2023 11:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E7=AE=A1=E7=90=86=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A3=80=E6=B5=8B=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.go | 33 ++++++++-------- src/service/host_manage.go | 80 +++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/main.go b/src/main.go index d83939d..0afec76 100644 --- a/src/main.go +++ b/src/main.go @@ -56,23 +56,22 @@ func initConfig() { conf.LoggerLevel = util.SetEnvStr("LOG_LEVEL", "info") conf.RunMode = util.SetEnvStr("GIN_MODE", "debug") // project run mode, available parameters: debug、release conf.Options = &conf.Config{ - Prefix: *prefix, - DbURL: util.SetEnvStr("DB_URL", "host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"), - DbDriver: util.SetEnvStr("DB_DRIVER", "postgres"), - RedisURL: util.SetEnvStr("REDIS_URL", "localhost:7001"), - RedisDB: 0, - RedisTag: "bg", - LogDirPrefix: util.SetEnvStr("LOG_DIR_PREFIX", "/app/log"), // 日志目录 - LogDirName: util.SetEnvStr("LOG_NAME", "syslog"), // 日志名称 - LogSaveDays: util.SetEnvInt("LOG_SAVE_DAYS", 7), // 日志最大存储天数 - LogMode: util.SetEnvInt("LOG_MODE", 1), // 1.标准打印 2.输出文件 - ArgBool: util.SetEnvBool("ARG_BOOL", false), // 示例参数 - ArgInt: util.SetEnvInt("ARG_INT", 10), // 示例参数 - MinioServer: util.SetEnvStr("MINIO_SERVER", "https://cache.wodcloud.com"), // Minio 服务地址 - MinioAccessKey: util.SetEnvStr("MINIO_ACCESS_KEY", "beagleadmin"), // Minio Access Key - MinioSecretKey: util.SetEnvStr("MINIO_SECRET_KEY", "H76cPmwvH7vJ"), // Minio Secret - MinioBucket: util.SetEnvStr("MINIO_BUCKET", "so-operation"), // Minio Bucket - //TempDirPrefix: util.SetEnvStr("TEMP_DIR_PREFIX", "/app/xlsx/"), //模板目录前缀 + Prefix: *prefix, + DbURL: util.SetEnvStr("DB_URL", "host=localhost port=9010 user=postgres password=passwd123 dbname=postgres sslmode=disable"), + DbDriver: util.SetEnvStr("DB_DRIVER", "postgres"), + RedisURL: util.SetEnvStr("REDIS_URL", "localhost:7001"), + RedisDB: 0, + RedisTag: "bg", + LogDirPrefix: util.SetEnvStr("LOG_DIR_PREFIX", "/app/log"), // 日志目录 + LogDirName: util.SetEnvStr("LOG_NAME", "syslog"), // 日志名称 + LogSaveDays: util.SetEnvInt("LOG_SAVE_DAYS", 7), // 日志最大存储天数 + LogMode: util.SetEnvInt("LOG_MODE", 1), // 1.标准打印 2.输出文件 + ArgBool: util.SetEnvBool("ARG_BOOL", false), // 示例参数 + ArgInt: util.SetEnvInt("ARG_INT", 10), // 示例参数 + MinioServer: util.SetEnvStr("MINIO_SERVER", "https://cache.wodcloud.com"), // Minio 服务地址 + MinioAccessKey: util.SetEnvStr("MINIO_ACCESS_KEY", "beagleadmin"), // Minio Access Key + MinioSecretKey: util.SetEnvStr("MINIO_SECRET_KEY", "H76cPmwvH7vJ"), // Minio Secret + MinioBucket: util.SetEnvStr("MINIO_BUCKET", "so-operation"), // Minio Bucket PrometheusHost: util.SetEnvStr("PROMETHEUS_HOST", "https://prometheus.wodcloud.com"), // Prometheus Host AccessRuleModeKey: "accessRuleMode", LocationUrl: util.SetEnvStr("LOCATION_URL", "https://apis.map.qq.com/ws/location/v1/ip"), diff --git a/src/service/host_manage.go b/src/service/host_manage.go index cdcc886..7414e91 100644 --- a/src/service/host_manage.go +++ b/src/service/host_manage.go @@ -412,46 +412,46 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err } // 读取hosts中的主机组 - //hosts, err := tools.HostsToJson() - //if err != nil { - // err = resp.MarshalError.WithError(err) - // session.Rollback() - // return - //} - // - //if _, ok := hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"]; !ok { - // // 不存在 - // hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] = nil - //} - ////新增主机分组列表 - //for _, v := range hostManageList { - // hostsIp := "" - // if v.VoucherType == 0 { - // hostsIp = fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\" ansible_host_key_checking=false", - // AnsibleIp+fmt.Sprintf("%d", v.Id), v.Ip, v.Port, v.UserName, v.Password) - // } else { - // hostsIp = fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_private_key_file=/root/.ssh/id_rsa ansible_host_key_checking=false", - // AnsibleIp+fmt.Sprintf("%d", v.Id), v.Ip, v.Port, v.UserName) - // } - // - // flag := 0 - // for _, v1 := range hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] { - // if v1 == hostsIp { - // flag = 1 - // } - // } - // if flag == 0 { - // hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] = append(hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"], hostsIp) - // } - //} - // - ////写入hosts - //err = tools.MapToSaveHosts(hosts) - //if err != nil { - // err = resp.MarshalError.WithError(err) - // session.Rollback() - // return - //} + hosts, err := tools.HostsToJson() + if err != nil { + err = resp.MarshalError.WithError(err) + session.Rollback() + return + } + + if _, ok := hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"]; !ok { + // 不存在 + hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] = nil + } + //新增主机分组列表 + for _, v := range hostManageList { + hostsIp := "" + if v.VoucherType == 0 { + hostsIp = fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_pass=\"%s\" ansible_host_key_checking=false", + AnsibleIp+fmt.Sprintf("%d", v.Id), v.Ip, v.Port, v.UserName, v.Password) + } else { + hostsIp = fmt.Sprintf("%s ansible_ssh_host=%s ansible_ssh_port=%s ansible_ssh_user=\"%s\" ansible_ssh_private_key_file=/root/.ssh/id_rsa ansible_host_key_checking=false", + AnsibleIp+fmt.Sprintf("%d", v.Id), v.Ip, v.Port, v.UserName) + } + + flag := 0 + for _, v1 := range hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] { + if v1 == hostsIp { + flag = 1 + } + } + if flag == 0 { + hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"] = append(hosts["["+AnsibleGroup+fmt.Sprintf("%d", req.Id)+"]"], hostsIp) + } + } + + //写入hosts + err = tools.MapToSaveHosts(hosts) + if err != nil { + err = resp.MarshalError.WithError(err) + session.Rollback() + return + } for _, v := range hostManageList { //修改状态 -- 2.26.0