cmd

package
v0.0.0-...-23da3e3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ControlsCmd = &cobra.Command{
	Use:   "controls [name]",
	Short: "Lists actions that can be performed at this endpoint.",
	Long: `
	Function: Lists actions that can be performed at this endpoint. 
	Format: JSON
	Tip: Pipe into jq for prettified output`,
	Run: func(cmd *cobra.Command, args []string) {
		internal.Help(cmd, args)
		fmt.Println(InspectControlInit(args[0]))
	},
}

ControlsCmd is used to restart the Splunk instance

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 RestartCmd = &cobra.Command{
	Use:   "restart",
	Short: "Restart the Splunk instance",
	Run: func(cmd *cobra.Command, args []string) {

		validate := func(input string) error {
			if len(input) < 1 {
				return errors.New("provide an input to confirm")
			}
			return nil
		}

		if confirm == false {
			confirmPrompt := promptui.Prompt{
				Label:    "Are you sure you'd like to restart Splunk? [Y/n]",
				Validate: validate,
				Default:  "Y",
			}

			result, err := confirmPrompt.Run()
			if err != nil {
				fmt.Printf("Prompt failed %v\n", err)
			}

			if result == "Y" || result == "y" {
				msg := RestartSplunkInit()
				fmt.Println(msg)
			} else {
				os.Exit(0)
			}

		} else {
			msg := RestartSplunkInit()
			fmt.Println(msg)
		}

	},
}

RestartCmd is used to restart the Splunk instance

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 == false {
			internal.Help(cmd, args)

			if splunk.ValidSPL(args[0]) {
				content, err := ioutil.ReadFile(args[0])
				if err != nil {
					log.Fatal(err)
				}

				result := searchString(string(content), mode, conn)
				fmt.Println(result)
			} else {
				log.Fatal(au.Red("Please provide a valid .spl file."))
			}

		} else if interactive == true {
			file := splunk.SearchInteractive()
			if !splunk.ValidSPL(file) {
				log.Fatal(au.Red("Please provide a valid .spl file."))
			}
			content, err := ioutil.ReadFile(file)
			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.

func InspectControlInit

func InspectControlInit(endpoint string) string

InspectControlInit is used to pass user auth into the InspectControl method from pkg

func RestartSplunkInit

func RestartSplunkInit() string

RestartSplunkInit is used to pass user auth into the RestartServer method from pkg

Types

This section is empty.

Jump to

Keyboard shortcuts

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