frontman

package module
v0.0.0-...-7c61842 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 52 Imported by: 0

README

Frontman - at a glance

Frontman is a general-purpose monitoring proxy that performs checks on foreign hosts. The main goal is to check services and performs other checks, where no logon-rights are needed for. It's expected to be used in any kind of monitoring solutions, where agent-less checks must be executed over the network. Frontman is a robust check executor that can work in the background of any monitoring solution. It enables developers to build custom solutions. Frontman can be controlled by local Json files or via Json-based HTTP APIs.

Credits

European Regional Development Fund Project co-financed by the European Regional Development Fund
under the Innovative Economy Operational Programme. Innovation grants.
We invest in your future.

What kind of checks frontman can perform

Run the example

./frontman -i src/github.com/cloudradar-monitoring/frontman/example.json -o result.out

Use ctrl-c to stop it

Command line Usage

Usage of frontman:
  -c  config file path (default depends on OS)
  -d  daemonize – run the process in background
  -i  JSON file to read the list (required if no hub_url specified in the config)
  -o  file to write the results (default ./results.out)
  -r  one run only – perform checks once and exit. Overwrites output file
  -s  username to install and start the system service
  -u  stop and uninstall the system service
  -p  print the active config
  -v  log level – overrides the level in config file (values "error","info","debug") (default "error")
  -version  show the frontman version

Configuration

On first run frontman will automatically create the config file and fill it with the default value.

Default config locations:

  • Mac OS: ~/.frontman/frontman.conf
  • Windows: ./frontman.conf
  • UNIX: /etc/frontman/frontman.conf

If some of the fields are missing in the config frontman will use the defaults. To print the active config you can use frontman -p

Also you may want to check the example config that contains comments on each field.

Logs location

  • Mac OS: ~/.frontman/frontman.log
  • Windows: ./frontman.log
  • UNIX: /etc/frontman/frontman.conf

How to build from sources

go get -d -u github.com/cloudradar-monitoring/frontman
go build -o frontman -ldflags="-X main.version=$(git --git-dir=src/github.com/cloudradar-monitoring/frontman/.git describe --always --long --dirty --tag)" github.com/cloudradar-monitoring/frontman/cmd/frontman

Build binaries and deb/rpm packages

– Install goreleaser

make goreleaser-snapshot

Build MSI package

Should be done on Windows machine

  • Download go-msi and put it in the C:\Program Files\go-msi
  • Open command prompt(cmd.exe or powershell)
  • Go to frontman directory cd path_to_directory
  • Run make goreleaser-snapshot to build binaries
  • Run build-win.bat

Versioning model

Frontman uses <major>.<minor>.<buildnumber> model for compatibility with a maximum number of package managers.

Starting from version 1.2.0 packages with even <minor> number are considered stable.

Running as a docker container

Check dockerhub for available images.

Passing credentials

Username and password need to be configured via environment variables. You can pass them using the -e flags. docker run -d -e FRONTMAN_HUB_USER=YOUR_USERNAME -e FRONTMAN_HUB_PASSWORD=YOUR_PASS cloudradario/frontman:1.0.7

Documentation

Index

Constants

View Source
const (
	IOModeFile = "file"
	IOModeHTTP = "http"
)
View Source
const (
	ProtocolICMP = "icmp"
	ProtocolTCP  = "tcp"
	ProtocolUDP  = "udp"
	ProtocolSSL  = "ssl"

	ServiceICMPPing = "ping"
)

Variables

View Source
var (
	Version            string
	SelfUpdatesFeedURL = "https://repo.cloudradar.io/windows/frontman/feed/rolling"
)

variables set on build. Example: go build -o frontman -ldflags="-X main.Version=$(git --git-dir=src/github.com/cloudradar-monitoring/frontman/.git describe --always --long --dirty --tag)" github.com/cloudradar-monitoring/frontman/cmd/frontman

View Source
var DefaultCfgPath string

Functions

func AskForConfirmation

func AskForConfirmation(s string) bool

func CheckIfRawICMPAvailable

func CheckIfRawICMPAvailable() bool

func CheckIfRootlessICMPAvailable

func CheckIfRootlessICMPAvailable() bool

func GenerateDefaultConfigFile

func GenerateDefaultConfigFile(mvc *MinValuableConfig, configFilePath string) error

GenerateDefaultConfigFile creates a default frontman.toml and writes to to disk

func HandleFlagDaemonizeMode

func HandleFlagDaemonizeMode() int

returns exit code

func HandleFlagInputOutput

func HandleFlagInputOutput(inputFile string, outputFile string, oneRunOnlyMode bool) *os.File

func HandleFlagSearchUpdates

func HandleFlagSearchUpdates() int

returns exit code

func HandleFlagUpdate

func HandleFlagUpdate(assumeYes *bool) int

returns exit code

func SaveConfigFile

func SaveConfigFile(mvc *MinValuableConfig, configFilePath string) error

SaveConfigFile saves config file as toml

func Uname

func Uname() (string, error)

Types

type Check

type Check interface {
	// contains filtered or unexported methods
}

type Config

type Config struct {
	NodeName       string  `` /* 137-byte string literal not displayed */
	Sleep          float64 `` /* 297-byte string literal not displayed */
	PidFile        string  `toml:"pid" comment:"path to pid file"`
	LogFile        string  `toml:"log,omitempty" comment:"path to log file"`
	LogSyslog      string  `toml:"log_syslog" comment:"\"local\" for local unix socket or URL e.g. \"udp://localhost:514\" for remote syslog server"`
	StatsFile      string  `toml:"stats_file" comment:"Path to the file where we write frontman statistics"`
	QueueStatsFile string  `toml:"queue_stats_file" comment:"Path to the file where we write frontman queue statistics"`

	MinValuableConfig

	HubGzip                  bool `toml:"hub_gzip" comment:"enable gzip when sending results to the HUB"`
	HubRequestTimeout        int  `` /* 200-byte string literal not displayed */
	HubMaxOfflineBufferBytes int  `toml:"hub_max_offline_buffer_bytes" commented:"true"`

	ICMPTimeout            float64 `toml:"icmp_timeout" comment:"ICMP ping timeout in seconds"`
	NetTCPTimeout          float64 `toml:"net_tcp_timeout" comment:"TCP timeout in seconds"`
	NetUDPTimeout          float64 `toml:"net_udp_timeout" comment:"UDP timeout in seconds"`
	HTTPCheckTimeout       float64 `toml:"http_check_timeout" comment:"HTTP time in seconds"`
	HTTPCheckMaxRedirects  int     `toml:"max_redirects" comment:"Limit the number of HTTP redirects to follow"`
	IgnoreSSLErrors        bool    `toml:"ignore_ssl_errors"`
	SSLCertExpiryThreshold int     `toml:"ssl_cert_expiry_threshold" comment:"Min days remain on the SSL cert to pass the check"`

	SenderBatchSize int `toml:"sender_batch_size" comment:"Do not send back more than N results per POST request"`

	SenderInterval float64 `toml:"sender_interval" comment:"Make a pause of N seconds between POST requests when processing the result queue"`

	SenderThreadConcurrency int `toml:"sender_thread_concurrency" comment:"The maximum number of concurrent http connections for sending\nresults to the hub."`

	DiscardOnHTTPResponseError bool `` /* 152-byte string literal not displayed */
	DiscardOnHTTPConnectError  bool `` /* 199-byte string literal not displayed */

	CheckResultsTTL float64 `` /* 160-byte string literal not displayed */

	SleepDurationAfterCheck float64 `toml:"sleep_duration_after_check" comment:"Time in seconds to sleep between each check being dispatched for execution"`
	SleepDurationEmptyQueue float64 `toml:"sleep_duration_empty_queue" comment:"Time in seconds to sleep when the check queue is empty"`

	HealthChecks HealthCheckConfig `` /* 534-byte string literal not displayed */

	HTTPListener HTTPListenerConfig `toml:"http_listener" comment:"Perform checks requested via HTTP POST requests"`

	FailureConfirmation      int     `` /* 268-byte string literal not displayed */
	FailureConfirmationDelay float64 `toml:"failure_confirmation_delay" comment:"Delay in seconds"`

	Node  NodeConfig      `toml:"node" comment:"Node configuration"`
	Nodes map[string]Node `` /* 527-byte string literal not displayed */

	Updates UpdatesConfig `toml:"self_update" comment:"Control how frontman installs self-updates. Windows-only"`
}

func HandleAllConfigSetup

func HandleAllConfigSetup(configFilePath string) (*Config, error)

HandleAllConfigSetup prepares config for Frontman with parameters specified in file if config file not exists default one created in form of MinValuableConfig

func NewConfig

func NewConfig() *Config

func (*Config) DumpToml

func (cfg *Config) DumpToml() string

func (*Config) TryUpdateConfigFromFile

func (cfg *Config) TryUpdateConfigFromFile(configFilePath string) error

TryUpdateConfigFromFile applies values from file in configFilePath to cfg if given file exists. it rewrites all cfg keys that present in the file

type ErrorHubGeneral

type ErrorHubGeneral struct {
	// contains filtered or unexported fields
}

func (ErrorHubGeneral) Error

func (e ErrorHubGeneral) Error() string

type ErrorHubResetContent

type ErrorHubResetContent struct{}

func (ErrorHubResetContent) Error

func (e ErrorHubResetContent) Error() string

type ErrorHubTooManyRequests

type ErrorHubTooManyRequests struct{}

func (ErrorHubTooManyRequests) Error

func (e ErrorHubTooManyRequests) Error() string

type ErrorMissingHubOrInput

type ErrorMissingHubOrInput struct{}

func (ErrorMissingHubOrInput) Error

func (e ErrorMissingHubOrInput) Error() string

type Frontman

type Frontman struct {
	Config         *Config
	ConfigLocation string

	HealthCheckPassedPreviously bool

	TerminateQueue sync.WaitGroup

	// interrupt handler, close it to shut down frontman
	InterruptChan chan struct{}

	// send true to signal completion
	DoneChan chan bool
	// contains filtered or unexported fields
}

func New

func New(cfg *Config, cfgPath, version string) (*Frontman, error)

func (*Frontman) CheckHubCredentials

func (fm *Frontman) CheckHubCredentials(ctx context.Context, fieldHubURL, fieldHubUser, fieldHubPassword string) error

CheckHubCredentials performs credentials check for a Hub config, returning errors that reference field names as in source config. Since config may be filled from file or UI, the field names can be different. Consider also localization of UI, we want to decouple credential checking logic from their actual view in UI.

Examples: * for TOML: CheckHubCredentials(ctx, "hub_url", "hub_user", "hub_password") * for WinUI: CheckHubCredentials(ctx, "URL", "User", "Password")

func (*Frontman) HandleFlagLogLevel

func (fm *Frontman) HandleFlagLogLevel(logLevel string) error

func (*Frontman) HandleFlagOneRunOnlyMode

func (fm *Frontman) HandleFlagOneRunOnlyMode(inputFile string, output *os.File) int

returns error code

func (*Frontman) HandleFlagPrintConfig

func (fm *Frontman) HandleFlagPrintConfig()

func (*Frontman) HandleFlagPrintStats

func (fm *Frontman) HandleFlagPrintStats() int

returns exit code

func (*Frontman) HandleFlagServiceInstall

func (fm *Frontman) HandleFlagServiceInstall(systemManager service.System, username string, serviceInstallPtr *bool, cfgPath string, assumeYesPtr *bool) int

returns exit code

func (*Frontman) HandleFlagServiceUninstall

func (fm *Frontman) HandleFlagServiceUninstall() int

returns exit code

func (*Frontman) HandleFlagServiceUpgrade

func (fm *Frontman) HandleFlagServiceUpgrade(cfgPath string, serviceUpgradeFlag *bool, serviceInstallUserPtr *string) int

returns exit code

func (*Frontman) HandleFlagTest

func (fm *Frontman) HandleFlagTest() int

HandleFlagTest handles -t flag for the frontman executable returns exit code

func (*Frontman) HandleServiceCommand

func (fm *Frontman) HandleServiceCommand(check, start, stop, restart bool) int

returns exit code

func (*Frontman) HealthCheck

func (fm *Frontman) HealthCheck() error

HealthCheck runs before any other check to ensure that the host itself and its network are healthly. This is useful to confirm a stable internet connection to avoid false alerts due to network outages.

func (*Frontman) HostInfoResults

func (fm *Frontman) HostInfoResults() (MeasurementsMap, error)

HostInfoResults fetches information about the host itself which can be send to the hub alongside measurements.

func (*Frontman) RemovePidFileIfNeeded

func (fm *Frontman) RemovePidFileIfNeeded()

func (*Frontman) Run

func (fm *Frontman) Run(inputFilePath string, outputFile *os.File)

Run runs all checks continuously and sends result to hub or file

func (*Frontman) RunOnce

func (fm *Frontman) RunOnce(inputFilePath string, outputFile *os.File) error

RunOnce runs all checks once and send result to hub or file

func (*Frontman) RunUnderOsServiceManager

func (fm *Frontman) RunUnderOsServiceManager() int

returns exit code

func (*Frontman) ServeWeb

func (fm *Frontman) ServeWeb() error

ServeWeb starts the webserver as configured under [http_listener] section of frontman.conf

func (*Frontman) SetLogLevel

func (fm *Frontman) SetLogLevel(lvl LogLevel)

SetLogLevel sets Log level and corresponding logrus level

func (*Frontman) WritePidFileIfNeeded

func (fm *Frontman) WritePidFileIfNeeded() error

type HTTPListenerConfig

type HTTPListenerConfig struct {
	HTTPListen       string `` /* 419-byte string literal not displayed */
	HTTPTLSKey       string `toml:"http_tls_key" comment:"Private key for https connections"`
	HTTPTLSCert      string `toml:"http_tls_cert" comment:"Certificate for https connections"`
	HTTPAuthUser     string `toml:"http_auth_user" comment:"Username for the http basic authentication. If omitted authentication is disabled"`
	HTTPAuthPassword string `toml:"http_auth_password" comment:"Password for the http basic authentication."`
	HTTPAccessLog    string `toml:"http_access_log" comment:"Log http requests. On windows slash must be escaped like \"C:\\\\access.log\""`
}

type HealthCheckConfig

type HealthCheckConfig struct {
	ReferencePingHosts   []string `` /* 239-byte string literal not displayed */
	ReferencePingTimeout float64  `toml:"reference_ping_timeout" comment:"Maximum time (seconds) to wait for the response"`
	ReferencePingCount   int      `toml:"reference_ping_count" comment:"Number of request packets to send to each host."`
}

type Input

type Input struct {
	ServiceChecks []ServiceCheck `json:"serviceChecks"`
	WebChecks     []WebCheck     `json:"webChecks"`
	SNMPChecks    []SNMPCheck    `json:"snmpChecks,omitempty"`
}

func InputFromFile

func InputFromFile(filename string) (*Input, error)

type Invoke

type Invoke struct{}

func (Invoke) Command

func (i Invoke) Command(name string, arg ...string) ([]byte, error)

func (Invoke) CommandWithContext

func (i Invoke) CommandWithContext(ctx context.Context, name string, arg ...string) ([]byte, error)

type Invoker

type Invoker interface {
	Command(string, ...string) ([]byte, error)
	CommandWithContext(context.Context, string, ...string) ([]byte, error)
}

type LogLevel

type LogLevel string
const (
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelError LogLevel = "error"
)

func (LogLevel) LogrusLevel

func (lvl LogLevel) LogrusLevel() logrus.Level

type LogrusErrorHook

type LogrusErrorHook struct {
	// contains filtered or unexported fields
}

func (*LogrusErrorHook) Fire

func (h *LogrusErrorHook) Fire(entry *logrus.Entry) error

func (*LogrusErrorHook) Levels

func (h *LogrusErrorHook) Levels() []logrus.Level

type MeasurementsMap

type MeasurementsMap map[string]interface{}

type MinValuableConfig

type MinValuableConfig struct {
	LogLevel    LogLevel `toml:"log_level" comment:"\"debug\", \"info\", \"error\" verbose level; can be overridden with -v flag"`
	IOMode      string   `toml:"io_mode" comment:"\"file\" or \"http\" – where frontman gets checks to perform and post results"`
	HubURL      string   `toml:"hub_url" commented:"true"`
	HubUser     string   `toml:"hub_user" commented:"true"`
	HubPassword string   `toml:"hub_password" commented:"true"`

	HubProxy         string `toml:"hub_proxy" commented:"true"`
	HubProxyUser     string `toml:"hub_proxy_user" commented:"true"`
	HubProxyPassword string `toml:"hub_proxy_password" commented:"true"`

	// new configs should use host_info, keep system_fields to support older configs
	SystemFields []string `toml:"system_fields" commented:"true" comment:"DEPRECATED: use host_info instead"`
	HostInfo     []string `toml:"host_info" commented:"true"`
}

func NewMinimumConfig

func NewMinimumConfig() *MinValuableConfig

type MockHub

type MockHub struct {

	// if set, responds with this status code on all requests. useful for testing 401 and such
	ResponseStatusCode int
	// contains filtered or unexported fields
}

func NewMockHub

func NewMockHub(address string) *MockHub

func (*MockHub) Serve

func (hub *MockHub) Serve()

func (*MockHub) URL

func (hub *MockHub) URL() string

type Node

type Node struct {
	URL       string `toml:"url" comment:"URL of frontman node"`
	Username  string `toml:"username" comment:"Username"`
	Password  string `toml:"password" comment:"Password"`
	VerifySSL bool   `toml:"verify_ssl"`
}

type NodeConfig

type NodeConfig struct {
	NodeTimeout     float64  `toml:"node_timeout" comment:"Set the maximum time in seconds frontman should spend trying to connect a node"`
	NodeCacheErrors float64  `` /* 181-byte string literal not displayed */
	ForwardExcept   []string `` /* 179-byte string literal not displayed */
	ForwardLog      string   `` /* 164-byte string literal not displayed */
}

type Result

type Result struct {
	CheckUUID        string                   `json:"checkUuid"`
	Timestamp        int64                    `json:"timestamp"`
	CheckType        string                   `json:"checkType"`
	Check            interface{}              `json:"check"` // *CheckData
	Measurements     map[string]interface{}   `json:"measurements"`
	Message          interface{}              `json:"message"`
	Node             string                   `json:"node,omitempty"` // filled in when result is coming from a neighbor
	NodeMeasurements []map[string]interface{} `json:"nodeMeasurements,omitempty"`
}

type Results

type Results struct {
	Results  []Result               `json:"results"`
	HostInfo map[string]interface{} `json:"hostInfo,omitempty"`
}

type SNMPCheck

type SNMPCheck struct {
	UUID  string        `json:"checkUuid"`
	Check SNMPCheckData `json:"check"`
}

type SNMPCheckData

type SNMPCheckData struct {
	Connect                string   `json:"connect"`
	Port                   uint16   `json:"port"`
	Timeout                float64  `json:"timeout"`
	Protocol               string   `json:"protocol"`
	Community              string   `json:"community,omitempty"` // v1, v2
	Preset                 string   `json:"preset"`
	Oids                   []string `json:"oids,omitempty"`
	SecurityLevel          string   `json:"security_level,omitempty"`          // v3
	Username               string   `json:"username,omitempty"`                // v3
	AuthenticationProtocol string   `json:"authentication_protocol,omitempty"` // v3
	AuthenticationPassword string   `json:"authentication_password,omitempty"` // v3
	PrivacyProtocol        string   `json:"privacy_protocol,omitempty"`        // v3
	PrivacyPassword        string   `json:"privacy_password,omitempty"`        // v3

	// values used by "oid" preset
	Oid       string `json:"oid,omitempty"`
	Name      string `json:"name,omitempty"`
	ValueType string `json:"value_type,omitempty"` /// auto (default), hex, delta, delta_per_sec
	Unit      string `json:"unit,omitempty"`
}

type ServiceCheck

type ServiceCheck struct {
	UUID  string           `json:"checkUuid"`
	Check ServiceCheckData `json:"check"`
}

type ServiceCheckData

type ServiceCheckData struct {
	Connect  string      `json:"connect,omitempty"`
	Service  string      `json:"service,omitempty"`
	Protocol string      `json:"protocol,omitempty"`
	Port     json.Number `json:"port,omitempty"`
}

type ServiceName

type ServiceName string

type UpdatesConfig

type UpdatesConfig struct {
	Enabled       bool   `toml:"enabled" comment:"Set 'false' to disable self-updates"`
	URL           string `toml:"url" comment:"URL for updates feed"`
	CheckInterval uint32 `toml:"check_interval" comment:"Frontman will check for new versions every N seconds"`
}

func (*UpdatesConfig) GetCheckInterval

func (u *UpdatesConfig) GetCheckInterval() time.Duration

func (*UpdatesConfig) Validate

func (u *UpdatesConfig) Validate() error

type WebCheck

type WebCheck struct {
	UUID  string       `json:"checkUuid"`
	Check WebCheckData `json:"check"`
}

type WebCheckData

type WebCheckData struct {
	Method                  string            `json:"method"`
	URL                     string            `json:"url"`
	PostData                string            `json:"postData,omitempty"`
	ExpectedHTTPStatus      int               `json:"expectedHttpStatus,omitempty"`
	SearchHTMLSource        bool              `json:"searchHtmlSource"`
	ExpectedPattern         string            `json:"expectedPattern,omitempty"`
	ExpectedPatternPresence string            `json:"expectedPatternPresence,omitempty"`
	DontFollowRedirects     bool              `json:"dontFollowRedirects"`
	IgnoreSSLErrors         *bool             `json:"ignoreSSLErrors,omitempty"`
	Timeout                 float64           `json:"timeout,omitempty"`
	Headers                 map[string]string `json:"headers,omitempty"`
}

Directories

Path Synopsis
cmd
pkg
iax

Jump to

Keyboard shortcuts

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