Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
split ohgi to sensu package
Browse files Browse the repository at this point in the history
  • Loading branch information
hico-horiuchi committed Jun 25, 2015
1 parent d684108 commit 3a1cf6e
Show file tree
Hide file tree
Showing 27 changed files with 942 additions and 500 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ run:
gom run main.go ${ARGS}

fmt:
gom exec goimports -w *.go ohgi/*.go
gom exec goimports -w *.go sensu/*.go ohgi/*.go

build: fmt
gom build $(GO_BUILDOPT) -o bin/ohgi main.go
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
"host": "192.168.11.20",
"port": 4567
}
],
"timeout": 3 // Optional
]
}

Specify a datacenter by `-x`(`--datacenter`) option as below.
If datacenter is not specified, use first of `datacenters`.
If a datacenter is not specified, use first of `datacenters`.

$ ohgi -x server-1 events

Expand All @@ -50,16 +49,16 @@ If datacenter is not specified, use first of `datacenters`.
ohgi [command]

Available Commands:
checks List locally defined checks and request executions
request Issues a check execution request
clients List and delete client(s) information
jit Dynamically created clients, added to the client registry
history Returns the history for a client
checks List locally defined checks and request executions
request Issues a check execution request
events List and resolve current events
resolve Resolves an event
silence Create, list, and delete silence stashes
health Check the status of the API's transport & Redis connections, and query the transport's status
info List the Sensu version and the transport and Redis connection information
silence Create, list, and delete silences
version Print and check version of ohgi
help Help about any command

Expand Down
155 changes: 78 additions & 77 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"./ohgi"
"./sensu"
isatty "github.com/mattn/go-isatty"
"github.com/spf13/cobra"
)
Expand All @@ -18,10 +19,10 @@ func main() {
limit int
offset int
delete bool
consumers int
messages int
expiration string
reason string
consumers int
messages int
)

if !isatty.IsTerminal(os.Stdout.Fd()) {
Expand All @@ -33,59 +34,27 @@ func main() {
Short: "Sensu command-line tool by golang",
Long: "Sensu command-line tool by golang\nhttps://github.com/hico-horiuchi/ohgi",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
ohgi.LoadConfig(datacenter)
sensu.DefaultAPI = ohgi.LoadConfig(datacenter)
},
}
rootCmd.PersistentFlags().StringVarP(&datacenter, "datacenter", "x", "", "Specify a datacenter")

rootCmd.AddCommand(&cobra.Command{
Use: "checks [check]",
Short: "List locally defined checks and request executions",
Long: "checks Returns the list of checks\nchecks [check] Returns a check",
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
fmt.Print(ohgi.GetChecks())
case 1:
if strings.Contains(args[0], "*") {
fmt.Print(ohgi.GetChecksWildcard(args[0]))
} else {
fmt.Print(ohgi.GetChecksCheck(args[0]))
}
}
},
})

rootCmd.AddCommand(&cobra.Command{
Use: "request [check] [subscriber]",
Short: "Issues a check execution request",
Long: "request [check] Issues a check execution request\nrequest [check] [subscriber] Issues a check execution request",
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 1:
fmt.Print(ohgi.PostRequest(args[0], ""))
case 2:
fmt.Print(ohgi.PostRequest(args[0], args[1]))
}
},
})

clientsCmd := &cobra.Command{
Use: "clients [client]",
Short: "List and delete client(s) information",
Long: "clients Returns the list of clients\nclients [client] Returns a client",
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
fmt.Print(ohgi.GetClients(limit, offset))
fmt.Print(ohgi.GetClients(sensu.DefaultAPI, limit, offset))
case 1:
if delete {
fmt.Print(ohgi.DeleteClientsClient(args[0]))
fmt.Print(ohgi.DeleteClientsClient(sensu.DefaultAPI, args[0]))
} else {
if strings.Contains(args[0], "*") {
fmt.Print(ohgi.GetClientsWildcard(args[0]))
fmt.Print(ohgi.GetClientsWildcard(sensu.DefaultAPI, args[0]))
} else {
fmt.Print(ohgi.GetClientsClient(args[0]))
fmt.Print(ohgi.GetClientsClient(sensu.DefaultAPI, args[0]))
}
}
}
Expand All @@ -103,9 +72,9 @@ func main() {
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 2:
fmt.Print(ohgi.PostClients(args[0], args[1], ""))
fmt.Print(ohgi.PostClients(sensu.DefaultAPI, args[0], args[1], []string{}))
case 3:
fmt.Print(ohgi.PostClients(args[0], args[1], args[2]))
fmt.Print(ohgi.PostClients(sensu.DefaultAPI, args[0], args[1], strings.Split(args[2], ",")))
}
},
})
Expand All @@ -117,7 +86,39 @@ func main() {
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 1:
fmt.Print(ohgi.GetHistory(args[0]))
fmt.Print(ohgi.GetClientsHistory(sensu.DefaultAPI, args[0]))
}
},
})

rootCmd.AddCommand(&cobra.Command{
Use: "checks [check]",
Short: "List locally defined checks and request executions",
Long: "checks Returns the list of checks\nchecks [check] Returns a check",
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
fmt.Print(ohgi.GetChecks(sensu.DefaultAPI))
case 1:
if strings.Contains(args[0], "*") {
fmt.Print(ohgi.GetChecksWildcard(sensu.DefaultAPI, args[0]))
} else {
fmt.Print(ohgi.GetChecksCheck(sensu.DefaultAPI, args[0]))
}
}
},
})

rootCmd.AddCommand(&cobra.Command{
Use: "request [check] [subscribers]",
Short: "Issues a check execution request",
Long: "request [check] Issues a check execution request\nrequest [check] [subscribers] Issues a check execution request",
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 1:
fmt.Print(ohgi.PostRequest(sensu.DefaultAPI, args[0], []string{}))
case 2:
fmt.Print(ohgi.PostRequest(sensu.DefaultAPI, args[0], strings.Split(args[1], ",")))
}
},
})
Expand All @@ -129,14 +130,14 @@ func main() {
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
fmt.Print(ohgi.GetEvents())
fmt.Print(ohgi.GetEvents(sensu.DefaultAPI))
case 1:
fmt.Print(ohgi.GetEventsClient(args[0]))
fmt.Print(ohgi.GetEventsClient(sensu.DefaultAPI, args[0]))
case 2:
if delete {
fmt.Print(ohgi.DeleteEventsClientCheck(args[0], args[1]))
fmt.Print(ohgi.DeleteEventsClientCheck(sensu.DefaultAPI, args[0], args[1]))
} else {
fmt.Print(ohgi.GetEventsClientCheck(args[0], args[1]))
fmt.Print(ohgi.GetEventsClientCheck(sensu.DefaultAPI, args[0], args[1]))
}
}
},
Expand All @@ -151,60 +152,60 @@ func main() {
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 2:
fmt.Print(ohgi.PostResolve(args[0], args[1]))
fmt.Print(ohgi.PostResolve(sensu.DefaultAPI, args[0], args[1]))
}
},
})

healthCmd := &cobra.Command{
Use: "health",
Short: "Check the status of the API's transport & Redis connections, and query the transport's status",
Long: "health Returns health information on transport & Redis connections",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(ohgi.GetHealth(consumers, messages))
},
}
healthCmd.Flags().IntVarP(&consumers, "consumers", "c", 1, "The minimum number of transport consumers to be considered healthy")
healthCmd.Flags().IntVarP(&messages, "messages", "m", 1, "The maximum ammount of transport queued messages to be considered healthy")
rootCmd.AddCommand(healthCmd)

rootCmd.AddCommand(&cobra.Command{
Use: "info",
Short: "List the Sensu version and the transport and Redis connection information",
Long: "info Returns information on the API",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(ohgi.GetInfo())
},
})

silenceCmd := &cobra.Command{
Use: "silence [client] [check]",
Short: "Create, list, and delete silences",
Long: "silence Returns a list of silences\nsilence [client] Create a silence\nsilence [client] [check] Create a silence",
Short: "Create, list, and delete silence stashes",
Long: "silence Returns a list of silence stashes\nsilence [client] Create a silence stash\nsilence [client] [check] Create a silence stash",
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
fmt.Print(ohgi.GetSilence())
fmt.Print(ohgi.GetSilence(sensu.DefaultAPI))
case 1:
if delete {
fmt.Print(ohgi.DeleteSilence(args[0], ""))
fmt.Print(ohgi.DeleteSilence(sensu.DefaultAPI, args[0], ""))
} else {
fmt.Print(ohgi.PostSilence(args[0], "", expiration, reason))
fmt.Print(ohgi.PostSilence(sensu.DefaultAPI, args[0], "", expiration, reason))
}
case 2:
if delete {
fmt.Print(ohgi.DeleteSilence(args[0], args[1]))
fmt.Print(ohgi.DeleteSilence(sensu.DefaultAPI, args[0], args[1]))
} else {
fmt.Print(ohgi.PostSilence(args[0], args[1], expiration, reason))
fmt.Print(ohgi.PostSilence(sensu.DefaultAPI, args[0], args[1], expiration, reason))
}
}
},
}
silenceCmd.Flags().StringVarP(&expiration, "expiration", "e", "", "15m, 1h, 1d")
silenceCmd.Flags().StringVarP(&expiration, "expiration", "e", "", "e.g. 15m, 1h, 1d")
silenceCmd.Flags().StringVarP(&reason, "reason", "r", "", "Enter a reason")
silenceCmd.Flags().BoolVarP(&delete, "delete", "d", false, "Delete a silence")
silenceCmd.Flags().BoolVarP(&delete, "delete", "d", false, "Remove silence stash")
rootCmd.AddCommand(silenceCmd)

healthCmd := &cobra.Command{
Use: "health",
Short: "Check the status of the API's transport & Redis connections, and query the transport's status",
Long: "health Returns health information on transport & Redis connections",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(ohgi.GetHealth(sensu.DefaultAPI, consumers, messages))
},
}
healthCmd.Flags().IntVarP(&consumers, "consumers", "c", 1, "The minimum number of transport consumers to be considered healthy")
healthCmd.Flags().IntVarP(&messages, "messages", "m", 0, "The maximum ammount of transport queued messages to be considered healthy")
rootCmd.AddCommand(healthCmd)

rootCmd.AddCommand(&cobra.Command{
Use: "info",
Short: "List the Sensu version and the transport and Redis connection information",
Long: "info Returns information on the API",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(ohgi.GetInfo(sensu.DefaultAPI))
},
})

rootCmd.AddCommand(&cobra.Command{
Use: "version",
Short: "Print and check the version of ohgi",
Expand Down
49 changes: 0 additions & 49 deletions ohgi/api.go

This file was deleted.

Loading

0 comments on commit 3a1cf6e

Please sign in to comment.