Categorygithub.com/infrasonar/go-libagent
repositorypackage
1.0.4
Repository: https://github.com/infrasonar/go-libagent.git
Documentation: pkg.go.dev

# README

CI Release Version

Go library for building InfraSonar Probes

This library is created for building InfraSonar probes.

Environment variables

EnvironmentDefaultDescription
CONFIG_PATH/etc/infrasonarPath where configuration files are loaded and stored (note: for a user, the $HOME path will be used instead of /etc)
TOKENrequiredToken used for authentication (This MUST be a container token).
ASSET_NAMEnoneInitial Asset Name. This will only be used at the announce. Once the asset is created, ASSET_NAME will be ignored.
ASSET_IDnoneAsset Id (If not given, the asset Id will be stored and loaded from file).
API_URIhttps://api.infrasonar.comInfraSonar API.
SKIP_VERIFYnoneSet to 1 or something else to skip certificate validation.
CHECK_XXX_INTERVAL300Interval in seconds for the xxx check or 0 to disable the check. (should be one environment variable for each check)
DISABLED_CHECKS_CACHE_AGE15mKeep disabled checks cache for this time before polling again.

Floating points

Be aware that floating points might be converted to fixed integer values. To preserve the .0 convert floating point values to the provides IFloat32 or IFloat64 types.

Example

package main

import (
	"log"

	"github.com/infrasonar/go-libagent"
)

const version = "0.1.0"

func CheckSample() (map[string][]map[string]any, error) {
	state := map[string][]map[string]any{}

	// Here code to create a check state.

	// Returning with an error will result in an InfraSonar Notification with
	// a check error.

	// Both a state and an error may be returned.

	// Example state (type: agent):

	state["agent"] = []map[string]any{{
		"name":    "example",
		"version": version,
	}}

	return state, nil
}

func main() {
	// Start collector
	log.Printf("Starting InfraSonar Example Agent Collector v%s\n", version)

	// Initialize random
	libagent.RandInit()

	// Initialize Helper
	libagent.GetHelper()

	// Set-up signal handler
	quit := make(chan bool)
	go libagent.SigHandler(quit)

	// Create Collector
	collector := libagent.NewCollector("example", version)

	// Create Asset
	asset := libagent.NewAsset(collector)
	//asset.Kind = "Asset" // Optionally, set the asset Kind
	asset.Announce()

	// Create and plan checks
	checkSample := libagent.Check{
		Key:             "sample",
		Collector:       collector,
		Asset:           asset,
		IntervalEnv:     "CHECK_SAMPLE_INTERVAL",
		DefaultInterval: 300,
		NoCount:         false,
		SetTimestamp:    false,
		Fn:              CheckSample,
	}
	go checkSample.Plan(quit)

	// Wait for quit
	<-quit
}