2025-02-26 18:58:43 +08:00
|
|
|
|
package method
|
|
|
|
|
|
|
|
|
|
import (
|
2025-03-04 17:40:37 +08:00
|
|
|
|
"bufio"
|
2025-03-11 16:04:26 +08:00
|
|
|
|
"dt_automate/tool"
|
2025-02-26 18:58:43 +08:00
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
2025-03-04 17:40:37 +08:00
|
|
|
|
"os"
|
2025-02-26 18:58:43 +08:00
|
|
|
|
|
|
|
|
|
"github.com/playwright-community/playwright-go"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ZWW_DTCLOUD() {
|
|
|
|
|
// 启动 Playwright
|
|
|
|
|
pw, err := playwright.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not start Playwright: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer pw.Stop()
|
|
|
|
|
|
|
|
|
|
// 启动浏览器(Chromium)
|
|
|
|
|
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
|
|
|
|
|
Headless: playwright.Bool(false), // 设置为 false 以显示浏览器界面
|
|
|
|
|
Args: []string{
|
|
|
|
|
"--ignore-certificate-errors", // 忽略证书错误[^28^][^29^]
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not launch browser: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer browser.Close()
|
|
|
|
|
|
|
|
|
|
// 创建一个新页面
|
|
|
|
|
page, err := browser.NewPage()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not create page: %v", err)
|
|
|
|
|
}
|
|
|
|
|
// 设置浏览器窗口大小
|
|
|
|
|
err = page.SetViewportSize(1920, 1080) // 宽度为 1200px,高度为 800px
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("无法设置浏览器窗口大小: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 导航到指定网址
|
2025-03-18 19:03:40 +08:00
|
|
|
|
_, err = page.Goto("https://ops.zww.dtcloud.com/login", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit})
|
2025-02-26 18:58:43 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not go to the page: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// page.WaitForTimeout(4000)
|
|
|
|
|
//输入用户名
|
2025-03-11 16:04:26 +08:00
|
|
|
|
page.Locator(`.el-input__inner`).Nth(0).Fill(tool.KeyStr("rpcI3bxLzCdjgBOnML5A/7tajCNKxi3ditUNMIPVqd9jAG0mMy8XQCvkPh5pJ1OKUIGK0UyEaD1tvigSlTTpH0VQJXIExhLaEhbDZFJxZo6UM2yuarvsYQ0uceridCvK1izQEypk98UcuFwyyd9WOklIjOaz8fW0pYv3C+JnXBOHpnvWVyPAaAirr5jtKmOsnBEIvv7XXVHnS1zSd4f5UbVjVZ5sfmPW064cHTJrqo45J6uboQ1AkI0ajiXWhYV3wiBTRfVcMatb4rirErBwG731Vte2rImu2BQmH+bgeDOFgE1UXOsH7pSOrQy6wky/aHxgH7lSvYZ8nTPSvGqW4w=="))
|
2025-02-26 18:58:43 +08:00
|
|
|
|
//输入密码
|
2025-03-11 16:04:26 +08:00
|
|
|
|
page.Locator(`.el-input__inner`).Nth(1).Fill(tool.KeyStr("YesC+4BrWvL3uvLRq0dWFnneTXnoMyvORhRjN9ZhU+85fWOLRf7naq/O51wbOXtOOPnPIlMjGstB7Lt0kVsNVrd4EEpVKfDZC9XSzB0SFVjR4P47gd02vjgR+6gWIkFhkDL70Bx7Z3+Shg7JSqTovJtpMKisamfLfcnu6J9exbmvGMAQk4vr+cha2QWeD/kBExW/SnYueL4RBiZVTtumbTq8gBIj8uceCL9NpvEPGnverflIiYn+fUGH3xhY+y8sCa7NZA3YXXqTxF6FYC0cTsXqpv+O9EuK81fGXIswt2Y/O8hIE5Qp3jmdxmkxr/zlnVjP1vZs7zS4ONkogXOhzA=="))
|
2025-03-04 17:40:37 +08:00
|
|
|
|
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
fmt.Print("请输入验证码:")
|
2025-03-04 17:40:37 +08:00
|
|
|
|
input, _ := reader.ReadString('\n')
|
|
|
|
|
|
2025-02-26 18:58:43 +08:00
|
|
|
|
//输入验证码
|
2025-03-04 17:40:37 +08:00
|
|
|
|
page.Locator(`.el-input__inner`).Nth(2).Fill(input)
|
|
|
|
|
log.Println("当前验证码为:", input)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.WaitForTimeout(2000)
|
|
|
|
|
//登录
|
|
|
|
|
if err := page.Locator(".el-button.login-form-item.login-btn.el-button--primary").Click(); err != nil {
|
|
|
|
|
log.Fatalf("could not click button: %v", err)
|
|
|
|
|
}
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.WaitForTimeout(20000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
//运维中心主页
|
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_man.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_man.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "运维中心主页")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/console/om/capacity/overview?regionId=-1", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //跳转到运维中心概览
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_01.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_01.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "运维中心概览")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/console/om/capacity/resource?regionId=-1", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //运维-资源容量
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_02.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_02.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "运维-资源容量")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/region/dtcloud2/console/om/monitor/overview", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //监控-概览
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_03.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_03.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "监控-概览")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/region/dtcloud2/console/om/monitor/resource", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //监控-资源监控-物理服务器
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-03-04 17:40:37 +08:00
|
|
|
|
page.Locator(`.arco-tree.arco-tree-show-line`).Locator(`div`).Nth(8).Locator(`span`).Nth(2).Locator(`span`).Nth(0).Click()
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Locator(`div[data-test-id="PhysicalServer"]`).Click()
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.WaitForTimeout(4000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_04.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_04.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "监控-资源监控-物理服务器")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/region/dtcloud2/console/om/alert/view", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //监控-告警-告警查看
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-03-04 17:40:37 +08:00
|
|
|
|
page.Locator(`.arco-space-item`).Nth(0).Locator(`div`).Nth(1).Locator(`button`).Click()
|
2025-02-27 18:37:03 +08:00
|
|
|
|
page.WaitForTimeout(6000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_05.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_05.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "监控-告警-告警查看")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/region/dtcloud2/console/om/alert/history", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //监控-告警历史
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Locator(`.arco-btn.arco-btn-outline.arco-btn-size-default.arco-btn-shape-square`).Nth(0).Click()
|
2025-02-27 18:37:03 +08:00
|
|
|
|
page.WaitForTimeout(1000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Locator(`.arco-input-tag-input.arco-input-tag-input-size-default.arco-input-tag-input-autowidth`).Click()
|
2025-02-27 18:37:03 +08:00
|
|
|
|
page.Locator(`.arco-select-option-wrapper`).Nth(0).Locator(`.arco-checkbox-mask`).Click()
|
2025-03-06 18:53:00 +08:00
|
|
|
|
page.Locator(`.arco-btn.arco-btn-primary.arco-btn-size-mini.arco-btn-shape-square`).Click()
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.WaitForTimeout(1000)
|
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_06.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_06.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "监控-告警--告警历史")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/region/dtcloud2/console/om/health-inspection/outputs?page=1&size=10&order=createTime%3Adesc&searchResult=%7B%7D", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //运维-监控巡检-巡检结果
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_07.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
|
|
|
|
// tool.Jietu("img/hw_dtcloud_07.png")
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "运维-监控巡检-巡检结果")
|
2025-03-18 19:03:40 +08:00
|
|
|
|
page.Goto("https://ops.zww.dtcloud.com/console/om/capacity/service?regionId=-1", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateCommit}) //运维-容量-云服务容量
|
|
|
|
|
page.WaitForTimeout(20000)
|
2025-02-26 18:58:43 +08:00
|
|
|
|
page.Screenshot(playwright.PageScreenshotOptions{
|
|
|
|
|
Path: playwright.String("img/zww_dtcloud_08.png"),
|
|
|
|
|
FullPage: playwright.Bool(false),
|
|
|
|
|
})
|
2025-03-20 19:05:57 +08:00
|
|
|
|
log.Printf("Page title is: %s\n", "运维-容量-云服务容量")
|
2025-02-26 18:58:43 +08:00
|
|
|
|
// 获取页面标题
|
|
|
|
|
title, err := page.Title()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not get title: %v", err)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Page title is: %s\n", title)
|
|
|
|
|
page.WaitForTimeout(5000)
|
|
|
|
|
}
|