config

package
v0.12.12 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config provides types and functions to collect, validate and apply user-provided settings.

Index

Constants

View Source
const DefaultNagiosNotificationTimeout time.Duration = 30 * time.Second

DefaultNagiosNotificationTimeout is the default timeout value for Nagios 3 and 4 installations. This is our *default* timeout ceiling.

Variables

View Source
var ErrVersionRequested = errors.New("version information requested")

ErrVersionRequested indicates that the user requested application version information.

Functions

func Branding

func Branding()

Branding is responsible for emitting application name, version and origin

func MessageTrailer

func MessageTrailer(sender string) string

MessageTrailer generates a branded "footer" for use with submitted Teams messages. If specified, the sending or "generator" application is credited as the source of the message, while this application is credited as the delivery agent/mechanism.

Types

type AppInfo added in v0.7.0

type AppInfo struct {

	// Name specifies the public name shared by all tools in this project.
	Name string

	// Version specifies the public version shared by all tool in this
	// project.
	Version string

	// URL specifies the public repo URL shared by all tools in this project.
	URL string
}

AppInfo identifies common details about the tools provided by this project.

type Config

type Config struct {

	// Team is the human-readable name of the Microsoft Teams "team" that
	// contains the channel we wish to post a message to. This is used in
	// informational output produced by this application only; the remote API
	// does not receive this value.
	Team string

	// Channel is human-readable name of the channel within a specific
	// Microsoft Teams "team". This is used in informational output produced
	// by this application only; the remote API does not receive this value.
	Channel string

	// WebhookURL is the full URL used to submit messages to the Teams channel
	// This URL is in the form of https://outlook.office.com/webhook/xxx or
	// https://outlook.office365.com/webhook/xxx. This URL is REQUIRED in
	// order for this application to function and needs to be created in
	// advance by adding/configuring a Webhook Connector in a Microsoft Teams
	// channel that you wish to submit messages to using this application.
	WebhookURL string

	// ThemeColor is no longer used. Values specified for this flag are
	// ignored. If/when the Adaptive Card format adds support for message
	// theming (or border color) we can re-enable this setting.
	ThemeColor string

	// MessageTitle is the text shown on the top portion of the message "card"
	// that is displayed in Microsoft Teams for the message that we send.
	MessageTitle string

	// MessageText is an (optionally) Markdown-formatted string representing
	// the message that we will submit.
	MessageText string

	// Sender is an optional value provided to indicate what application was
	// responsible for generating the message that this one will attempt to
	// deliver.
	Sender string

	// App represents common details about the tools provided by this project.
	App AppInfo

	// TargetURLs is the collection of user-specified URLs and descriptions
	// that should be displayed as actionable links or "buttons" within the
	// generated Microsoft Teams message.
	TargetURLs targetURLsStringFlag

	// UserMention is the collection of user-specified name and ID values that
	// should be used when generating user mentions within the generated
	// Microsoft Teams message.
	UserMentions userMentionsStringFlag

	// Retries is the number of attempts that this application will make
	// to deliver messages before giving up.
	Retries int

	// RetriesDelay is the number of seconds to wait between retry attempts.
	RetriesDelay int

	// DisableWebhookURLValidation indicates whether validation of the
	// user-specified WebhookURL should be disabled. Useful for testing.
	DisableWebhookURLValidation bool

	// DisableBrandingTrailer indicates whether the branding trailer should be
	// appended to all messages generated by this application.
	DisableBrandingTrailer bool

	// IgnoreInvalidResponse indicates whether an invalid response from remote
	// endpoint should be ignored. This is expected if submitting a message to
	// a non-standard webhook URL.
	IgnoreInvalidResponse bool

	// Whether detailed output should be shown after message submission
	// success or failure.
	VerboseOutput bool

	// Whether ANY output should be shown after message submission success or
	// failure.
	SilentOutput bool

	// Whether messages with Windows, Mac and Linux newlines are updated to
	// use break statements before message submission.
	ConvertEOL bool

	// ShowVersion is a flag indicating whether the user opted to display only
	// the version string and then immediately exit the application
	ShowVersion bool
}

Config is a unified set of configuration values for this application. This struct is configured via command-line flags provided by the user.

func NewConfig

func NewConfig() (*Config, error)

NewConfig is a factory function that produces a new Config object based on user provided flag values.

func (Config) String

func (c Config) String() string

func (Config) TeamsSubmissionTimeout added in v0.4.11

func (c Config) TeamsSubmissionTimeout() time.Duration

TeamsSubmissionTimeout is the timeout value for sending messages to Microsoft Teams.

func (Config) UserAgent added in v0.7.0

func (c Config) UserAgent() string

UserAgent returns a string usable as-is as a custom user agent for plugins provided by this project.

func (Config) Validate

func (c Config) Validate(disableWebhookURLValidation bool) error

Validate verifies all struct fields have been provided acceptable values.

type TargetURL added in v0.6.0

type TargetURL struct {

	// URL to be used as the target for labelled "buttons" within a Microsoft
	// Teams message.
	URL url.URL

	// Description is the text used as the label for link "buttons" within a
	// Microsoft Teams message.
	Description string
}

TargetURL is a URL and description provided by the user for use with generating potentialAction entries for display as "buttons" in the generated Microsoft Teams message.

type UserMention added in v0.8.0

type UserMention struct {
	// ID is the unique identifier for a user that is mentioned. This value
	// can be an object ID (e.g., 5e8b0f4d-2cd4-4e17-9467-b0f6a5c0c4d0) or a
	// UserPrincipalName (e.g., NewUser@contoso.onmicrosoft.com).
	ID string

	// Name is the DisplayName of the user mentioned.
	Name string
}

UserMention is a pair of name and ID values separated by a comma used for generating a user mention.

Jump to

Keyboard shortcuts

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