cmd

package
v1.19.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CriticalCellStyle = excelize.Style{
		Fill: excelize.Fill{
			Type:    "pattern",
			Color:   []string{"DC143C"},
			Pattern: 1,
		},
		Font: &excelize.Font{
			Color: "FFFFFF",
		},
	}
	WarningCellStyle = excelize.Style{
		Fill: excelize.Fill{
			Type:    "pattern",
			Color:   []string{"FFD700"},
			Pattern: 1,
		},
		Font: &excelize.Font{
			Color: "000000",
		},
	}
	OKCellStyle = excelize.Style{
		Fill: excelize.Fill{
			Type:    "pattern",
			Color:   []string{"32cd32"},
			Pattern: 1,
		},
		Font: &excelize.Font{
			Color: "FFFFFF",
		},
	}
	HeadingCellStyle = excelize.Style{
		Font: &excelize.Font{
			Bold: true,
		},
	}
)

Hardwired cell defaults

View Source
var DV2EMAILCmd = &cobra.Command{
	Use:          "dv2email",
	Short:        "Email a Dataview following Geneos Action/Effect conventions",
	Long:         DV2EMAILCmdDescription,
	SilenceUsage: true,
	CompletionOptions: cobra.CompletionOptions{
		DisableDefaultCmd: true,
	},
	Version:               cordial.VERSION,
	DisableAutoGenTag:     true,
	DisableSuggestions:    true,
	DisableFlagsInUseLine: true,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		initConfig()
	},
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		gw, err := dialGateway(cf)
		if err != nil {
			log.Fatal().Err(err).Msg("")
		}

		em := email.NewEmailConfig(cf, toArg, ccArg, bccArg)

		data, err := fetchDataviews(cmd, gw,
			em.GetString("_firstcolumn"),
			em.GetString("__headlines"),
			em.GetString("__rows"),
			em.GetString("__columns"),
			em.GetString("__roworder"),
		)
		if err != nil {
			log.Error().Err(err).Msg("")
			return
		}

		switch cf.GetString("email.split") {
		case "entity":
			entities := map[string][]*commands.Dataview{}
			for _, d := range data.Dataviews {
				if len(entities[d.XPath.Entity.Name]) == 0 {
					entities[d.XPath.Entity.Name] = []*commands.Dataview{}
				}
				entities[d.XPath.Entity.Name] = append(entities[d.XPath.Entity.Name], d)
			}
			for _, e := range entities {
				many := DV2EMailData{
					Dataviews: e,
					Env:       data.Env,
				}
				if err = sendEmail(cf, em, many, inlineCSS); err != nil {
					log.Fatal().Err(err).Msg("")
				}
			}
		case "dataview":
			for _, d := range data.Dataviews {
				one := DV2EMailData{
					Dataviews: []*commands.Dataview{d},
					Env:       data.Env,
				}
				if err = sendEmail(cf, em, one, inlineCSS); err != nil {
					log.Fatal().Err(err).Msg("")
				}
			}
		default:
			if err = sendEmail(cf, em, data, inlineCSS); err != nil {
				log.Fatal().Err(err).Msg("sending failed")
			}
		}

		return
	},
}

DV2EMAILCmd represents the base command when called without any subcommands

View Source
var DV2EMAILCmdDescription string

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 RootCmd.

func Less added in v1.11.2

func Less(a, b string) bool

Less does a 'natural' comparison on the two strings.

It treats digits as decimal numbers, so that Less("10", "2") return false.

This function does no memory allocation.

Types

type DV2EMailData added in v1.11.0

type DV2EMailData struct {
	// Dataviews is a slice of each Dataview's data, including Columns
	// and Rows which are ordered names for the columns and rows
	// respectively, suitable for range loops. See
	// https://pkg.go.dev/github.com/itrs-group/cordial/pkg/commands#Dataview
	// for details
	Dataviews []*commands.Dataview

	// Env is a map of environment variable, names to values
	Env map[string]string
}

type NatsortStringSlice added in v1.11.2

type NatsortStringSlice []string

NatsortStringSlice attaches the methods of Interface to []string, sorting in increasing order using natural order.

func (NatsortStringSlice) Len added in v1.11.2

func (p NatsortStringSlice) Len() int

func (NatsortStringSlice) Less added in v1.11.2

func (p NatsortStringSlice) Less(i, j int) bool

func (NatsortStringSlice) Swap added in v1.11.2

func (p NatsortStringSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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