-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (48 loc) · 1.08 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
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"github.com/keybase/go-ps"
"github.com/nlopes/slack"
"gopkg.in/yaml.v2"
)
func main() {
conf := struct {
Token string `yaml:"token"`
ChatID string `yaml:"chatid"`
}{}
data, err := ioutil.ReadFile(".pscheck")
if err != nil {
fmt.Println("Can't read .pscheck file")
os.Exit(0)
}
err = yaml.Unmarshal([]byte(data), &conf)
if err != nil {
fmt.Printf("Can't parse .pscheck file: %v\n", err)
os.Exit(0)
}
if len(os.Args) < 3 {
fmt.Println("Sends slack message is process with binary doesn't run.")
fmt.Println("Usage: pscheck {executable name (example: lim)} {servername for chat message}")
os.Exit(0)
}
pp, err := ps.Processes()
if err != nil {
log.Fatalf("err: %s", err)
}
if len(pp) <= 0 {
log.Fatalf("should have processes")
}
for _, p := range pp {
if p.Executable() == os.Args[1] {
os.Exit(0)
}
}
api := slack.New(conf.Token)
api.PostMessage(
conf.ChatID,
slack.MsgOptionText(fmt.Sprintf("PSCheck (from cron): No '%s' process running on server %s", os.Args[1], os.Args[2]), false),
)
}