cmd

package
v0.0.0-...-aac3333 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenDocs = &cobra.Command{
	Use:   "docs",
	Short: "Automatically generate documentation for the CLI.",
	Run: func(cmd *cobra.Command, args []string) {
		err := doc.GenMarkdownTree(rootCmd, "./docs")
		if err != nil {
			log.Fatal(err)
		}

		header := &doc.GenManHeader{
			Title:   "Splunk GO",
			Section: "1",
		}
		err = doc.GenManTree(rootCmd, header, "./docs/manual")
		if err != nil {
			log.Fatal(err)
		}
	},
}

GenDocs is used to generate documentation for the CLI

View Source
var LoginCmd = &cobra.Command{
	Use:   "login",
	Short: "Authenticate to Splunk and return a session token.",
	Run: func(cmd *cobra.Command, args []string) {

		conn := splunk.Connection{
			Username: viper.GetString("SPLUNK_USERNAME"),
			Password: viper.GetString("SPLUNK_PASSWORD"),
			BaseURL:  viper.GetString("SPLUNK_URL"),
		}

		key, err := conn.Login()
		if err != nil {
			log.Fatal(au.Red("Couldn't login to Splunk. Ensure your configuration is correct."))
		}

		fmt.Println("Logged in Successfully. \nSession key:", au.BrightBlue(key.Value))
	},
}

LoginCmd is used to authenticate to Splunk

View Source
var SearchCmd = &cobra.Command{
	Use:   "search [string or filepath]",
	Short: "Search Splunk for events.",
	Long: `The search command is used to perform search queries via the Splunk REST API. 
Searching splunk using the CLI requires one argument of a SPL file containing your search.

e.g. splunk-go search ~/.splunk-go/searches/my-search.spl

`,
	Run: func(cmd *cobra.Command, args []string) {

		conn := splunk.Connection{
			Username: viper.GetString("SPLUNK_USERNAME"),
			Password: viper.GetString("SPLUNK_PASSWORD"),
			BaseURL:  viper.GetString("SPLUNK_URL"),
		}

		if interactive == true {
			file := splunk.SearchInteractive()
			content, err := ioutil.ReadFile(file)
			if err != nil {
				log.Fatal(err)
			}

			result := searchString(string(content), mode, conn)
			fmt.Println(result)
		} else {
			internal.Help(cmd, args)
			content, err := ioutil.ReadFile(args[0])
			if err != nil {
				log.Fatal(err)
			}
			result := searchString(string(content), mode, conn)
			fmt.Println(result)
		}
	},
}

SearchCmd is used to search splunk events

View Source
var SystemCmd = &cobra.Command{
	Use:   "system",
	Short: "Perform operations on the Splunk server.",
	Run: func(cmd *cobra.Command, args []string) {
		internal.Help(cmd, args)
	},
}

SystemCmd represents the system command

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL