Skip to content

Commit

Permalink
feat: target add os type (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwb0214 authored Aug 1, 2024
1 parent 6a0e7a8 commit 96d3b48
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions center/router/router_heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package router
import (
"compress/gzip"
"encoding/json"
"fmt"
"errors"
"io/ioutil"
"strings"
"time"
Expand Down Expand Up @@ -57,7 +57,7 @@ func HandleHeartbeat(c *gin.Context, ctx *ctx.Context, engineName string, metaSe
}

if req.Hostname == "" {
return req, fmt.Errorf("hostname is required", 400)
return req, errors.New("hostname is required")
}

// maybe from pushgw
Expand Down Expand Up @@ -121,6 +121,10 @@ func HandleHeartbeat(c *gin.Context, ctx *ctx.Context, engineName string, metaSe
field["agent_version"] = req.AgentVersion
}

if req.OS != "" && req.OS != target.OS {
field["os"] = req.OS
}

if len(field) > 0 {
err := target.UpdateFieldsMap(ctx, field)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions models/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ type Target struct {
HostIp string `gorm:"column:host_ip;varchar(15);default:'';comment:IPv4 string;index:idx_host_ip"`
AgentVersion string `gorm:"column:agent_version;varchar(255);default:'';comment:agent version;index:idx_agent_version"`
EngineName string `gorm:"column:engine_name;varchar(255);default:'';comment:engine name;index:idx_engine_name"`
OS string `gorm:"column:os;varchar(31);default:'';comment:os type;index:idx_os"`
}

type Datasource struct {
Expand Down
6 changes: 3 additions & 3 deletions models/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type Target struct {
HostIp string `json:"host_ip"` //ipv4,do not needs range select
AgentVersion string `json:"agent_version"`
EngineName string `json:"engine_name"`
OS string `json:"os" gorm:"column:os"`

UnixTime int64 `json:"unixtime" gorm:"-"`
Offset int64 `json:"offset" gorm:"-"`
TargetUp float64 `json:"target_up" gorm:"-"`
MemUtil float64 `json:"mem_util" gorm:"-"`
CpuNum int `json:"cpu_num" gorm:"-"`
CpuUtil float64 `json:"cpu_util" gorm:"-"`
OS string `json:"os" gorm:"-"`
Arch string `json:"arch" gorm:"-"`
RemoteAddr string `json:"remote_addr" gorm:"-"`
}
Expand Down Expand Up @@ -111,7 +111,8 @@ func BuildTargetWhereWithQuery(query string) BuildTargetWhereOption {
arr := strings.Fields(query)
for i := 0; i < len(arr); i++ {
q := "%" + arr[i] + "%"
session = session.Where("ident like ? or note like ? or tags like ?", q, q, q)
session = session.Where("ident like ? or note like ? or tags like ? "+
"or os like ?", q, q, q, q)
}
}
return session
Expand Down Expand Up @@ -418,7 +419,6 @@ func (t *Target) FillMeta(meta *HostMeta) {
t.CpuNum = meta.CpuNum
t.UnixTime = meta.UnixTime
t.Offset = meta.Offset
t.OS = meta.OS
t.Arch = meta.Arch
t.RemoteAddr = meta.RemoteAddr
}
Expand Down

0 comments on commit 96d3b48

Please sign in to comment.