fix: all组显示所有主机 + playbook warn模块改为debug

此提交包含在:
Hermes Agent
2026-05-18 17:26:51 +08:00
父節點 d58e860059
當前提交 ecb8afd732
共有 4 個檔案被更改,包括 39 行新增33 行删除
二進制
查看文件
未顯示二進位檔案。
+7 -1
查看文件
@@ -275,6 +275,12 @@ func (s *AnsibleService) ListGroups() []models.HostGroup {
// 动态展开组内主机(通过 host.Groups 字段关联,而非 group.Hosts)
var hostList []models.Host
for _, h := range s.hosts {
if gcopy.Name == "all" {
// all 组包含所有主机
hcopy := *h
hostList = append(hostList, hcopy)
continue
}
for _, hGroup := range h.Groups {
if hGroup == gcopy.Name {
hcopy := *h
@@ -282,7 +288,7 @@ func (s *AnsibleService) ListGroups() []models.HostGroup {
break
}
}
// 也检查主机的默认组(all/ungrouped)
// 也检查主机的默认组(ungrouped)
if len(h.Groups) == 0 && gcopy.Name == "ungrouped" {
hcopy := *h
hostList = append(hostList, hcopy)
+30 -30
查看文件
@@ -1,34 +1,4 @@
[
{
"id": "57884720",
"name": "scmp46",
"ip": "172.16.11.42",
"port": 22,
"username": "root",
"password": "STC#scmp%0818",
"groups": [
"zebu_user01"
],
"status": "online",
"last_check": "2026-05-13T18:30:38.103119534+08:00",
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "2026-05-13T18:28:16.71131472+08:00"
},
{
"id": "5150c740",
"name": "scmp47",
"ip": "172.16.11.44",
"port": 22,
"username": "root",
"password": "STC#scmp%0818",
"groups": [
"zebu_user01"
],
"status": "online",
"last_check": "2026-05-13T18:30:33.343216547+08:00",
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "2026-05-13T18:28:08.656450224+08:00"
},
{
"id": "706f8ce7",
"name": "nas",
@@ -58,5 +28,35 @@
"last_check": "2026-05-13T18:27:19.272543838+08:00",
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "2026-05-13T18:23:27.433461112+08:00"
},
{
"id": "57884720",
"name": "scmp46",
"ip": "172.16.11.42",
"port": 22,
"username": "root",
"password": "STC#scmp%0818",
"groups": [
"zebu_user01"
],
"status": "online",
"last_check": "2026-05-13T18:30:38.103119534+08:00",
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "2026-05-13T18:28:16.71131472+08:00"
},
{
"id": "5150c740",
"name": "scmp47",
"ip": "172.16.11.44",
"port": 22,
"username": "root",
"password": "STC#scmp%0818",
"groups": [
"zebu_user01"
],
"status": "online",
"last_check": "2026-05-13T18:30:33.343216547+08:00",
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "2026-05-13T18:28:08.656450224+08:00"
}
]
+2 -2
查看文件
@@ -48,6 +48,6 @@
when: cpu_usage | int >= crit_threshold
- name: 警告判断
warn:
msg: "{{ inventory_hostname }} CPU 使用率超过 {{ warn_threshold }}%: {{ cpu_usage }}%"
debug:
msg: "⚠️ WARNING: {{ inventory_hostname }} CPU 使用率超过 {{ warn_threshold }}%: {{ cpu_usage }}%"
when: cpu_usage | int >= warn_threshold and cpu_usage | int < crit_threshold