summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/systemdunits/client.go
blob: a2787c4ec106556108fed2e6895438a69b499682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// SPDX-License-Identifier: GPL-3.0-or-later

//go:build linux
// +build linux

package systemdunits

import (
	"context"

	"github.com/coreos/go-systemd/v22/dbus"
)

type systemdClient interface {
	connect() (systemdConnection, error)
}
type systemdConnection interface {
	Close()
	GetManagerProperty(string) (string, error)
	ListUnitsContext(ctx context.Context) ([]dbus.UnitStatus, error)
	ListUnitsByPatternsContext(ctx context.Context, states []string, patterns []string) ([]dbus.UnitStatus, error)
}

type systemdDBusClient struct{}

func (systemdDBusClient) connect() (systemdConnection, error) {
	return dbus.NewWithContext(context.Background())
}

func newSystemdDBusClient() *systemdDBusClient {
	return &systemdDBusClient{}
}