OVH VPS-1新加坡补货监控代码
OVH VPS-x系列对别的商家绝对是降维打击。然后新加坡这机器总是卖断货,放货一天然后断货一周甚至更久。
上周本来入了一个想自用,结果被人高价给收去了。我是贪财之人,只要有溢价,我就忍不住把机器卖了。。。
好吧,现在就只能继续蹲了。让AI写了个小工具来监控一下。我唯一做的有价值的事,只是告诉AI需要监视的API链接。
代码是GO的,运行方法就是 ./checkstock sgp 这样了。只是提供思路了,如果需要,你可以让AI把它改成任何语言以及形式等。
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
"time"
)
const (
telegramToken = "Telegram机器人token"
telegramChatID = "Telegram发送通知的会话ID"
apiURL = "https://api.ovh.com/1.0/vps/order/rule/datacenter?ovhSubsidiary=IE&os=Ubuntu+25.04&planCode=vps-2025-model1"
)
type Data struct {
Datacenters []struct {
Datacenter string `json:"datacenter"`
Status string `json:"status"`
LinuxStatus string `json:"linuxStatus"`
WindowsStatus string `json:"windowsStatus"`
} `json:"datacenters"`
}
func isAvailable(s string) bool {
return s == "available" || s == "out-of-stock-preorder-allowed"
}
func sendTelegram(msg string) {
endpoint := fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", telegramToken)
data := url.Values{}
data.Set("chat_id", telegramChatID)
data.Set("text", msg)
http.PostForm(endpoint, data)
}
func check(target string) (bool, error) {
resp, err := http.Get(apiURL)
if err != nil {
return false, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return false, err
}
var data Data
if err := json.Unmarshal(body, &data); err != nil {
return false, err
}
fmt.Printf("[%s] 当前各数据中心状态:\n", time.Now().Format("2006-01-02 15:04:05"))
for _, d := range data.Datacenters {
fmt.Printf(" %s: status=%s, linux=%s, windows=%s\n",
d.Datacenter, d.Status, d.LinuxStatus, d.WindowsStatus)
}
for _, d := range data.Datacenters {
if strings.EqualFold(d.Datacenter, target) {
return isAvailable(d.Status) && isAvailable(d.LinuxStatus), nil
}
}
fmt.Printf("%s 不存在\n", target)
return false, nil
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: checkstock <datacenter_code>")
os.Exit(1)
}
target := strings.ToUpper(strings.TrimSpace(os.Args[1]))
startMsg := fmt.Sprintf("监控启动:正在监控 %s 库存状态", target)
fmt.Println(startMsg)
sendTelegram(startMsg)
for {
ok, err := check(target)
if err != nil {
fmt.Println("Error:", err)
} else if ok {
msg := fmt.Sprintf("🚀 %s 有货(含预购)!", target)
fmt.Println(msg)
sendTelegram(msg)
os.Exit(0)
}
fmt.Printf("[%s] 无货,等待60秒后重试...\n----\n", time.Now().Format("2006-01-02 15:04:05"))
time.Sleep(60 * time.Second)
}
}
运行示例:
[2025-10-09 01:54:20] 当前各数据中心状态:
GRA: status=available, linux=available, windows=available
DE: status=available, linux=available, windows=available
BHS: status=available, linux=available, windows=available
SBG: status=out-of-stock-preorder-allowed, linux=out-of-stock-preorder-allowed, windows=out-of-stock-preorder-allowed
WAW: status=out-of-stock-preorder-allowed, linux=out-of-stock-preorder-allowed, windows=available
SGP: status=out-of-stock, linux=out-of-stock, windows=out-of-stock
UK: status=out-of-stock, linux=out-of-stock, windows=out-of-stock
[2025-10-09 01:54:20] 无货,等待60秒后重试...
已有 2 条评论