entities

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date time.Time

Date is a custom type for time.Time that marshals to and from RFC3339 date only.

func (*Date) MarshalJSON

func (d *Date) MarshalJSON() ([]byte, error)

MarshalJSON marshals the date to JSON.

func (*Date) MarshalText

func (d *Date) MarshalText() ([]byte, error)

MarshalText marshals the date to text.

func (*Date) Scan

func (d *Date) Scan(src any) error

Scan scans the date from a database value.

func (Date) String

func (d Date) String() string

String returns the date as a string.

func (Date) Time

func (d Date) Time() time.Time

MySQL returns the date as a MySQL string.

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(text []byte) error

UnmarshalJSON unmarshals the date from JSON.

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(text []byte) error

UnmarshalText unmarshals the date from text.

type Datetime

type Datetime time.Time

Datetime represents a datetime.

func (*Datetime) MarshalBSON

func (d *Datetime) MarshalBSON() ([]byte, error)

func (*Datetime) MarshalBSONValue

func (d *Datetime) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Datetime) MarshalJSON

func (d *Datetime) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Datetime) Scan

func (d *Datetime) Scan(src any) error

Scan implements the sql.Scanner interface.

func (Datetime) String

func (d Datetime) String() string

String implements the fmt.Stringer interface.

func (Datetime) Time

func (d Datetime) Time() time.Time

func (*Datetime) UnmarshalBSON

func (d *Datetime) UnmarshalBSON(bytes []byte) error

func (*Datetime) UnmarshalJSON

func (d *Datetime) UnmarshalJSON(text []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Duration

type Duration time.Duration

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON marshals the duration to JSON. We want to marshal to a max of days (e.g. 1d2h3m4s)

func (Duration) PrettyString

func (d Duration) PrettyString() string

PrettyString returns the duration as a pretty string.

func (*Duration) Scan

func (d *Duration) Scan(src any) error

Scan converts the string to a duration.

func (Duration) String

func (d Duration) String() string

String returns the duration as a string.

func (*Duration) Time

func (d *Duration) Time() time.Duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(text []byte) error

UnmarshalJSON unmarshals the duration from JSON.

Remove all quites from text if present with regex (e.g. "1h30m" -> 1h30m) reg := regexp.MustCompile(`"(.*)"`) text = reg.ReplaceAll(text, []byte("$1")) Parse the duration from a string

type PuppetHistory

type PuppetHistory struct {
	// Date is the date of the run.
	Date string `json:"date" bson:"date"`

	// Changed is the number of resources that changed.
	Changed int `json:"changed" bson:"changed"`

	// Unchanged is the number of resources that were unchanged.
	Unchanged int `json:"unchanged" bson:"unchanged"`

	// Failed is the number of resources that failed.
	Failed int `json:"failed" bson:"failed"`
}

func (*PuppetHistory) AddCount

func (p *PuppetHistory) AddCount(state summary.State, count int)

type PuppetReport

type PuppetReport struct {
	// ID is a hash of the report-body. This is used to create the file to store the report in on-disk,
	// and as a means of detecting duplication submissions.
	ID string `json:"id" bson:"id"`

	// Fqdn of the node.
	Fqdn string `json:"fqdn" bson:"fqdn"`

	// PuppetVersion is the version of puppet used to generate the report.
	PuppetVersion float64 `json:"puppet_version" bson:"puppet_version"`

	// Env of the node.
	Env summary.Environment `json:"env" bson:"env"`

	// State of the run. changed, unchanged, etc.
	State summary.State `json:"state" bson:"state"`

	// ExecTime is the time the puppet-run was completed. This is self-reported by the node, and copied almost literally.
	ExecTime Datetime `json:"exec_time" bson:"exec_time"`

	// Runtime is the time the puppet-run took.
	Runtime Duration `json:"runtime" bson:"runtime"`

	// Failed is the number of resources which failed.
	Failed int64 `json:"failed" bson:"failed"`

	// Changed is the number of resources which changed.
	Changed int64 `json:"changed" bson:"changed"`

	// Skipped is the number of resources which were skipped.
	Skipped int64 `json:"skipped" bson:"skipped"`

	// Total is the total number of resources.
	Total int64 `json:"total" bson:"total"`

	// LogMessages are the messages logged by puppet.
	LogMessages []string `json:"log_messages" bson:"log_messages"`

	// ResourcesFailed are the resources which failed.
	ResourcesFailed []*PuppetResource `json:"resources_failed" bson:"resources_failed"`

	// ResourcesChanged are the resources which changed.
	ResourcesChanged []*PuppetResource `json:"resources_changed" bson:"resources_changed"`

	// ResourcesSkipped are the resources which were skipped.
	ResourcesSkipped []*PuppetResource `json:"resources_skipped" bson:"resources_skipped"`

	// ResourcesOK are the resources which were OK.
	ResourcesOK []*PuppetResource `json:"resources_ok" bson:"resources_ok"`

	// YamlFile is the file the report was read from.
	YamlFile string `json:"-" bson:"yamlFile"`
}

PuppetReport stores the details of a single run of puppet.

func (*PuppetReport) ReportFilePath

func (n *PuppetReport) ReportFilePath() string

func (*PuppetReport) SortResources

func (n *PuppetReport) SortResources()

type PuppetReportSummary

type PuppetReportSummary struct {
	// ID is the ID of the node.
	ID string `json:"id" bson:"id"`

	// Fqdn is the FQDN of the node.
	Fqdn string `json:"fqdn" bson:"fqdn"`

	// Env is the environment of the node.
	Env summary.Environment `json:"env" bson:"env"`

	// State is the state of the node.
	State summary.State `json:"state" bson:"state"`

	// ExecTime is the time the puppet-run was completed. This is self-reported by the node, and copied almost literally.
	ExecTime Datetime `json:"exec_time" bson:"exec_time"`

	// TimeSince is the time since the puppet-run was completed.
	TimeSince Duration `json:"time_since" bson:"time_since"`

	// Runtime is the time the puppet-run took.
	Runtime Duration `json:"runtime" bson:"runtime"`

	// Failed is the number of resources which failed.
	Failed int `json:"failed" bson:"failed"`

	// Changed is the number of resources which changed.
	Changed int `json:"changed" bson:"changed"`

	// Skipped is the number of resources which were skipped.
	Skipped int `json:"skipped" bson:"skipped"`

	// Total is the total number of resources.
	Total int `json:"total" bson:"total"`

	// YamlFile is the file the report was read from.
	YamlFile string `json:"-" bson:"yamlFile"`
}

PuppetReportSummary is the structure used to represent a series of puppet-runs against a particular node.

func (*PuppetReportSummary) CalculateTimeSince

func (n *PuppetReportSummary) CalculateTimeSince()

func (*PuppetReportSummary) ReportFilePath

func (n *PuppetReportSummary) ReportFilePath() string

type PuppetResource

type PuppetResource struct {
	Name string `json:"name" bson:"name"`
	Type string `json:"type" bson:"type"`
	File string `json:"file" bson:"file"`
	Line string `json:"line" bson:"line"`
}

PuppetResource refers to a resource in your puppet modules, a resource has a name, along with the file & line-number it was defined in within your manifest

type PuppetRun

type PuppetRun struct {
	ID        string              `json:"id,omitempty" bson:"id"`
	Fqdn      string              `json:"fqdn" bson:"fqdn"`
	Env       summary.Environment `json:"env" bson:"env"`
	State     summary.State       `json:"state" bson:"state"`
	ExecTime  Datetime            `json:"exec_time" bson:"exec_time"`
	Runtime   Duration            `json:"runtime" bson:"runtime"`
	TimeSince Duration            `json:"-" bson:"time_since"`
}

PuppetRun is the structure which is used to list a summary of puppet runs on the front-page.

func (*PuppetRun) CalculateTimeSince

func (p *PuppetRun) CalculateTimeSince()

Jump to

Keyboard shortcuts

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