Startup options, fixed new group bug with unnamed groups
This commit is contained in:
parent
9cc26fe41c
commit
aa1d4d10fa
11
alrmrc
Normal file
11
alrmrc
Normal file
@ -0,0 +1,11 @@
|
||||
set interval 30
|
||||
|
||||
monitor host gateway address 10.11.135.100
|
||||
|
||||
monitor group webservers
|
||||
host www1.example.com address 10.11.135.101
|
||||
check ping
|
||||
host www2.example.com address 10.11.135.102
|
||||
check ping
|
||||
|
||||
monitor host database
|
45
main.go
45
main.go
@ -3,26 +3,51 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"flag"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr, "filename required\n")
|
||||
os.Exit(1)
|
||||
configPath := flag.String("config", "", "path to configuration file")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *configPath == "" {
|
||||
if _, err := os.Stat("./alrmrc"); err == nil {
|
||||
*configPath = "./alrmrc"
|
||||
}
|
||||
if _, err := os.Stat("/etc/alrmrc"); err == nil {
|
||||
*configPath = "/etc/alrmrc"
|
||||
}
|
||||
if *configPath == "" {
|
||||
fmt.Fprintf(os.Stderr, "Cannot find configuration\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
config, err := ReadConfig(os.Args[1])
|
||||
config, err := ReadConfig(*configPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
o, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "JSON error: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
command := strings.ToLower(flag.Arg(0))
|
||||
switch command {
|
||||
case "json":
|
||||
o, err := json.MarshalIndent(config, "", " ")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "JSON error: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintf(os.Stdout, "%s", string(o))
|
||||
|
||||
fmt.Println(string(o))
|
||||
case "", "config":
|
||||
fmt.Fprintf(os.Stdout, "Config is OK.\n")
|
||||
os.Exit(0)
|
||||
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", command)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,8 @@ func (p *Parser) Parse(fn string) (*AlrmConfig, error) {
|
||||
case TK_MONITOR:
|
||||
switch strings.ToLower(tk) {
|
||||
case "host":
|
||||
host = config.NewGroup().NewHost()
|
||||
group = config.NewGroup()
|
||||
host = group.NewHost()
|
||||
p.setState(TK_HOST)
|
||||
|
||||
case "group":
|
||||
|
@ -1,11 +0,0 @@
|
||||
# set alert "Don't think about it"
|
||||
|
||||
monitor group
|
||||
host www1.example.com address 10.11.135.101
|
||||
# check allows for a check using a host/address
|
||||
check ping
|
||||
host www2.example.com address 10.11.135.102
|
||||
check ping
|
||||
|
||||
# Address is optional, derived from host
|
||||
monitor host monkey.com
|
13
small.config
13
small.config
@ -1,13 +0,0 @@
|
||||
set interval 30
|
||||
|
||||
# Address is optional, derived from host
|
||||
monitor host monkey.com
|
||||
|
||||
monitor host stupid.com
|
||||
|
||||
monitor group webservers
|
||||
# Monitor host one
|
||||
host one.com address 10.12.121.1
|
||||
check ping
|
||||
# Monitor host two
|
||||
host two.com
|
Loading…
Reference in New Issue
Block a user