util

package
v0.0.0-...-5615184 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package util offers helpers and building blocks to easily generate payloads for the inventory product.

Usage: When creating a new payload for the inventory product, one should only embed the 'InventoryPayload' struct and provide it with a callback to generate a payload.

Example:

type customPayload struct {
	InventoryPayload
}

type dependencies struct {
	fx.In

	Log        log.Component
	Config     config.Component
	Serializer serializer.MetricSerializer
}

type provides struct {
	fx.Out

	Comp          Component
	Provider      runner.Provider
	FlareProvider flaretypes.Provider
}

func newCustomPayload(deps dependencies) provides {
	cp := &customPayload{
		InventoryPayload: CreateInventoryPayload(
			deps.Config,
			deps.Log,
			deps.Serializer,
			cp.getPayload,
			"custom.json",
		),
	}

	return provides{
		Comp:          cp,
		Provider:      cp.MetadataProvider(),
		FlareProvider: cp.FlareProvider(),
	}
}

func (cp *customPayload) getPayload() marshaler.JSONMarshaler { ... }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InventoryEnabled

func InventoryEnabled(conf model.Reader) bool

InventoryEnabled returs true if 'enable_metadata_collection' and 'inventories_enabled' are set to true in the configuration.

Types

type InventoryPayload

type InventoryPayload struct {
	Enabled     bool
	LastCollect time.Time
	MinInterval time.Duration
	MaxInterval time.Duration

	FlareFileName string
	// contains filtered or unexported fields
}

InventoryPayload offers helpers for all inventory payloads providing all the common part to create a new payload. InventoryPayload will handle the common configuration as well as refresh rates and flare. This type is meant to be embedded.

Embedding type need to provide a PayloadGetter callback when calling Init. This callback will be called each time a new payload need to be generated.

func CreateInventoryPayload

func CreateInventoryPayload(conf config.Component, l log.Component, s serializer.MetricSerializer, getPayload PayloadGetter, flareFileName string) InventoryPayload

CreateInventoryPayload returns an initialized InventoryPayload. 'getPayload' will be called each time a new payload needs to be generated.

func (*InventoryPayload) FlareProvider

func (i *InventoryPayload) FlareProvider() flaretypes.Provider

FlareProvider returns a flare providers to add the current inventory payload to each flares.

func (*InventoryPayload) GetAsJSON

func (i *InventoryPayload) GetAsJSON() ([]byte, error)

GetAsJSON returns the payload as a JSON string. Useful to be displayed in the CLI or added to a flare.

func (*InventoryPayload) MetadataProvider

func (i *InventoryPayload) MetadataProvider() runnerimpl.Provider

MetadataProvider returns a metadata 'runner.Provider' for the current inventory payload (taking into account if invnetory is enabled or not).

func (*InventoryPayload) Refresh

func (i *InventoryPayload) Refresh()

Refresh trigger a new payload to be send while still respecting the minimal interval between two updates.

func (*InventoryPayload) RefreshTriggered

func (i *InventoryPayload) RefreshTriggered() bool

RefreshTriggered returns true if a refresh was trigger but not yet done.

type PayloadGetter

type PayloadGetter func() marshaler.JSONMarshaler

PayloadGetter is the callback to generate a new payload exposed by each inventory payload to InventoryPayload utils

Jump to

Keyboard shortcuts

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