-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.go
57 lines (51 loc) · 1.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"strings"
"time"
"os"
)
var (
dingdingToken string //钉钉告警url
podId string //PodId
folder string //日期命名文件夹
postfix string //文件名的时间后缀
env string //部署环境
projectGroup string //项目组
bucketName string //OSS bucketName
locaFilename string //OOM DumpFile
)
func init() {
flag.StringVar(&podId, "k", "ops", "PodId")
flag.StringVar(&env, "e", "test", "ENV")
folder = time.Now().Format("20060102")
postfix = time.Now().Format("20060102150405")
locaFilename = "/dumps/oom" //正式
}
// 判断所给路径文件是否存在
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func main() {
flag.Parse()
projectGroup = fmt.Sprintf(strings.Split(podId,"-")[0]) // podId: "ops-demo"
bucketName = fmt.Sprintf("%s-disaster",projectGroup) //正式的bucketName,如ops-disaster
// 判断dump文件是否存在
exist, err := PathExists(locaFilename)
if err != nil {
fmt.Printf("get dir error![%v]\n", err)
return
}
if exist {
alarm()
upload()
}
}