fix: all组显示所有主机 + playbook warn模块改为debug
This commit is contained in:
Binary file not shown.
@@ -275,6 +275,12 @@ func (s *AnsibleService) ListGroups() []models.HostGroup {
|
|||||||
// 动态展开组内主机(通过 host.Groups 字段关联,而非 group.Hosts)
|
// 动态展开组内主机(通过 host.Groups 字段关联,而非 group.Hosts)
|
||||||
var hostList []models.Host
|
var hostList []models.Host
|
||||||
for _, h := range s.hosts {
|
for _, h := range s.hosts {
|
||||||
|
if gcopy.Name == "all" {
|
||||||
|
// all 组包含所有主机
|
||||||
|
hcopy := *h
|
||||||
|
hostList = append(hostList, hcopy)
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, hGroup := range h.Groups {
|
for _, hGroup := range h.Groups {
|
||||||
if hGroup == gcopy.Name {
|
if hGroup == gcopy.Name {
|
||||||
hcopy := *h
|
hcopy := *h
|
||||||
@@ -282,7 +288,7 @@ func (s *AnsibleService) ListGroups() []models.HostGroup {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 也检查主机的默认组(all/ungrouped)
|
// 也检查主机的默认组(ungrouped)
|
||||||
if len(h.Groups) == 0 && gcopy.Name == "ungrouped" {
|
if len(h.Groups) == 0 && gcopy.Name == "ungrouped" {
|
||||||
hcopy := *h
|
hcopy := *h
|
||||||
hostList = append(hostList, hcopy)
|
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",
|
"id": "706f8ce7",
|
||||||
"name": "nas",
|
"name": "nas",
|
||||||
@@ -58,5 +28,35 @@
|
|||||||
"last_check": "2026-05-13T18:27:19.272543838+08:00",
|
"last_check": "2026-05-13T18:27:19.272543838+08:00",
|
||||||
"created_at": "0001-01-01T00:00:00Z",
|
"created_at": "0001-01-01T00:00:00Z",
|
||||||
"updated_at": "2026-05-13T18:23:27.433461112+08:00"
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -48,6 +48,6 @@
|
|||||||
when: cpu_usage | int >= crit_threshold
|
when: cpu_usage | int >= crit_threshold
|
||||||
|
|
||||||
- name: 警告判断
|
- name: 警告判断
|
||||||
warn:
|
debug:
|
||||||
msg: "{{ inventory_hostname }} CPU 使用率超过 {{ warn_threshold }}%: {{ cpu_usage }}%"
|
msg: "⚠️ WARNING: {{ inventory_hostname }} CPU 使用率超过 {{ warn_threshold }}%: {{ cpu_usage }}%"
|
||||||
when: cpu_usage | int >= warn_threshold and cpu_usage | int < crit_threshold
|
when: cpu_usage | int >= warn_threshold and cpu_usage | int < crit_threshold
|
||||||
|
|||||||
Reference in New Issue
Block a user