search

package
v1.0.0-beta7 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CliCommand = cli.Command{
	Name:  "search",
	Usage: "Search OpenNMS database",
	Flags: []cli.Flag{
		cli.GenericFlag{
			Name:     "entity, e",
			Value:    Entities,
			Usage:    "The severity of the event: " + Entities.EnumAsString(),
			Required: true,
		},
		cli.StringFlag{
			Name:  "filter, f",
			Usage: "The filter to apply in FIQL format",
		},
		cli.IntFlag{
			Name:  "limit, l",
			Usage: "The amount of entities per query",
			Value: 10,
		},
		cli.IntFlag{
			Name:  "offset, o",
			Usage: "The starting entity index (for pagination)",
			Value: 0,
		},
	},
	Action: func(c *cli.Context) error {
		entity := c.String("entity")
		if entity == "" {
			return fmt.Errorf("Entity required; options: %s", Entities.EnumAsString())
		}
		url := fmt.Sprintf("/api/v2/%s?limit=%d&offset=%d", entity, c.Int("limit"), c.Int("offset"))
		filter := c.String("filter")
		if filter != "" {
			url += "&_s=" + filter
		}
		jsonBytes, err := rest.Instance.Get(url)
		if err != nil {
			return err
		}
		if len(jsonBytes) == 0 {
			fmt.Printf("There is no data for %s\n", entity)
			return nil
		}
		var data interface{}
		switch entity {
		case "nodes":
			data = &model.OnmsNodeList{}
		case "events":
			data = &model.OnmsEventList{}
		case "alarms":
			data = &model.OnmsAlarmList{}
		case "outages":
			data = &model.OnmsOutageList{}
		}
		err = json.Unmarshal(jsonBytes, data)
		if err != nil {
			return err
		}
		yamlBytes, _ := yaml.Marshal(data)
		fmt.Println(string(yamlBytes))
		return nil
	},
}

CliCommand the CLI command to provide search capabilities information

View Source
var Entities = &model.EnumValue{
	Enum: []string{"nodes", "events", "alarms", "outages"},
}

Entities list of valid searchable entities

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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