cmd

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Copyright © 2023 NAME HERE <EMAIL ADDRESS>

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,
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		gw, err := dialGateway(cf)
		if err != nil {
			log.Fatal().Err(err).Msg("")
		}

		em := setupEmail(toArg, ccArg, bccArg)

		data, err := fetchDataviews(gw,
			em.GetString("_firstcolumn"),
			em.GetString("__headlines"),
			em.GetString("__rows"),
			em.GetString("__columns"),
		)

		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(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(em, one, inlineCSS); err != nil {
					log.Fatal().Err(err).Msg("")
				}
			}
		default:
			if err = sendEmail(em, data, inlineCSS); err != nil {
				log.Fatal().Err(err).Msg("")
			}
		}

		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.

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
}

Jump to

Keyboard shortcuts

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