Skip to content

Commit

Permalink
Merge pull request #1 from Tencent/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
rentiansheng committed Apr 8, 2018
2 parents fb271e4 + cf1460c commit 21fa267
Show file tree
Hide file tree
Showing 38 changed files with 508 additions and 353 deletions.
27 changes: 27 additions & 0 deletions ISSUE_TEMPLATE.md
@@ -0,0 +1,27 @@

问题描述
===========
<这里写问题描述>


重现方法
================
<列出如何重现的方法或操作步骤>


**重要提醒**: 请优先尝试最新发布的版本 (发布清单: https://github.com/Tencent/bk-cmdb/releases), 如果问题不能在最新发布的版本里重现,说明此问题已经被修复。


关键信息
=========

**重要提醒**: 这些关键信息会辅助我们快速定位问题。

请提供以下信息:

- [x] bk-cmdb 版本 (发布版本号 或 git tag): `<示例: v3.0.6-alpha 或者 git sha. 请不要使用 "最新版本" 或 "当前版本"等无法准确定位代码版本的语句描述>`
- [ ] Redis 版本: `<示例: 3.2.11>`
- [ ] MongoDB 版本: `<示例: 2.8.0>`
- [ ] ZooKeeper 版本: `<示例: 3.4.11>`
- [ ] 操作系统 : `<示例: Centos 5 (x64)>`
- [ ] bk-cmdb 异常日志
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.md
Expand Up @@ -12,7 +12,7 @@



### [分支管理](https://github.com/Tencent/bk-cmdb/blob/master/docs/VERSION.md)
### [分支管理](./VERSION.md)



Expand Down
3 changes: 0 additions & 3 deletions docs/apidoc/host_custom_api.md
Expand Up @@ -72,7 +72,6 @@ info 参数说明:
* English :update customize query

* input body:

```
{
"info":"{\"condition\":[{\"bk_obj_id\":\"biz\",\"condition\":[{\"field\":\"default\",\"operator\":\"$ne\",\"value\":1}],\"fields\":[]},{\"bk_obj_id\":\"set\",\"condition\":[],\"fields\":[]},{\"bk_obj_id\":\"module\",\"condition\":[],\"fields\":[]},{\"bk_obj_id\":\"host\",\"condition\":[{\"field\":\"bk_host_innerip\",\"operator\":\"$eq\",\"value\":\"127.0.0.1\"}],\"fields\":[\"bk_host_innerip\",\"bk_host_outerip\",\"bk_agent_status\"]}]}",
Expand Down Expand Up @@ -278,12 +277,10 @@ condition 参数说明:
* 中文: 获取自定义api详情
* English :get customize query detail
* input body


* input参数说明


| 名称 | 类型 |必填| 默认值 | 说明 | Description|
| --- | --- |---| --- | --- | ---|
| bk_biz_id|int|||业务ID | business ID|
Expand Down
1 change: 0 additions & 1 deletion docs/apidoc/host_relation.md
@@ -1,5 +1,4 @@


### 新增主机
* API: POST /api/{version}/hosts/add
* API名称: add_host_to_resource
Expand Down
2 changes: 0 additions & 2 deletions docs/apidoc/host_search.md
@@ -1,13 +1,11 @@


### 根据条件查询主机
* API: POST /api/{version}/hosts/search
* API名称: search_host
* 功能说明:
* 中文:根据条件查询主机
* English :search host by condition
* input body:

```
{
"ip":{
Expand Down
2 changes: 0 additions & 2 deletions docs/apidoc/host_search_his.md
@@ -1,5 +1,4 @@


### 新加主机查询历史
* API: POST /api/v1/hosts/history
* API名称: create_host_search_history
Expand All @@ -20,7 +19,6 @@
| 名称 | 类型 |必填| 默认值 | 说明 |Description|
| --- | --- | --- |--- | --- | --- |
| content| object|||主机查询条件 | host search condition content|

content为对象

* output
Expand Down
1 change: 0 additions & 1 deletion docs/apidoc/object_biz.md
Expand Up @@ -30,7 +30,6 @@
|bk_biz_maintainer|string|||运维人员|operation staff|
|bk_biz_developer|string|||开发人员|the developer|
|bk_biz_tester|string|||测试人员|the tester|

**注:此处的输入参数仅对必填以及系统内置的参数做了说明,其余需要填写的参数取决于用户自己定义的属性字段。**

### 删除业务
Expand Down
1 change: 0 additions & 1 deletion docs/apidoc/proc_config.md
@@ -1,5 +1,4 @@


### 新增进程
* API: POST /api/{version}/proc/{bk_supplier_account}/{bk_biz_id}
* API名称: create_process
Expand Down
1 change: 0 additions & 1 deletion docs/apidoc/user_privilege.md
@@ -1,5 +1,4 @@


### 权限说明

* 管理员具有所有权限
Expand Down
6 changes: 3 additions & 3 deletions docs/overview/installation.md
Expand Up @@ -54,8 +54,8 @@

### 4. 源码下载 && 编译

[源码下载 & 编译](source_compile.md)

* [源码下载 & 编译](source_compile.md)
* [可执行文件(linux)](http://bkopen-10032816.file.myqcloud.com/cmdb3/cmdb-3.0.6.tar.gz),md5[e1ce350eeb7947054e7ab95e7e3470e6]

### 5. 配置数据库

Expand Down Expand Up @@ -274,4 +274,4 @@ Not Running: cmdb_test
``` shell
[root@SWEBVM000229 /data/cmdb]# ./stop.sh
Running process count: 0
```
```
Binary file added docs/resource/img/code.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -12,7 +12,7 @@

此次重构使用golang作为开发语言,相比于2.0版本,系统的运行效率得到较大提升。此外采用了微服务架构设计,系统的部署发布可以支持传统方式和容器方式。

开源的版本会保持与蓝鲸社区版、企业版中内置的蓝鲸配置平台版本保持一致并且同步更新。我们的目标是打造能够兼容不同行业、不同架构的统一配置管理平台,成为业界领先的通用性强、易用性好的免费开源CMDB,欢迎对此感兴趣的同仁能够参与其中。
开源的版本会与蓝鲸社区版、企业版中内置的蓝鲸配置平台版本保持一致并且同步更新。我们的目标是打造能够兼容不同行业、不同架构的统一配置管理平台,成为业界领先的通用性强、易用性好的免费开源CMDB,欢迎对此感兴趣的同仁能够参与其中。



Expand Down
Empty file added src/changelog.md
Empty file.
7 changes: 4 additions & 3 deletions src/common/pattern.go
@@ -1,16 +1,17 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package common

// PatternIP regular pattern for ip
const PatternIP = `^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.((1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.){2}(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$`
const PatternMultipleIP = `^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.((1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.){2}(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)(,(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.((1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.){2}(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d))*$`
Empty file added src/readme.md
Empty file.
@@ -1,15 +1,15 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package data

import (
Expand Down Expand Up @@ -119,8 +119,8 @@ func HostRow() []*metadata.ObjectAttDes {
dataRows := []*metadata.ObjectAttDes{
//&metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.HOSTID_FIELD, PropertyName: "主机ID", IsSystem: true, IsRequired: true, IsOnly: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeInt, Option: ""},
//基本信息分组
&metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKHostInnerIPField, PropertyName: "内网IP", IsRequired: true, IsOnly: true, Editable: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeSingleChar, Option: common.PatternIP},
&metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKHostOuterIPField, PropertyName: "外网IP", IsRequired: false, IsOnly: false, Editable: true, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeSingleChar, Option: common.PatternIP},
&metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKHostInnerIPField, PropertyName: "内网IP", IsRequired: true, IsOnly: true, Editable: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeSingleChar, Option: common.PatternMultipleIP},
&metadata.ObjectAttDes{ObjectID: objID, PropertyID: common.BKHostOuterIPField, PropertyName: "外网IP", IsRequired: false, IsOnly: false, Editable: true, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeSingleChar, Option: common.PatternMultipleIP},
// &metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_agent_status", PropertyName: "Agent状态", IsRequired: false, IsOnly: false, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeEnum, Option: "[{\"name\":\"正常\", \"type\":\"text\"},{\"name\":\"异常\", \"type\":\"text\"},{\"name\":\"未安装\", \"type\":\"text\"}]"},
&metadata.ObjectAttDes{ObjectID: objID, PropertyID: "operator", PropertyName: "主要维护人", IsRequired: false, IsOnly: false, Editable: true, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeUser, Option: ""},
&metadata.ObjectAttDes{ObjectID: objID, PropertyID: "bk_bak_operator", PropertyName: "备份维护人", IsRequired: false, IsOnly: false, Editable: true, PropertyGroup: groupBaseInfo, PropertyType: common.FiledTypeUser, Option: ""},
Expand Down
Expand Up @@ -50,11 +50,14 @@ func (d *dataCollectionAction) AutoExectueAction(config map[string]string) error
if nil != err {
return err
}
chanName, err := getChanName()
if nil != err {
blog.Errorf("get channame faile,: %v, please init databae first ", err)
go d.AutoExectueAction(config)
return nil
chanName := ""
for {
chanName, err = getChanName()
if nil == err {
break
}
blog.Errorf("get channame faile: %v, please init databae firs, we will try 10 second later", err)
time.Sleep(time.Second * 10)
}

hostSnap := logics.NewHostSnap(chanName, 2000, rediscli, snapcli)
Expand Down
34 changes: 26 additions & 8 deletions src/scene_server/datacollection/datacollection/logics/hostsnap.go
Expand Up @@ -120,7 +120,7 @@ func (h *HostSnap) Run() {
if h.saveRunning() {
go h.subChan()
} else {
blog.Infof("there is other master process exists, recheck after %v ", getMasterProcIntervalTime)
blog.Infof("run: there is other master process exists, recheck after %v ", getMasterProcIntervalTime)
}
for {
select {
Expand All @@ -130,7 +130,7 @@ func (h *HostSnap) Run() {
go h.subChan()
}
} else {
blog.Infof("there is other master process exists, recheck after %v ", getMasterProcIntervalTime)
blog.Infof("loop: there is other master process exists, recheck after %v ", getMasterProcIntervalTime)
}
case msg = <-h.msgChan:
// read all from msgChan and lock to prevent clear operation
Expand Down Expand Up @@ -346,6 +346,7 @@ func (h *HostSnap) getHostByVal(val *gjson.Result) map[string]interface{} {

// concede concede when buffer fulled
func (h *HostSnap) concede() {
blog.Info("concede")
h.isMaster = false
h.subscribing = false
val := h.redisCli.Get(common.MASTER_PROC_LOCK_KEY).Val()
Expand All @@ -356,15 +357,29 @@ func (h *HostSnap) concede() {

// saveRunning lock master process
func (h *HostSnap) saveRunning() (ok bool) {
var err error
if h.isMaster {
val := h.redisCli.Get(common.MASTER_PROC_LOCK_KEY).Val()
if len(val) > 5 && h.id == val[0:5] {
var val string
val, err = h.redisCli.Get(common.MASTER_PROC_LOCK_KEY).Result()
if err != nil {
blog.Errorf("master: saveRunning err %v", err)
}
if len(val) > 5 && h.id == val[0:len(h.id)] {
blog.Infof("master check : i am still master")
h.redisCli.Set(common.MASTER_PROC_LOCK_KEY, h.id+"||"+time.Now().Format(time.RFC3339), masterProcLockLiveTime)
ok = true
} else {
blog.Infof("exit master,val = %v, id = %v", val, h.id)
h.isMaster = false
}
} else {
ok = h.redisCli.SetNX(common.MASTER_PROC_LOCK_KEY, h.id+"||"+time.Now().Format(time.RFC3339), masterProcLockLiveTime).Val()
ok, err = h.redisCli.SetNX(common.MASTER_PROC_LOCK_KEY, h.id+"||"+time.Now().Format(time.RFC3339), masterProcLockLiveTime).Result()
if err != nil {
blog.Errorf("slave: saveRunning err %v", err)
}
if ok {
blog.Infof("slave check: ok")
blog.Infof("i am master from now")
h.isMaster = true
}
}
Expand All @@ -382,16 +397,19 @@ func (h *HostSnap) subChan() {
h.interrupt <- err
blog.Error("subscribe channel faile ", err.Error())
}
defer subChan.Close()
defer blog.Infof("subChan Close")
defer func() {
subChan.Unsubscribe(h.chanName)
h.subscribing = false
blog.Infof("subChan Close")
}()

var ts = time.Now()
var cnt int64
blog.Infof("subcribing channel %s", h.chanName)
for {
if false == h.isMaster {
// not master again, close subscribe to prevent unnecessary subscript
blog.Info("This is not master process")
blog.Info("This is not master process, subChan Close")
return
}
received, err := subChan.Receive()
Expand Down
13 changes: 8 additions & 5 deletions src/scene_server/host_server/host_service/actions/detail/host.go
@@ -1,15 +1,15 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package detail

import (
Expand Down Expand Up @@ -152,8 +152,9 @@ func (cli *hostAction) HostSnapInfo(req *restful.Request, resp *restful.Response
return http.StatusInternalServerError, nil, defErr.Error(common.CCErrHostSnap)

} else {
snap, _ := output["data"].(string)
if "" != snap {
snap, err := js.Get("data").Get("data").String()

if nil == err && "" != snap {
ret, err := logics.ParseHostSnap(snap)
if nil != err {
blog.Error("query host snapshot error, error:%s", string(reply))
Expand All @@ -163,6 +164,8 @@ func (cli *hostAction) HostSnapInfo(req *restful.Request, resp *restful.Response
return http.StatusOK, ret, nil
}

return http.StatusOK, "", nil

} else {
return http.StatusOK, "", nil
}
Expand Down
@@ -1,15 +1,15 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package update

import (
Expand Down Expand Up @@ -132,7 +132,7 @@ func (cli *hostAction) UpdateHostBatch(req *restful.Request, resp *restful.Respo

}
opClient := auditlog.NewClient(cli.CC.AuditCtrl())
opClient.AuditHostsLog(logLastConents, "批量修改主机", common.BKDefaultOwnerID, appID, user, auditoplog.AuditOpTypeModify)
opClient.AuditHostsLog(logLastConents, "修改主机", common.BKDefaultOwnerID, appID, user, auditoplog.AuditOpTypeModify)

return http.StatusOK, common.CCSuccessStr, nil
}, resp)
Expand Down
8 changes: 4 additions & 4 deletions src/scene_server/host_server/host_service/logics/apphost.go
@@ -1,15 +1,15 @@
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/

package logics

import (
Expand Down Expand Up @@ -127,7 +127,7 @@ func ParseHostSnap(data string) (common.KvMap, error) {
var unitMB int64 = 1024 * 1024
diskTotal = diskTotal / unitGB
diskUsed = diskUsed / unitGB
if 0 == diskTotal {
if 0 != diskTotal {
diskUsage = (10000 * diskUsed / diskTotal) //获取使用百分比 保留两位小数
} else {
diskUsage = 0
Expand Down

0 comments on commit 21fa267

Please sign in to comment.