parent
d5d73f3e6f
commit
4053a83629
@ -84,12 +84,36 @@ func usage(err string) {
|
|||||||
logger.Fatalln(err)
|
logger.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClientShow(streamfilter, format string) {
|
func ClientShow(format, stream, filter string) {
|
||||||
response := SendAndRetrieve(Request{Show, streamfilter})
|
response := SendAndRetrieve(Request{Show, ""})
|
||||||
if response.Err != nil {
|
if response.Err != nil {
|
||||||
logger.Fatalln("Received error from daemon:", response.Err)
|
logger.Fatalln("Received error from daemon:", response.Err)
|
||||||
|
}
|
||||||
|
// Limit to stream, filter if exists
|
||||||
|
if stream != "" {
|
||||||
|
exists := false
|
||||||
|
for streamName := range response.ClientStatus {
|
||||||
|
if stream == streamName {
|
||||||
|
if filter != "" {
|
||||||
|
for filterName := range response.ClientStatus[streamName] {
|
||||||
|
if filter == filterName {
|
||||||
|
exists = true
|
||||||
|
} else {
|
||||||
|
delete(response.ClientStatus[streamName], filterName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
exists = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete(response.ClientStatus, streamName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
logger.Println(logger.WARN, "No matching stream.filter items found. This does not mean it doesn't exist, maybe it just didn't receive any match.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var text []byte
|
var text []byte
|
||||||
var err error
|
var err error
|
||||||
if format == "json" {
|
if format == "json" {
|
||||||
|
21
app/main.go
21
app/main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"framagit.org/ppom/reaction/logger"
|
"framagit.org/ppom/reaction/logger"
|
||||||
)
|
)
|
||||||
@ -48,6 +49,10 @@ func addLevelFlag(f *flag.FlagSet) *string {
|
|||||||
return addStringFlag([]string{"l", "loglevel"}, "INFO", f)
|
return addStringFlag([]string{"l", "loglevel"}, "INFO", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addStreamFilterFlag(f *flag.FlagSet) *string {
|
||||||
|
return addStringFlag([]string{"sf", "streamfilter"}, "", f)
|
||||||
|
}
|
||||||
|
|
||||||
func subCommandParse(f *flag.FlagSet, maxRemainingArgs int) {
|
func subCommandParse(f *flag.FlagSet, maxRemainingArgs int) {
|
||||||
help := addBoolFlag([]string{"h", "help"}, f)
|
help := addBoolFlag([]string{"h", "help"}, f)
|
||||||
f.Parse(os.Args[2:])
|
f.Parse(os.Args[2:])
|
||||||
@ -91,6 +96,7 @@ func basicUsage() {
|
|||||||
# options:
|
# options:
|
||||||
-s/--socket SOCKET # path to the client-daemon communication socket
|
-s/--socket SOCKET # path to the client-daemon communication socket
|
||||||
-f/--format yaml|json # (default: yaml)
|
-f/--format yaml|json # (default: yaml)
|
||||||
|
-sf/--streamfilter STREAM[.FILTER] # only show items related to this STREAM (or STREAM.FILTER)
|
||||||
|
|
||||||
` + bold + `reaction flush` + reset + ` TARGET
|
` + bold + `reaction flush` + reset + ` TARGET
|
||||||
# run currently active matches and pending actions for the specified TARGET
|
# run currently active matches and pending actions for the specified TARGET
|
||||||
@ -117,7 +123,7 @@ func Main() {
|
|||||||
basicUsage()
|
basicUsage()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
f := flag.NewFlagSet(os.Args[1], flag.ContinueOnError)
|
f := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
case "help", "-h", "--help":
|
case "help", "-h", "--help":
|
||||||
basicUsage()
|
basicUsage()
|
||||||
@ -155,12 +161,17 @@ func Main() {
|
|||||||
f.PrintDefaults()
|
f.PrintDefaults()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
stream, filter := "", ""
|
||||||
if *limit != "" {
|
if *limit != "" {
|
||||||
logger.Fatalln("for now, -l/--limit is not supported")
|
splitSF := strings.Split(*limit, ".")
|
||||||
os.Exit(1)
|
stream = splitSF[0]
|
||||||
|
if len(splitSF) == 2 {
|
||||||
|
filter = splitSF[1]
|
||||||
|
} else if len(splitSF) > 2 {
|
||||||
|
logger.Fatalln("-l/--limit: only one . separator is supported")
|
||||||
}
|
}
|
||||||
// f.Arg(0) is "" if there is no remaining argument
|
}
|
||||||
ClientShow(*limit, *queryFormat)
|
ClientShow(*queryFormat, stream, filter)
|
||||||
|
|
||||||
case "flush":
|
case "flush":
|
||||||
SocketPath = addSocketFlag(f)
|
SocketPath = addSocketFlag(f)
|
||||||
|
@ -26,5 +26,26 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
tailDown2: {
|
||||||
|
cmd: ['sh', '-c', 'echo coucou; sleep 2m'],
|
||||||
|
// cmd: ['sh', '-c', "echo 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 6 7 8 9 | tr ' ' '\n' | while read i; do sleep 3; echo found $(($i % 60)); done"],
|
||||||
|
filters: {
|
||||||
|
findIP: {
|
||||||
|
regex: ['^found <num>$'],
|
||||||
|
retry: 3,
|
||||||
|
retryperiod: '30s',
|
||||||
|
actions: {
|
||||||
|
damn: {
|
||||||
|
cmd: ['echo', '<num>'],
|
||||||
|
},
|
||||||
|
undamn: {
|
||||||
|
cmd: ['echo', 'undamn', '<num>'],
|
||||||
|
after: '30s',
|
||||||
|
onexit: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user