util

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

ssh_exporter.util provides helper functions and types for ssh_exporter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FatalCheck

func FatalCheck(e error)

FatalCheck exits the program if e is non-nil. Used for startup errors that should kill the server.

func LogMsg

func LogMsg(s string)

LogMsg logs a string to stdout with timestamp.

func ParseFlags

func ParseFlags(c, p *string) (*string, *string)

ParseFlags parses the given commandline arguments and returns config and port as a tuple.

func ParseQuery

func ParseQuery(w http.ResponseWriter, r *http.Request) (*regexp.Regexp, error)

ParseQuery parses HTTP query parameters for the 'pattern' query. Returns the compiled regex pattern or an error.

func PrometheusFormatResponse

func PrometheusFormatResponse(c Config) (string, error)

PrometheusFormatResponse converts the config struct to a Prometheus-digestable format.

func SoftCheck

func SoftCheck(e error) bool

SoftCheck logs non-nil errors to stderr. Used for runtime errors that should not kill the server.

Types

type Config

type Config struct {
	Version string         `yaml:"version"`
	Scripts []ScriptConfig `yaml:"scripts"`
}

Configuration file datastructure overview:

version: v0 scripts:

  • name: 'name' script: 'script' timeout: 1s credentials:
  • host: 'host' user: 'user' keyfile: '/path/to/keyfile'

Also includes internal data structures used to achieve a more sane data-flow.

func BatchExecute

func BatchExecute(c *Config, p *regexp.Regexp) (Config, error)

BatchExecute runs the scripts described in the provided configuration file.

Conceptual overview (because this is a little complicated):

A channel 't' is created as well as a sync.WaitGroup. These are used to communicate between goroutines and the main thread.

The main thread spawns each goroutine and then waits with done.Wait(). In each goroutine the size of our sync.WaitGroup is incremented by 1. Once that thread is done executing it's assigned script, it calls done(), unblocking the WaitGroup.

Once that stops blocking BatchExecute returns.

func ParseConfig

func ParseConfig(c string) (Config, error)

type CredentialConfig

type CredentialConfig struct {
	Host               string `yaml:"host"`
	Port               string `yaml:"port"`
	User               string `yaml:"user"`
	KeyFile            string `yaml:"keyfile"`
	ScriptResult       string // For internal use only
	ScriptReturnCode   int    // For internal use only
	ScriptError        string // For internal use only
	ResultPatternMatch int8   // For internal use only
}

CredentialConfig stores information about each host a script is to be run on; at runtime the structure also stores the result of a given on that host.

User assigned values include host, port, user, and keyfile.

Runtime determined ScriptResult, ScriptReturnCode, ScriptError, and ResultPatternMatch

type ScriptConfig

type ScriptConfig struct {
	Name          string             `yaml:"name"`
	Script        string             `yaml:"script"`
	Timeout       string             `yaml:"timeout"`
	Pattern       string             `yaml:"pattern"`
	Credentials   []CredentialConfig `yaml:"credentials"`
	ParsedTimeout time.Duration      // For internal use only
	Ignored       bool               // For internal use only
}

ScriptConfig stores information about a given script including the name (which can be used to filter results on the /probe endpoint), Script, Timeout, Pattern (which determines if the script failed or not), and Credentials (described below).

In addition to the above, ParsedTimeout is the go Duration of the user provided Timeout value and Ignored stores weather or not the script is run for a given request; it is ignored if Name does not match the query parameter "pattern"

Jump to

Keyboard shortcuts

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