journal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanAccessLogs added in v0.2.0

func CanAccessLogs() bool

CanAccessLogs checks if the current process has permission to access system logs. It returns true if the process is running as root or can successfully open the systemd journal.

func CreateListLogsSchema added in v0.2.0

func CreateListLogsSchema() *jsonschema.Schema

Types

type HostLog

type HostLog struct {
	// contains filtered or unexported fields
}

func NewLog

func NewLog(auth *auth.AuthKeeper) (*HostLog, error)

NewLog instance creates a new HostLog instance

func (*HostLog) Close

func (log *HostLog) Close() error

Close the log and underlying journal

func (*HostLog) ListLog

func (sj *HostLog) ListLog(ctx context.Context, req *mcp.CallToolRequest, params *ListLogParams) (*mcp.CallToolResult, any, error)
func (sj *HostLog) ListLogTimeout(ctx context.Context, req *mcp.CallToolRequest, params *ListLogParams) (*mcp.CallToolResult, any, error) {
	slog.Debug("ListLogTimeout called", "params", params)
	timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Second)
	defer cancel()

	resultChan := make(chan struct {
		res *mcp.CallToolResult
		out any
		err error
	}, 1)

	go func() {
		res, out, err := sj.ListLog(timeoutCtx, req, params)
		resultChan <- struct {
			res *mcp.CallToolResult
			out any
			err error
		}{res: res, out: out, err: err}
	}()

	select {
	case <-timeoutCtx.Done():
		// The timeout context was cancelled, meaning the timeout occurred.
		return nil, nil, fmt.Errorf("timed out: %w", timeoutCtx.Err())
	case result := <-resultChan:
		// ListLog completed within the timeout.
		return result.res, result.out, result.err
	}
}

get the lat log entries for a given unit, else just the last messages

type ListLogParams

type ListLogParams struct {
	Count    int       `json:"count,omitempty" jsonschema:"Number of log lines to output"`
	Offset   int       `json:"offset,omitempty" jsonschema:"Number of newest log entries to skip for pagination"`
	From     time.Time `json:"from,omitempty" jsonschema:"Start time for filtering logs"`
	To       time.Time `json:"to,omitempty" jsonschema:"End time for filtering logs "`
	Pattern  string    `json:"pattern,omitempty" jsonschema:"Regular expression pattern to filter log messages."`
	Unit     string    `` /* 181-byte string literal not displayed */
	AllBoots bool      `json:"allboots,omitempty" jsonschema:"Get the log entries from all boots, not just the active one"`
}

type ListLogResult added in v0.2.0

type ListLogResult struct {
	Host          string      `json:"host"`
	NrMessages    int         `json:"nr_messages"`
	Hint          string      `json:"hint,omitempty"`
	Documentation []ManPage   `json:"documentation,omitempty"`
	Messages      []LogOutput `json:"messages"`
	Identifier    string      `json:"identifier,omitempty"`
	UnitName      string      `json:"unit_name,omitempty"`
}

type LogOutput added in v0.2.0

type LogOutput struct {
	Time       time.Time `json:"time"`
	Identifier string    `json:"identifier,omitempty"`
	UnitName   string    `json:"unit_name,omitempty"`
	ExeName    string    `json:"exe_name,omitempty"`
	Host       string    `json:"host,omitempty"`
	Msg        string    `json:"message"`
	Boot       string    `json:"bootid,omitempty"`
}

type ManPage added in v0.2.0

type ManPage struct {
	Name        string `json:"name"`
	Section     uint   `json:"section"`
	Description string `json:"description"`
}

Jump to

Keyboard shortcuts

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