Documentation ¶
Overview ¶
ssh_exporter.util provides helper functions and types for ssh_exporter.
Index ¶
- func FatalCheck(e error)
- func LogMsg(s string)
- func ParseFlags(c, p *string) (*string, *string)
- func ParseQuery(w http.ResponseWriter, r *http.Request) (*regexp.Regexp, error)
- func PrometheusFormatResponse(c Config) (string, error)
- func SoftCheck(e error) bool
- type Config
- type CredentialConfig
- type ScriptConfig
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 ParseFlags ¶
ParseFlags parses the given commandline arguments and returns config and port as a tuple.
func ParseQuery ¶
ParseQuery parses HTTP query parameters for the 'pattern' query. Returns the compiled regex pattern or an error.
func PrometheusFormatResponse ¶
PrometheusFormatResponse converts the config struct to a Prometheus-digestable format.
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 ¶
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 ¶
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"