Skip to content

Commit 0b4206e

Browse files
authored
Merge pull request #113 from canghai908/dev
update to 2.1.6
2 parents c839ddf + 0303aa9 commit 0b4206e

File tree

18 files changed

+367
-170
lines changed

18 files changed

+367
-170
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ MS-Agent: Installed on Zabbix Server, used to receive alarms generated by Zabbix
3232
## Compatibility
3333

3434
| Zabbix Version | Compatibility |
35-
|:---------------| :------------ |
36-
| 6.4.x ||
37-
| 6.2.x ||
38-
| 6.0.x ||
39-
| 5.4.x ||
40-
| 5.2.x ||
41-
| 5.0.x LTS ||
42-
| 4.4.x ||
43-
| 4.2.x ||
44-
| 4.0.x LTS ||
45-
| 3.4.x | untested |
46-
| 3.2.x | untested |
47-
| 3.0.x LTS | untested |
35+
|:---------------|:-------------:|
36+
| 7.0.x LTS ||
37+
| 6.4.x ||
38+
| 6.2.x ||
39+
| 6.0.x LTS ||
40+
| 5.4.x ||
41+
| 5.2.x ||
42+
| 5.0.x LTS ||
43+
| 4.4.x ||
44+
| 4.2.x ||
45+
| 4.0.x LTS ||
46+
| 3.4.x | untested |
47+
| 3.2.x | untested |
48+
| 3.0.x LTS | untested |
4849

4950
## Documentation
5051

@@ -60,7 +61,7 @@ MS-Agent: Installed on Zabbix Server, used to receive alarms generated by Zabbix
6061

6162
## Compile
6263

63-
go >=1.21
64+
go >=1.22
6465

6566
```
6667
mkdir -p $GOPATH/src/github.com/canghai908

README.zh-CN.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ MS-Agent: 安装在 Zabbix Server 上, 用于接收 Zabbix Server 产生的告
3232

3333
## 兼容性
3434

35-
| zabbix 版本 | 兼容性 |
36-
|:----------| :----- |
37-
| 6.4.x ||
38-
| 6.2.x ||
39-
| 6.0.x ||
40-
| 5.4.x ||
41-
| 5.2.x ||
42-
| 5.0.x LTS ||
43-
| 4.4.x ||
44-
| 4.2.x ||
45-
| 4.0.x LTS ||
46-
| 3.4.x | 未测试 |
47-
| 3.2.x | 未测试 |
48-
| 3.0.x LTS | 未测试 |
35+
| zabbix 版本 | 兼容性 |
36+
|:-------------|:-------:|
37+
| 7.0.x LTS ||
38+
| 6.4.x ||
39+
| 6.2.x ||
40+
| 6.0.x LTS ||
41+
| 5.4.x ||
42+
| 5.2.x ||
43+
| 5.0.x LTS ||
44+
| 4.4.x ||
45+
| 4.2.x ||
46+
| 4.0.x LTS ||
47+
| 3.4.x | 未测试 |
48+
| 3.2.x | 未测试 |
49+
| 3.0.x LTS | 未测试 |
4950

5051
## 文档
5152

@@ -61,7 +62,7 @@ MS-Agent: 安装在 Zabbix Server 上, 用于接收 Zabbix Server 产生的告
6162

6263
## 编译
6364

64-
环境:go >=1.21
65+
环境:go >=1.22
6566

6667
```
6768
mkdir -p $GOPATH/src/github.com/canghai908

control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# release version
3-
version=2.1.5
3+
version=2.1.6
44

55
CWD=$(cd $(dirname $0)/; pwd)
66
cd $CWD

controllers/host.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func (c *HostController) URLMapping() {
2424
c.Mapping("getOneInterface", c.GetOneInterface)
2525
c.Mapping("GetMonWinFileSystem", c.GetMonWinFileSystem)
2626
c.Mapping("GetMonLinFileSystem", c.GetMonLinFileSystem)
27+
c.Mapping("GetGraph", c.GetGraph)
2728
}
2829

2930
// Post ...
@@ -80,8 +81,6 @@ func (c *HostController) GetOne() {
8081
c.Data["json"] = v.Error
8182
} else {
8283
c.Data["json"] = v
83-
c.ServeJSON()
84-
return
8584
}
8685
c.ServeJSON()
8786
return
@@ -258,3 +257,35 @@ func (c *HostController) GetMonLinFileSystem() {
258257
c.Data["json"] = HostInterfaceRes
259258
c.ServeJSON()
260259
}
260+
261+
// GetGraph
262+
// @Title 查看主机图形
263+
// @Description 查看图形
264+
// @Param X-Token header string true "x-token in header"
265+
// @Param hostid path string ture "hostid"
266+
// @Success 200 {object} models.MonItemList
267+
// @Failure 403
268+
// @router /graph/:hostid [post]
269+
func (c *HostController) GetGraph() {
270+
var v models.GraphReq
271+
err := json.Unmarshal(c.Ctx.Input.RequestBody, &v)
272+
if err != nil {
273+
HostInterfaceRes.Code = 500
274+
HostInterfaceRes.Message = err.Error()
275+
c.Data["json"] = HostInterfaceRes
276+
c.ServeJSON()
277+
}
278+
hostId := c.Ctx.Input.Param(":hostid")
279+
hs, err := models.GetGraphData(hostId, v.Start, v.End)
280+
if err != nil {
281+
HostInterfaceRes.Code = 500
282+
HostInterfaceRes.Message = err.Error()
283+
} else {
284+
HostInterfaceRes.Code = 200
285+
HostInterfaceRes.Message = "获取数据成功"
286+
HostInterfaceRes.Data.Items = hs
287+
HostInterfaceRes.Data.Total = int64(len(hs))
288+
}
289+
c.Data["json"] = HostInterfaceRes
290+
c.ServeJSON()
291+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/json-iterator/go v1.1.12
2020
github.com/lib/pq v1.10.7
2121
github.com/manifoldco/promptui v0.9.0
22+
github.com/patrickmn/go-cache v2.1.0+incompatible
2223
github.com/pterm/pterm v0.12.75
2324
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49
2425
github.com/shopspring/decimal v1.3.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042
184184
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
185185
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
186186
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
187+
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
188+
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
187189
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
188190
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
189191
github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=

models/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func ModelsInit(zabbix_web, zabbix_user, zabbix_pass, zabbix_token,
167167
}
168168
logs.Info("Zabbix API connected!Zabbix version:", version)
169169

170-
//zabbix web login
171-
// LoginZabbixWeb(zabbix_web, zabbix_user, zabbix_pass)
170+
// zabbix web login
171+
LoginZabbixWeb(zabbix_web, zabbix_user, zabbix_pass)
172172

173173
//redis
174174
res_db, err := strconv.Atoi(redis_db)

models/channel.go

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"zbxtable/utils"
1313
)
1414

15-
//alert gen by rules
15+
// alert gen by rules
1616
func GenAlert(alarm *Alarm) bool {
1717
o := orm.NewOrm()
1818
var rules []Rule
@@ -143,31 +143,41 @@ func GenAlert(alarm *Alarm) bool {
143143
return true
144144
}
145145

146-
func GetEventUser(groupIds, userIds, channel string) (list []string, err error) {
146+
// GetEventUser 查找事件用户信息
147+
func GetEventUser(groupIds, userIds string) (list []string, err error) {
147148
o := orm.NewOrm()
148-
//get grouids
149-
var group UserGroup
150-
var gList []UserGroup
151-
gids := strings.Split(groupIds, ",")
152-
_, err = o.QueryTable(group).Filter("id__in", gids).All(&gList)
153-
if err != nil {
154-
return []string{}, err
155-
}
156-
//get group userid
149+
//用户组信息,判断用户组是否为空
157150
var guidList []string
158-
if len(gList) != 0 {
159-
for _, v := range gList {
160-
ids := strings.Split(v.Member, ",")
161-
for _, vv := range ids {
162-
guidList = append(guidList, vv)
151+
if groupIds != "" {
152+
var group UserGroup
153+
var gList []UserGroup
154+
//组分隔
155+
gids := strings.Split(groupIds, ",")
156+
_, err = o.QueryTable(group).Filter("id__in", gids).All(&gList)
157+
if err != nil {
158+
return
159+
}
160+
//get group userid
161+
if len(gList) != 0 {
162+
for _, v := range gList {
163+
ids := strings.Split(v.Member, ",")
164+
for _, vv := range ids {
165+
guidList = append(guidList, vv)
166+
}
163167
}
164168
}
165169
}
170+
var ids []string
166171
uid := strings.Split(userIds, ",")
172+
if len(guidList) != 0 {
173+
//添加用户组
174+
ids = utils.UniqueArr(utils.MergeArr(guidList, uid))
175+
} else {
176+
//添加用户
177+
ids = uid
178+
}
167179
//get all userids unique
168-
ids := utils.UniqueArr(utils.MergeArr(guidList, uid))
169180
if len(ids) != 0 {
170-
171181
var user Manager
172182
var plist []Manager
173183
_, err = o.QueryTable(user).Filter("id__in", ids).All(&plist, "id", "username",
@@ -204,8 +214,8 @@ func sendEvent(event *Event) {
204214
}
205215
continue
206216
}
207-
//popuser
208-
toUsers, err := GetEventUser(event.GroupIds, event.UserIds, v)
217+
//GetEventUser
218+
toUsers, err := GetEventUser(event.GroupIds, event.UserIds)
209219
if err != nil {
210220
logs.Error(err)
211221
return
@@ -237,7 +247,7 @@ func sendEvent(event *Event) {
237247
}
238248
}
239249

240-
//mut
250+
// mut
241251
func IsMuted(event *Event) bool {
242252
o := orm.NewOrm()
243253
var rules []Rule
@@ -280,7 +290,7 @@ func IsMuted(event *Event) bool {
280290
return false
281291
}
282292

283-
//IsMuteTime not
293+
// IsMuteTime not
284294
func IsMuteTime(event *Event, rule *Rule) bool {
285295
stime, _ := utils.ParTime(rule.Stime)
286296
etime, _ := utils.ParTime(rule.Etime)

models/cron.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ func GetTypeHostList() error {
339339
p, _, err := GetHostsList(v)
340340
if err != nil {
341341
logs.Error(err)
342-
return err
343342
continue
344343
}
345344
//hosts info to redis
@@ -350,7 +349,6 @@ func GetTypeHostList() error {
350349
err = RDB.Set(ctx, v+"_OVERVIEW", string(hostsdata), 3600*time.Second).Err()
351350
if err != nil {
352351
logs.Error(err)
353-
return err
354352
continue
355353
}
356354
//inventor info to redis
@@ -375,7 +373,6 @@ func GetTypeHostList() error {
375373
err = RDB.Set(ctx, v+"_INVENTORY", string(data), 3600*time.Second).Err()
376374
if err != nil {
377375
logs.Error(err)
378-
return err
379376
continue
380377
}
381378
}
@@ -392,7 +389,7 @@ func EgressCache() error {
392389
}
393390
var itemlist []string
394391
//空返回
395-
if v.InOne == "" || v.OutOne == "" || v.InTwo == "" || v.OutTwo == "" {
392+
if v.InOne == "" && v.OutOne == "" && v.InTwo == "" && v.OutTwo == "" {
396393
var dList EgressList
397394
dList.NameOne = v.NameOne
398395
dList.InOne = "0Kb/s"

0 commit comments

Comments
 (0)