-
Notifications
You must be signed in to change notification settings - Fork 14
/
fetch.go
51 lines (41 loc) · 1.55 KB
/
fetch.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
package cmd
import (
"github.com/spf13/cobra"
"github.com/ostrost/ostent/ostent"
"github.com/ostrost/ostent/params"
)
// fetchCmd represents the fetch command
var fetchCmd = &cobra.Command{
SilenceUsage: true,
Use: "fetch",
Short: "Print collected data.",
Long: `Ostent fetch retrieves data from one or many ostent servers to print. Server
addresses and request details can be specified with --keys flag. The value is
parsed as a partial URL: most details can be omitted for defaults. The fragment
is treated as key(s) to reduce data with. Join multiple keys with "#".`,
Example: `ostent fetch --keys \#uptime
ostent fetch --keys '?times=-1#uptime'
ostent fetch --keys 'http://10.0.0.4:8050?cpun=1#cpu'
ostent fetch --keys 'http://10.0.0.5:8050#hostname,http://10.0.0.6:8050#hostname'`,
RunE: fetchRun,
}
func init() {
RootCmd.AddCommand(fetchCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// fetchCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// fetchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
fetchCmd.PersistentFlags().Var(fetchKeys, "keys", "Ostent server(s)")
}
var fetchKeys = params.NewFetchKeys(8050)
func fetchRun(*cobra.Command, []string) error {
if len(fetchKeys.Values) == 0 {
if err := fetchKeys.Set(""); err != nil {
return err
}
}
return ostent.Fetch(fetchKeys)
}