cmd

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:          "gateway-reporter",
	Short:        "Report on Geneos Gateway XML files",
	Long:         rootCmdDescription,
	SilenceUsage: true,
	CompletionOptions: cobra.CompletionOptions{
		DisableDefaultCmd: true,
	},
	Version:               cordial.VERSION,
	DisableAutoGenTag:     true,
	DisableSuggestions:    true,
	DisableFlagsInUseLine: true,
	RunE: func(cmd *cobra.Command, args []string) (err error) {

		initLogging(execname, "/tmp/reporter.log")
		zerolog.SetGlobalLevel(zerolog.DebugLevel)
		log.Debug().Msg("logging")

		setupFile := os.Getenv("_SETUP")
		validateType := os.Getenv("_VALIDATE_TYPE")

		if setupFile == "" || (validateType != "Validate" && validateType != "Command") {
			return nil
		}

		in, err := os.Open(setupFile)
		if err != nil {
			fmt.Print(`
<validation>
<issues>
<issue>
<severity>Error</severity>
<path>/gateway</path>
<message>Cannot open setup file ` + setupFile + `</message>
</issue>
</issues>
</validation>
`)
			return err
		}
		defer in.Close()

		savedXML := new(bytes.Buffer)
		input := io.TeeReader(in, savedXML)

		gateway, entities, probes, err := processInputFile(input)
		if err != nil {
			fmt.Printf(`
<validation>
<issues>
<issue>
<severity>Error</severity>
<path>/gateway</path>
<message>Error reading setup: %s</message>
</issue>
</issues>
</validation>
`, err)
			return err
		}

		dir := cf.GetString("output.directory")
		_ = os.MkdirAll(dir, 0775)

		for format, filename := range cf.GetStringMap("output.formats") {
			if filename == "" {
				continue
			}
			switch format {
			case "json":
				if err = outputJSON(cf, gateway, entities, probes); err != nil {
					break
				}
			case "csv":
				if err = outputCSVZip(cf, gateway, entities, probes); err != nil {
					break
				}
			case "csvdir":
				if _, _, err = outputCSVDir(cf, gateway, entities, probes); err != nil {
					break
				}
			case "xlsx":
				if err = outputXLSX(cf, gateway, entities, probes); err != nil {
					break
				}
			case "xml":
				if err = outputXML(cf, gateway, savedXML); err != nil {
					break
				}
			default:

			}
		}

		if err != nil {
			fmt.Printf(`
<validation>
<issues>
<issue>
<severity>Error</severity>
<path>/gateway</path>
<message>Error encoding report results: %s</message>
</issue>
</issues>
</validation>
`, err)
			return err
		}

		fmt.Printf(`
<validation>
<issues>
<issue>
<severity>None</severity>
<path>/gateway</path>
<message>Report file(s) written to %q</message>
</issue>
</issues>
</validation>
`, cf.GetString("output.directory"))
		return nil
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the listCmd.

Types

type Entity

type Entity struct {
	Name       string            `json:"name"`
	Probe      Probe             `json:"probe"`
	Attributes map[string]string `json:"attributes,omitempty"`
	Samplers   []Sampler         `json:"sampler,omitempty"`
}

type Probe

type Probe struct {
	Name     string `json:"name"`
	Hostname string `json:"hostname"`
	Port     int    `json:"port,omitempty"`
	Secure   bool   `json:"secure,omitempty"`
}

type Sampler

type Sampler struct {
	Type    string   `json:"type,omitempty"`
	Name    string   `json:"name"`
	Plugin  string   `json:"plugin,omitempty"`
	Column1 []string `json:"data1,omitempty"`
	Column2 []string `json:"data2,omitempty"`
}

Jump to

Keyboard shortcuts

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