Skip to content

Commit

Permalink
Merge pull request #113 from canghai908/dev
Browse files Browse the repository at this point in the history
update to 2.1.6
  • Loading branch information
canghai908 authored Sep 22, 2024
2 parents c839ddf + 0303aa9 commit 0b4206e
Show file tree
Hide file tree
Showing 18 changed files with 367 additions and 170 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ MS-Agent: Installed on Zabbix Server, used to receive alarms generated by Zabbix
## Compatibility

| Zabbix Version | Compatibility |
|:---------------| :------------ |
| 6.4.x ||
| 6.2.x ||
| 6.0.x ||
| 5.4.x ||
| 5.2.x ||
| 5.0.x LTS ||
| 4.4.x ||
| 4.2.x ||
| 4.0.x LTS ||
| 3.4.x | untested |
| 3.2.x | untested |
| 3.0.x LTS | untested |
|:---------------|:-------------:|
| 7.0.x LTS ||
| 6.4.x ||
| 6.2.x ||
| 6.0.x LTS ||
| 5.4.x ||
| 5.2.x ||
| 5.0.x LTS ||
| 4.4.x ||
| 4.2.x ||
| 4.0.x LTS ||
| 3.4.x | untested |
| 3.2.x | untested |
| 3.0.x LTS | untested |

## Documentation

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

## Compile

go >=1.21
go >=1.22

```
mkdir -p $GOPATH/src/github.com/canghai908
Expand Down
31 changes: 16 additions & 15 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ MS-Agent: 安装在 Zabbix Server 上, 用于接收 Zabbix Server 产生的告

## 兼容性

| zabbix 版本 | 兼容性 |
|:----------| :----- |
| 6.4.x ||
| 6.2.x ||
| 6.0.x ||
| 5.4.x ||
| 5.2.x ||
| 5.0.x LTS ||
| 4.4.x ||
| 4.2.x ||
| 4.0.x LTS ||
| 3.4.x | 未测试 |
| 3.2.x | 未测试 |
| 3.0.x LTS | 未测试 |
| zabbix 版本 | 兼容性 |
|:-------------|:-------:|
| 7.0.x LTS ||
| 6.4.x ||
| 6.2.x ||
| 6.0.x LTS ||
| 5.4.x ||
| 5.2.x ||
| 5.0.x LTS ||
| 4.4.x ||
| 4.2.x ||
| 4.0.x LTS ||
| 3.4.x | 未测试 |
| 3.2.x | 未测试 |
| 3.0.x LTS | 未测试 |

## 文档

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

## 编译

环境:go >=1.21
环境:go >=1.22

```
mkdir -p $GOPATH/src/github.com/canghai908
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# release version
version=2.1.5
version=2.1.6

CWD=$(cd $(dirname $0)/; pwd)
cd $CWD
Expand Down
35 changes: 33 additions & 2 deletions controllers/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (c *HostController) URLMapping() {
c.Mapping("getOneInterface", c.GetOneInterface)
c.Mapping("GetMonWinFileSystem", c.GetMonWinFileSystem)
c.Mapping("GetMonLinFileSystem", c.GetMonLinFileSystem)
c.Mapping("GetGraph", c.GetGraph)
}

// Post ...
Expand Down Expand Up @@ -80,8 +81,6 @@ func (c *HostController) GetOne() {
c.Data["json"] = v.Error
} else {
c.Data["json"] = v
c.ServeJSON()
return
}
c.ServeJSON()
return
Expand Down Expand Up @@ -258,3 +257,35 @@ func (c *HostController) GetMonLinFileSystem() {
c.Data["json"] = HostInterfaceRes
c.ServeJSON()
}

// GetGraph
// @Title 查看主机图形
// @Description 查看图形
// @Param X-Token header string true "x-token in header"
// @Param hostid path string ture "hostid"
// @Success 200 {object} models.MonItemList
// @Failure 403
// @router /graph/:hostid [post]
func (c *HostController) GetGraph() {
var v models.GraphReq
err := json.Unmarshal(c.Ctx.Input.RequestBody, &v)
if err != nil {
HostInterfaceRes.Code = 500
HostInterfaceRes.Message = err.Error()
c.Data["json"] = HostInterfaceRes
c.ServeJSON()
}
hostId := c.Ctx.Input.Param(":hostid")
hs, err := models.GetGraphData(hostId, v.Start, v.End)
if err != nil {
HostInterfaceRes.Code = 500
HostInterfaceRes.Message = err.Error()
} else {
HostInterfaceRes.Code = 200
HostInterfaceRes.Message = "获取数据成功"
HostInterfaceRes.Data.Items = hs
HostInterfaceRes.Data.Total = int64(len(hs))
}
c.Data["json"] = HostInterfaceRes
c.ServeJSON()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/lib/pq v1.10.7
github.com/manifoldco/promptui v0.9.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pterm/pterm v0.12.75
github.com/sanbornm/go-selfupdate v0.0.0-20210106163404-c9b625feac49
github.com/shopspring/decimal v1.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
Expand Down
4 changes: 2 additions & 2 deletions models/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ func ModelsInit(zabbix_web, zabbix_user, zabbix_pass, zabbix_token,
}
logs.Info("Zabbix API connected!Zabbix version:", version)

//zabbix web login
// LoginZabbixWeb(zabbix_web, zabbix_user, zabbix_pass)
// zabbix web login
LoginZabbixWeb(zabbix_web, zabbix_user, zabbix_pass)

//redis
res_db, err := strconv.Atoi(redis_db)
Expand Down
54 changes: 32 additions & 22 deletions models/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"zbxtable/utils"
)

//alert gen by rules
// alert gen by rules
func GenAlert(alarm *Alarm) bool {
o := orm.NewOrm()
var rules []Rule
Expand Down Expand Up @@ -143,31 +143,41 @@ func GenAlert(alarm *Alarm) bool {
return true
}

func GetEventUser(groupIds, userIds, channel string) (list []string, err error) {
// GetEventUser 查找事件用户信息
func GetEventUser(groupIds, userIds string) (list []string, err error) {
o := orm.NewOrm()
//get grouids
var group UserGroup
var gList []UserGroup
gids := strings.Split(groupIds, ",")
_, err = o.QueryTable(group).Filter("id__in", gids).All(&gList)
if err != nil {
return []string{}, err
}
//get group userid
//用户组信息,判断用户组是否为空
var guidList []string
if len(gList) != 0 {
for _, v := range gList {
ids := strings.Split(v.Member, ",")
for _, vv := range ids {
guidList = append(guidList, vv)
if groupIds != "" {
var group UserGroup
var gList []UserGroup
//组分隔
gids := strings.Split(groupIds, ",")
_, err = o.QueryTable(group).Filter("id__in", gids).All(&gList)
if err != nil {
return
}
//get group userid
if len(gList) != 0 {
for _, v := range gList {
ids := strings.Split(v.Member, ",")
for _, vv := range ids {
guidList = append(guidList, vv)
}
}
}
}
var ids []string
uid := strings.Split(userIds, ",")
if len(guidList) != 0 {
//添加用户组
ids = utils.UniqueArr(utils.MergeArr(guidList, uid))
} else {
//添加用户
ids = uid
}
//get all userids unique
ids := utils.UniqueArr(utils.MergeArr(guidList, uid))
if len(ids) != 0 {

var user Manager
var plist []Manager
_, err = o.QueryTable(user).Filter("id__in", ids).All(&plist, "id", "username",
Expand Down Expand Up @@ -204,8 +214,8 @@ func sendEvent(event *Event) {
}
continue
}
//popuser
toUsers, err := GetEventUser(event.GroupIds, event.UserIds, v)
//GetEventUser
toUsers, err := GetEventUser(event.GroupIds, event.UserIds)
if err != nil {
logs.Error(err)
return
Expand Down Expand Up @@ -237,7 +247,7 @@ func sendEvent(event *Event) {
}
}

//mut
// mut
func IsMuted(event *Event) bool {
o := orm.NewOrm()
var rules []Rule
Expand Down Expand Up @@ -280,7 +290,7 @@ func IsMuted(event *Event) bool {
return false
}

//IsMuteTime not
// IsMuteTime not
func IsMuteTime(event *Event, rule *Rule) bool {
stime, _ := utils.ParTime(rule.Stime)
etime, _ := utils.ParTime(rule.Etime)
Expand Down
5 changes: 1 addition & 4 deletions models/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ func GetTypeHostList() error {
p, _, err := GetHostsList(v)
if err != nil {
logs.Error(err)
return err
continue
}
//hosts info to redis
Expand All @@ -350,7 +349,6 @@ func GetTypeHostList() error {
err = RDB.Set(ctx, v+"_OVERVIEW", string(hostsdata), 3600*time.Second).Err()
if err != nil {
logs.Error(err)
return err
continue
}
//inventor info to redis
Expand All @@ -375,7 +373,6 @@ func GetTypeHostList() error {
err = RDB.Set(ctx, v+"_INVENTORY", string(data), 3600*time.Second).Err()
if err != nil {
logs.Error(err)
return err
continue
}
}
Expand All @@ -392,7 +389,7 @@ func EgressCache() error {
}
var itemlist []string
//空返回
if v.InOne == "" || v.OutOne == "" || v.InTwo == "" || v.OutTwo == "" {
if v.InOne == "" && v.OutOne == "" && v.InTwo == "" && v.OutTwo == "" {
var dList EgressList
dList.NameOne = v.NameOne
dList.InOne = "0Kb/s"
Expand Down
Loading

0 comments on commit 0b4206e

Please sign in to comment.