inventory

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 8 Imported by: 0

README

Inventory

Inventory is an application that tracks deployed services/containers. It was built with a homelab in mind. It aims to answer the question:

| "Where the heck did I deploy Jellyfin, and was it Docker or Incus?"

Installation

Put the binary somewhere you can find it. /usr/local/bin/ never hurts.

Example systemd unit files are in the /contrib folder, along with example crontab and logrotate configurations.

Configuration

inventory searches /etc/inventory/, $HOME/.config/inventory/ and $HOME/.inventory/(deprecated) for a yaml formatted file named inventory.yml with configuration values.

Example config:

client:
    description: Generic Server
    location: Home Lab
    remote: 192.168.5.1:9999
debug: false
log-level: 0
server:
    http-port: 8000
    listen: 0.0.0.0
    rpc-port: 9999

If you want to track services that aren't deployed via docker or incus, you can add them as an array to the config file like this:

services:
    - name: syncthing
      port: 0
      listeners:
        - port: 8384
          listen_address: 0.0.0.0
          protocol: tcp
        - port: 22000
          listen_address: 0.0.0.0
          protocol: tcp
      protocol: ""
      unit: syncthing@.service

Permissions

The inventory send command should be run by a user who belongs to the docker and incus-admin groups. This can be root, or any other user in those groups.

Web Template

Web template modified from AdminLTE, MIT License, Copyright (c) 2014-2023 ColorlibHQ

Documentation

Overview

Package inventory provides the data structures and types used in the inventory service

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHostName  = errors.New("no hostname provided")
	ErrEmptyReport = errors.New("report cannot be nil")
	ErrEmptyQuery  = errors.New("query cannot be empty")
	ErrNoResults   = errors.New("no reports found")
)

Functions

func Static added in v0.8.0

func Static(logger *slog.Logger) http.Handler

Types

type Container

type Container struct {
	ContainerID string            `table:"container_id,default_sort" json:"container_id,omitempty"`
	Image       string            `table:"image" json:"image,omitempty"`
	IP          net.IPAddr        `table:"ip" json:"ip,omitempty"`
	Ports       []string          `table:"ports" json:"ports,omitempty"`
	HostName    string            `table:"hostname" json:"host_name,omitempty"`
	Platform    ContainerPlatform `table:"platform" json:"platform,omitempty"`
}

Container represents a container running on the host It contains the container ID, image name, IP address, ports it is listening on, the hostname of the container, and the platform it is running on. The container ID is a unique identifier for the container, which can be used to manage or interact with the container. The image name is the name of the container image that was used to create the container. The IP address is the address assigned to the container, which can be used to communicate with the container. The ports field is a list of ports that the container is listening on, which can be used to access services running inside the container. The hostname is the name of the container, which can be used to identify the container in a network or for logging purposes. The platform field indicates the container platform that is being used, such as Docker, Incus, KVM, or Podman.

type ContainerPlatform

type ContainerPlatform int

ContainerPlatform represents the platform on which a container is running

const (
	Docker ContainerPlatform = iota
	Incus
	KVM
	Podman
)

func (ContainerPlatform) String

func (p ContainerPlatform) String() string

String returns the string representation of the ContainerPlatform

type Host

type Host struct {
	HostName    string `table:"hostname,default_sort" json:"host_name,omitempty"`
	IP          string `table:"ip" json:"ip,omitempty"`
	Location    string `table:"location" json:"location,omitempty"`
	Description string `table:"description" json:"description,omitempty"`
}

Host represents the host information It contains the hostname, IP address, location, and description of the host. The IP address is represented as a string to allow for both IPv4 and IPv6 addresses. The location and description fields are optional and can be used to provide additional information about the host. The location field can be used to specify the physical location of the host, such as a data center or office location. The description field can be used to provide a brief description of the host, such as its purpose or role in the network or a physical description of the host.

type Listen

type Listen struct {
	Port          uint16 `table:"port" json:"port,omitempty"`
	ListenAddress string `yaml:"listen_address" table:"listen_address" json:"listen_address,omitempty"`
	Protocol      string `table:"protocol" json:"protocol,omitempty"`
}

Listen represents a network listener for a service

type Listener

type Listener struct {
	ListenAddress net.IP `table:"listen_address" json:"listen_address,omitempty"`
	Port          uint16 `table:"port" json:"port,omitempty"`
	PID           int    `table:"pid" json:"pid,omitempty"`
	Program       string `table:"program,default_sort" json:"program,omitempty"`
}

Listener represents a network listener on the host It contains the address it is listening on, the port it is listening on, the PID of the process that is listening, and the name of the program that is listening.

type Report

type Report struct {
	Host       Host        `table:"host,default_sort"`
	Services   []Service   `table:"services"`
	Listeners  []Listener  `table:"listeners"`
	Containers []Container `table:"containers"`
	Timestamp  time.Time   `table:"timestamp" `
}

Report represents the data structure sent to the server It contains information about the host, services, listeners, and containers that are running on the host.

func (*Report) DisplayTime

func (r *Report) DisplayTime() string

DisplayTime returns the timestamp in a human-readable format

func (*Report) HasPlatform added in v0.8.0

func (r *Report) HasPlatform(platform string) bool

type Service

type Service struct {
	Name      string    `table:"name,default_sort" json:"name,omitempty"`
	Port      uint16    `table:"port" json:"port,omitempty"`
	Listeners []*Listen `table:"listeners" json:"listeners,omitempty"`
	Protocol  string    `table:"protocol" json:"protocol,omitempty"`
	Unit      string    `table:"unit" json:"unit,omitempty"`
}

Service represents a service running on the host It contains the name of the service, the port it is listening on, the address it is listening on, the protocol it uses, and the unit name (if applicable). Services can be any type of service, such as a web server, database server, or any other type of service that listens for incoming connections. They are provided to account for services that are not necessarily containers.

type Storage

type Storage interface {
	StoreReport(report Report) error
	GetReport(hostname string) (Report, bool)
	GetAllReports() []Report
}

Storage defines the interface for persisting inventory data

Directories

Path Synopsis
Package client provides a client for the inventory server.
Package client provides a client for the inventory server.
cmd
inventory command
Package routes defines the routes for the web server
Package routes defines the routes for the web server
Package service provides the inventory server implementation It implements the RPC methods for the inventory server
Package service provides the inventory server implementation It implements the RPC methods for the inventory server
Package storage provides an in-memory implementation of the inventory.Storage interface It is the only storage implementation currently available
Package storage provides an in-memory implementation of the inventory.Storage interface It is the only storage implementation currently available
web
components
templ: version: v0.3.857
templ: version: v0.3.857
layouts
templ: version: v0.3.857
templ: version: v0.3.857
pages
templ: version: v0.3.857
templ: version: v0.3.857

Jump to

Keyboard shortcuts

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