Documentation ¶
Index ¶
- func Bool(v bool) *bool
- func BoolValue(v *bool) bool
- func Int(v int) *int
- func IntValue(v *int) int
- func String(v string) *string
- func StringValue(v *string) string
- type BoltDB
- type Config
- type DB
- type Email
- type EmailNotifier
- type FSLogger
- type HTTP
- type Logger
- type Notifier
- type Resync
- type Stat
- type Sync
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolValue ¶
BoolValue returns the value of the string pointer passed in or false if the pointer is nil.
func IntValue ¶
IntValue returns the value of the string pointer passed in or 0 if the pointer is nil.
func StringValue ¶
StringValue returns the value of the string pointer passed in or "" if the pointer is nil.
Types ¶
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
BoltDB is the default and only database for storing stats. In the future other databases could be added.
func NewBoltDB ¶
NewBoltDB creates the underlying boltdb database. If retention is less than 1 than the database isn't created and all calls are no-ops.
type Config ¶
type Config struct { // RsyncPath is the path to the rsync binary. Defaults to rsync or rsync.exe on Windows. RsyncPath *string `yaml:"rsync_path"` // LogPath is the directory on disk where resync logs will be stored. Defaults to /var/log/resync. LogPath *string `yaml:"log_path"` // LogLevel sets the level of logging. Valid levels are: panic, fatal, trace, debug, warn, info, and error. Defaults to error LogLevel *string `yaml:"log_level"` // LibPath is the directory on disk where resync lib files are stored. Defaults to /var/lib/resync. LibPath *string `yaml:"lib_path"` // The time format used when displaying sync stats. See formatting options in the go time.Time package. // Defaults to Mon Jan 02 03:04:05 PM MST TimeFormat *string `yaml:"time_format"` // Retention is the number of logs and stats that are stored for each sync. If set to less than 1 no // logs or are stats are saved. Defaults to 7. Retention *int `yaml:"retention"` // Enable the cron seconds field. This makes the first field in the cron expression handle seconds // changes the expression to 6 fields. Defaults to false. SecondsField *bool `yaml:"seconds_field"` // TimeLimit is the maximum amount of time that a sync job will run before being killed. TimeLimit // must be a string that can be passed to the time.Duration.ParseDuration() function. Default is no // time limit. TimeLimit *string `yaml:"time_limit"` HTTP *HTTP `yaml:"http"` Email *Email `yaml:"email"` Syncs map[string]*Sync `yaml:"syncs"` // contains filtered or unexported fields }
Config is an object representation of the YAML configuration file. Config is read from in multiple goroutines and should not be written after the NewConfig is called or data races will happen. Config is not thread safe and should be considered read only after being passed to any other object. Writing any of it's fields will cause a data race.
func OpenConfig ¶
OpenConfig returns a new Config option by reading the YAML file at path. If the file doesn't exist, can't be read, is invalid YAML, or doesn't match the resync spec then an error is returned.
type DB ¶
type DB interface { // Prune removes old stats based on the configured retention value. Prune() error // List returns all stats stored as a map. The map keys are sync names and the values are a list of all stored stats for. //that sysnc. Stats should be returned storted by Start in descending order. List() (map[string][]Stat, error) // Insert adds a stat to the database. Insert(Stat) error // Closes the connection the database Close() error }
DB defines an interface for persisting Stats. Stats are simple metrics for each job.
type Email ¶
type Email struct { // Host is the hostname or IP of the SMTP server. Host *string `yaml:"host"` // Port is the port of the SMTP server. Port *int `yaml:"port"` // User is the username used to authenticate. User *string `yaml:"user"` // Pass is the password used to authenticate. Pass *string `yaml:"pass"` // StartTLS enables TLS security. If both StartTLS and SSL are true then StartTLS will be used. StartTLS *bool `yaml:"starttls"` // Skip verifying the server's certificate chain and host name. InsecureSkipVerify *bool `yaml:"insecure_skip_verify"` // SSL enables SSL security. If both StartTLS and SSL are true then StartTLS will be used. SSL *bool `yaml:"ssl"` // From is the email address the email will be sent from. From *string `yaml:"from"` // To is an array of email addresses for which emails will be sent. To []string `yaml:"to"` // HistorySubject is an optional subject to use when sending sync history emails. HistorySubject *string `yaml:"history_subject"` // HistorySchedule is a cron expression. If set then an email with sync history will be sent based on the schedule. HistorySchedule *string `yaml:"history_schedule"` // HistoryTemplate is an optional path to an email template to use when sending history emails. If not set uses the default template. HistoryTemplate *string `yaml:"history_template"` // OnFailure will send an email for each sync failure if true. OnFailure *bool `yaml:"on_failure"` }
Email defines the SMTP configuration options needed when sending email notifications.
type EmailNotifier ¶ added in v0.4.0
type EmailNotifier struct {
// contains filtered or unexported fields
}
EmailNotifier sends emails based on stats saved in the DB.
func NewEmailNotifier ¶ added in v0.4.0
func NewEmailNotifier(config *Config, db DB, logger Logger) *EmailNotifier
NewEmailNotifier creates a Mailer using config, db, and logger.
func (*EmailNotifier) Notify ¶ added in v0.4.0
func (m *EmailNotifier) Notify(stat Stat) error
Notify sends a single email for the stat based on the configured email settings.
func (*EmailNotifier) NotifyHistory ¶ added in v0.4.0
func (m *EmailNotifier) NotifyHistory() error
NotifyHistory sends status email for the stats in the db based on the configured email settings.
type FSLogger ¶
type FSLogger struct {
// contains filtered or unexported fields
}
FSLoggger persists log files to a file system based on the LogPath config options. Beware that errors can occur when using the returned io.ReadClosers from Stderr and Stdout and calling Rotate.
func NewFSLogger ¶
Creates an FSLogger with the given config.
func (*FSLogger) Rotate ¶
func (l *FSLogger) Rotate(name string) (io.WriteCloser, io.WriteCloser, error)
Rotates the log files and keeps old logs based on the configured retention value.
func (*FSLogger) Stderr ¶
func (l *FSLogger) Stderr(name string) (io.ReadCloser, error)
Stderr returns the last STDERR from the rsync command. Expect errors Rotate is called while stderr is still open.
type HTTP ¶ added in v0.6.0
type HTTP struct { // The address the http server will listen on. Addr *string `yaml:"addr"` // The port the http server will listen on. Port *int `yaml:"port"` }
HTTP defines the configuration for http health checks.
type Logger ¶
type Logger interface { // Rotates the log files and keeps old logs based on the configured retention value. Rotate(string) (io.WriteCloser, io.WriteCloser, error) // Stdout returns the last STDOUT from the rsync command. Stdout(string) (io.ReadCloser, error) // Stderr returns the last STDERR from the rsync command. Stderr(string) (io.ReadCloser, error) // Zip returns file that contains all of the stored logs for all syncs. Zip() (*os.File, error) }
Logger defines an interface for persisting log files. Each rsync command logs the processes output from both STDOUT and STDERR.
type Notifier ¶ added in v0.4.0
type Notifier interface { // Notify sends a notification about a single stat. Notify(Stat) error // Notify History sends a notification with the sync history. NotifyHistory() error }
Notifier defines an interface for sending notifications.
type Resync ¶
type Resync struct {
// contains filtered or unexported fields
}
Resync is responsible for running rsync commands based on cron schedules.
type Stat ¶
type Stat struct { Name string Success bool Start string End string Duration time.Duration // contains filtered or unexported fields }
Stat defines basic statistics for a single sync. Stats are stored so that historical data from past syncs can be viewed.
type Sync ¶
type Sync struct { // RsyncArgs are all of the arguments needed to run your rsync command RsyncArgs *string `yaml:"rsync_args"` // RsyncSource is the location of the rsync command's source RsyncSource []string `yaml:"rsync_source"` // RsyncDestination is the location of the rsync command's destination RsyncDestination *string `yaml:"rsync_destination"` // Schedule is the cron expresion for this sync. Schedule *string `yaml:"schedule"` // TimeLimit is the maximum amount of time that a sync job will run before being killed. TimeLimit // must be a string that can be passed to the time.Duration.ParseDuration() function. TimeLimit *string `yaml:"time_limit"` // contains filtered or unexported fields }
Sync defines a single rsync command, cron expression, and other related options.