summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2024-05-09 11:35:15 +0300
committerGitHub <noreply@github.com>2024-05-09 11:35:15 +0300
commitb0cafb9d16801c7b6fbdc8527dee8c625ea4ed05 (patch)
tree685db7217a26d3aa841d93230d07dfeb57de3b72 /src
parent825602023b2ffad87e39dfe3549c364201d24e1d (diff)
go.d systemdunits fix unit files selector (#17622)
Diffstat (limited to 'src')
-rw-r--r--src/go/collectors/go.d.plugin/modules/systemdunits/collect_unit_files.go2
-rw-r--r--src/go/collectors/go.d.plugin/modules/systemdunits/systemdunits_test.go184
2 files changed, 113 insertions, 73 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/systemdunits/collect_unit_files.go b/src/go/collectors/go.d.plugin/modules/systemdunits/collect_unit_files.go
index c1b12cf119..eff2d6ecb6 100644
--- a/src/go/collectors/go.d.plugin/modules/systemdunits/collect_unit_files.go
+++ b/src/go/collectors/go.d.plugin/modules/systemdunits/collect_unit_files.go
@@ -79,7 +79,7 @@ func (s *SystemdUnits) getUnitFilesByPatterns(conn systemdConnection) ([]dbus.Un
s.Debugf("calling function 'ListUnitFilesByPatterns'")
- unitFiles, err := conn.ListUnitFilesByPatternsContext(ctx, nil, []string{"*.service"})
+ unitFiles, err := conn.ListUnitFilesByPatternsContext(ctx, nil, s.IncludeUnitFiles)
if err != nil {
return nil, fmt.Errorf("error on ListUnitFilesByPatterns: %v", err)
}
diff --git a/src/go/collectors/go.d.plugin/modules/systemdunits/systemdunits_test.go b/src/go/collectors/go.d.plugin/modules/systemdunits/systemdunits_test.go
index d87ae66782..fa9326b03f 100644
--- a/src/go/collectors/go.d.plugin/modules/systemdunits/systemdunits_test.go
+++ b/src/go/collectors/go.d.plugin/modules/systemdunits/systemdunits_test.go
@@ -663,83 +663,123 @@ func TestSystemdUnits_Collect(t *testing.T) {
prepare: func() *SystemdUnits {
systemd := New()
systemd.Include = []string{"*.service"}
+ systemd.IncludeUnitFiles = []string{"*.service", "*.slice"}
systemd.CollectUnitFiles = true
systemd.client = prepareOKClient(230)
return systemd
},
wantCollected: map[string]int64{
- "unit_file_/lib/systemd/system/uuidd.service_state_alias": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_bad": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_disabled": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_enabled": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_enabled-runtime": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_generated": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_indirect": 1,
- "unit_file_/lib/systemd/system/uuidd.service_state_linked": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_linked-runtime": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_masked": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_masked-runtime": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_static": 0,
- "unit_file_/lib/systemd/system/uuidd.service_state_transient": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_alias": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_bad": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_disabled": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_enabled": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_enabled-runtime": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_generated": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_indirect": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_linked": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_linked-runtime": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_masked": 1,
- "unit_file_/lib/systemd/system/x11-common.service_state_masked-runtime": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_static": 0,
- "unit_file_/lib/systemd/system/x11-common.service_state_transient": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_alias": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_bad": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_disabled": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_enabled": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_enabled-runtime": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_generated": 1,
- "unit_file_/run/systemd/generator.late/monit.service_state_indirect": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_linked": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_linked-runtime": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_masked": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_masked-runtime": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_static": 0,
- "unit_file_/run/systemd/generator.late/monit.service_state_transient": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_alias": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_bad": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_disabled": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled-runtime": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_generated": 1,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_indirect": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_linked": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_linked-runtime": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_masked": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_masked-runtime": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_static": 0,
- "unit_file_/run/systemd/generator.late/sendmail.service_state_transient": 0,
- "unit_systemd-ask-password-wall_service_state_activating": 0,
- "unit_systemd-ask-password-wall_service_state_active": 0,
- "unit_systemd-ask-password-wall_service_state_deactivating": 0,
- "unit_systemd-ask-password-wall_service_state_failed": 0,
- "unit_systemd-ask-password-wall_service_state_inactive": 1,
- "unit_systemd-fsck-root_service_state_activating": 0,
- "unit_systemd-fsck-root_service_state_active": 0,
- "unit_systemd-fsck-root_service_state_deactivating": 0,
- "unit_systemd-fsck-root_service_state_failed": 0,
- "unit_systemd-fsck-root_service_state_inactive": 1,
- "unit_user-runtime-dir@1000_service_state_activating": 0,
- "unit_user-runtime-dir@1000_service_state_active": 1,
- "unit_user-runtime-dir@1000_service_state_deactivating": 0,
- "unit_user-runtime-dir@1000_service_state_failed": 0,
- "unit_user-runtime-dir@1000_service_state_inactive": 0,
- "unit_user@1000_service_state_activating": 0,
- "unit_user@1000_service_state_active": 1,
- "unit_user@1000_service_state_deactivating": 0,
- "unit_user@1000_service_state_failed": 0,
- "unit_user@1000_service_state_inactive": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_alias": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_bad": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_disabled": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_enabled": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_enabled-runtime": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_generated": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_indirect": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_linked": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_linked-runtime": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_masked": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_masked-runtime": 0,
+ "unit_file_/lib/systemd/system/machine.slice_state_static": 1,
+ "unit_file_/lib/systemd/system/machine.slice_state_transient": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_alias": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_bad": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_disabled": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_enabled": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_enabled-runtime": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_generated": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_indirect": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_linked": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_linked-runtime": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_masked": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_masked-runtime": 0,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_static": 1,
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_transient": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_alias": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_bad": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_disabled": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_enabled": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_enabled-runtime": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_generated": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_indirect": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_linked": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_linked-runtime": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_masked": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_masked-runtime": 0,
+ "unit_file_/lib/systemd/system/user.slice_state_static": 1,
+ "unit_file_/lib/systemd/system/user.slice_state_transient": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_alias": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_bad": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_disabled": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_enabled": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_enabled-runtime": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_generated": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_indirect": 1,
+ "unit_file_/lib/systemd/system/uuidd.service_state_linked": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_linked-runtime": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_masked": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_masked-runtime": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_static": 0,
+ "unit_file_/lib/systemd/system/uuidd.service_state_transient": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_alias": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_bad": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_disabled": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_enabled": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_enabled-runtime": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_generated": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_indirect": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_linked": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_linked-runtime": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_masked": 1,
+ "unit_file_/lib/systemd/system/x11-common.service_state_masked-runtime": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_static": 0,
+ "unit_file_/lib/systemd/system/x11-common.service_state_transient": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_alias": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_bad": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_disabled": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_enabled": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_enabled-runtime": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_generated": 1,
+ "unit_file_/run/systemd/generator.late/monit.service_state_indirect": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_linked": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_linked-runtime": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_masked": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_masked-runtime": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_static": 0,
+ "unit_file_/run/systemd/generator.late/monit.service_state_transient": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_alias": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_bad": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_disabled": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled-runtime": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_generated": 1,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_indirect": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_linked": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_linked-runtime": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_masked": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_masked-runtime": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_static": 0,
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_transient": 0,
+ "unit_systemd-ask-password-wall_service_state_activating": 0,
+ "unit_systemd-ask-password-wall_service_state_active": 0,
+ "unit_systemd-ask-password-wall_service_state_deactivating": 0,
+ "unit_systemd-ask-password-wall_service_state_failed": 0,
+ "unit_systemd-ask-password-wall_service_state_inactive": 1,
+ "unit_systemd-fsck-root_service_state_activating": 0,
+ "unit_systemd-fsck-root_service_state_active": 0,
+ "unit_systemd-fsck-root_service_state_deactivating": 0,
+ "unit_systemd-fsck-root_service_state_failed": 0,
+ "unit_systemd-fsck-root_service_state_inactive": 1,
+ "unit_user-runtime-dir@1000_service_state_activating": 0,
+ "unit_user-runtime-dir@1000_service_state_active": 1,
+ "unit_user-runtime-dir@1000_service_state_deactivating": 0,
+ "unit_user-runtime-dir@1000_service_state_failed": 0,
+ "unit_user-runtime-dir@1000_service_state_inactive": 0,
+ "unit_user@1000_service_state_activating": 0,
+ "unit_user@1000_service_state_active": 1,
+ "unit_user@1000_service_state_deactivating": 0,
+ "unit_user@1000_service_state_failed": 0,
+ "unit_user@1000_service_state_inactive": 0,
},
},
"fails when all unites are filtered": {