forked from codeskyblue/gosuv
-
Notifications
You must be signed in to change notification settings - Fork 10
/
programs.go
43 lines (37 loc) · 772 Bytes
/
programs.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
package main
import (
"errors"
"fmt"
"os/user"
"gosuv/pushover"
log "github.com/cihub/seelog"
)
func (p *Program) Check() error {
if p.Name == "" {
return errors.New("Program name empty")
}
if p.Command == "" {
return errors.New("Program command empty")
}
return nil
}
func (p *Program) RunNotification() {
po := p.Notifications.Pushover
if po.ApiKey != "" && len(po.Users) > 0 {
for _, user := range po.Users {
err := pushover.Notify(pushover.Params{
Token: po.ApiKey,
User: user,
Title: "gosuv",
Message: fmt.Sprintf("%s change to fatal", p.Name),
})
if err != nil {
log.Warnf("pushover error: %v", err)
}
}
}
}
func IsRoot() bool {
u, err := user.Current()
return err == nil && u.Username == "root"
}