go.d systemdunits fix unit files selector (#17622)
Ilya Mashchenko committed
May 9, 2024 at 11:35 UTC
b0cafb9d16801c7b6fbdc8527dee8c625ea4ed05
2 files changed
+113
-73
src/go/collectors/go.d.plugin/modules/systemdunits/collect_unit_files.go
+1
-1
@@ -79,7 +79,7 @@ func (s *SystemdUnits) getUnitFilesByPatterns(conn systemdConnection) ([]dbus.Un
79
80
s.Debugf("calling function 'ListUnitFilesByPatterns'")
81
82
- unitFiles, err := conn.ListUnitFilesByPatternsContext(ctx, nil, []string{"*.service"})
82
+ unitFiles, err := conn.ListUnitFilesByPatternsContext(ctx, nil, s.IncludeUnitFiles)
83
if err != nil {
84
return nil, fmt.Errorf("error on ListUnitFilesByPatterns: %v", err)
85
}
src/go/collectors/go.d.plugin/modules/systemdunits/systemdunits_test.go
+112
-72
@@ -663,83 +663,123 @@ func TestSystemdUnits_Collect(t *testing.T) {
663
prepare: func() *SystemdUnits {
664
systemd := New()
665
systemd.Include = []string{"*.service"}
666
+ systemd.IncludeUnitFiles = []string{"*.service", "*.slice"}
667
systemd.CollectUnitFiles = true
668
systemd.client = prepareOKClient(230)
669
return systemd
670
},
671
wantCollected: map[string]int64{
671
- "unit_file_/lib/systemd/system/uuidd.service_state_alias": 0,
672
- "unit_file_/lib/systemd/system/uuidd.service_state_bad": 0,
673
- "unit_file_/lib/systemd/system/uuidd.service_state_disabled": 0,
674
- "unit_file_/lib/systemd/system/uuidd.service_state_enabled": 0,
675
- "unit_file_/lib/systemd/system/uuidd.service_state_enabled-runtime": 0,
676
- "unit_file_/lib/systemd/system/uuidd.service_state_generated": 0,
677
- "unit_file_/lib/systemd/system/uuidd.service_state_indirect": 1,
678
- "unit_file_/lib/systemd/system/uuidd.service_state_linked": 0,
679
- "unit_file_/lib/systemd/system/uuidd.service_state_linked-runtime": 0,
680
- "unit_file_/lib/systemd/system/uuidd.service_state_masked": 0,
681
- "unit_file_/lib/systemd/system/uuidd.service_state_masked-runtime": 0,
682
- "unit_file_/lib/systemd/system/uuidd.service_state_static": 0,
683
- "unit_file_/lib/systemd/system/uuidd.service_state_transient": 0,
684
- "unit_file_/lib/systemd/system/x11-common.service_state_alias": 0,
685
- "unit_file_/lib/systemd/system/x11-common.service_state_bad": 0,
686
- "unit_file_/lib/systemd/system/x11-common.service_state_disabled": 0,
687
- "unit_file_/lib/systemd/system/x11-common.service_state_enabled": 0,
688
- "unit_file_/lib/systemd/system/x11-common.service_state_enabled-runtime": 0,
689
- "unit_file_/lib/systemd/system/x11-common.service_state_generated": 0,
690
- "unit_file_/lib/systemd/system/x11-common.service_state_indirect": 0,
691
- "unit_file_/lib/systemd/system/x11-common.service_state_linked": 0,
692
- "unit_file_/lib/systemd/system/x11-common.service_state_linked-runtime": 0,
693
- "unit_file_/lib/systemd/system/x11-common.service_state_masked": 1,
694
- "unit_file_/lib/systemd/system/x11-common.service_state_masked-runtime": 0,
695
- "unit_file_/lib/systemd/system/x11-common.service_state_static": 0,
696
- "unit_file_/lib/systemd/system/x11-common.service_state_transient": 0,
697
- "unit_file_/run/systemd/generator.late/monit.service_state_alias": 0,
698
- "unit_file_/run/systemd/generator.late/monit.service_state_bad": 0,
699
- "unit_file_/run/systemd/generator.late/monit.service_state_disabled": 0,
700
- "unit_file_/run/systemd/generator.late/monit.service_state_enabled": 0,
701
- "unit_file_/run/systemd/generator.late/monit.service_state_enabled-runtime": 0,
702
- "unit_file_/run/systemd/generator.late/monit.service_state_generated": 1,
703
- "unit_file_/run/systemd/generator.late/monit.service_state_indirect": 0,
704
- "unit_file_/run/systemd/generator.late/monit.service_state_linked": 0,
705
- "unit_file_/run/systemd/generator.late/monit.service_state_linked-runtime": 0,
706
- "unit_file_/run/systemd/generator.late/monit.service_state_masked": 0,
707
- "unit_file_/run/systemd/generator.late/monit.service_state_masked-runtime": 0,
708
- "unit_file_/run/systemd/generator.late/monit.service_state_static": 0,
709
- "unit_file_/run/systemd/generator.late/monit.service_state_transient": 0,
710
- "unit_file_/run/systemd/generator.late/sendmail.service_state_alias": 0,
711
- "unit_file_/run/systemd/generator.late/sendmail.service_state_bad": 0,
712
- "unit_file_/run/systemd/generator.late/sendmail.service_state_disabled": 0,
713
- "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled": 0,
714
- "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled-runtime": 0,
715
- "unit_file_/run/systemd/generator.late/sendmail.service_state_generated": 1,
716
- "unit_file_/run/systemd/generator.late/sendmail.service_state_indirect": 0,
717
- "unit_file_/run/systemd/generator.late/sendmail.service_state_linked": 0,
718
- "unit_file_/run/systemd/generator.late/sendmail.service_state_linked-runtime": 0,
719
- "unit_file_/run/systemd/generator.late/sendmail.service_state_masked": 0,
720
- "unit_file_/run/systemd/generator.late/sendmail.service_state_masked-runtime": 0,
721
- "unit_file_/run/systemd/generator.late/sendmail.service_state_static": 0,
722
- "unit_file_/run/systemd/generator.late/sendmail.service_state_transient": 0,
723
- "unit_systemd-ask-password-wall_service_state_activating": 0,
724
- "unit_systemd-ask-password-wall_service_state_active": 0,
725
- "unit_systemd-ask-password-wall_service_state_deactivating": 0,
726
- "unit_systemd-ask-password-wall_service_state_failed": 0,
727
- "unit_systemd-ask-password-wall_service_state_inactive": 1,
728
- "unit_systemd-fsck-root_service_state_activating": 0,
729
- "unit_systemd-fsck-root_service_state_active": 0,
730
- "unit_systemd-fsck-root_service_state_deactivating": 0,
731
- "unit_systemd-fsck-root_service_state_failed": 0,
732
- "unit_systemd-fsck-root_service_state_inactive": 1,
733
- "unit_user-runtime-dir@1000_service_state_activating": 0,
734
- "unit_user-runtime-dir@1000_service_state_active": 1,
735
- "unit_user-runtime-dir@1000_service_state_deactivating": 0,
736
- "unit_user-runtime-dir@1000_service_state_failed": 0,
737
- "unit_user-runtime-dir@1000_service_state_inactive": 0,
738
- "unit_user@1000_service_state_activating": 0,
739
- "unit_user@1000_service_state_active": 1,
740
- "unit_user@1000_service_state_deactivating": 0,
741
- "unit_user@1000_service_state_failed": 0,
742
- "unit_user@1000_service_state_inactive": 0,
672
+ "unit_file_/lib/systemd/system/machine.slice_state_alias": 0,
673
+ "unit_file_/lib/systemd/system/machine.slice_state_bad": 0,
674
+ "unit_file_/lib/systemd/system/machine.slice_state_disabled": 0,
675
+ "unit_file_/lib/systemd/system/machine.slice_state_enabled": 0,
676
+ "unit_file_/lib/systemd/system/machine.slice_state_enabled-runtime": 0,
677
+ "unit_file_/lib/systemd/system/machine.slice_state_generated": 0,
678
+ "unit_file_/lib/systemd/system/machine.slice_state_indirect": 0,
679
+ "unit_file_/lib/systemd/system/machine.slice_state_linked": 0,
680
+ "unit_file_/lib/systemd/system/machine.slice_state_linked-runtime": 0,
681
+ "unit_file_/lib/systemd/system/machine.slice_state_masked": 0,
682
+ "unit_file_/lib/systemd/system/machine.slice_state_masked-runtime": 0,
683
+ "unit_file_/lib/systemd/system/machine.slice_state_static": 1,
684
+ "unit_file_/lib/systemd/system/machine.slice_state_transient": 0,
685
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_alias": 0,
686
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_bad": 0,
687
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_disabled": 0,
688
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_enabled": 0,
689
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_enabled-runtime": 0,
690
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_generated": 0,
691
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_indirect": 0,
692
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_linked": 0,
693
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_linked-runtime": 0,
694
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_masked": 0,
695
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_masked-runtime": 0,
696
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_static": 1,
697
+ "unit_file_/lib/systemd/system/system-systemd-cryptsetup.slice_state_transient": 0,
698
+ "unit_file_/lib/systemd/system/user.slice_state_alias": 0,
699
+ "unit_file_/lib/systemd/system/user.slice_state_bad": 0,
700
+ "unit_file_/lib/systemd/system/user.slice_state_disabled": 0,
701
+ "unit_file_/lib/systemd/system/user.slice_state_enabled": 0,
702
+ "unit_file_/lib/systemd/system/user.slice_state_enabled-runtime": 0,
703
+ "unit_file_/lib/systemd/system/user.slice_state_generated": 0,
704
+ "unit_file_/lib/systemd/system/user.slice_state_indirect": 0,
705
+ "unit_file_/lib/systemd/system/user.slice_state_linked": 0,
706
+ "unit_file_/lib/systemd/system/user.slice_state_linked-runtime": 0,
707
+ "unit_file_/lib/systemd/system/user.slice_state_masked": 0,
708
+ "unit_file_/lib/systemd/system/user.slice_state_masked-runtime": 0,
709
+ "unit_file_/lib/systemd/system/user.slice_state_static": 1,
710
+ "unit_file_/lib/systemd/system/user.slice_state_transient": 0,
711
+ "unit_file_/lib/systemd/system/uuidd.service_state_alias": 0,
712
+ "unit_file_/lib/systemd/system/uuidd.service_state_bad": 0,
713
+ "unit_file_/lib/systemd/system/uuidd.service_state_disabled": 0,
714
+ "unit_file_/lib/systemd/system/uuidd.service_state_enabled": 0,
715
+ "unit_file_/lib/systemd/system/uuidd.service_state_enabled-runtime": 0,
716
+ "unit_file_/lib/systemd/system/uuidd.service_state_generated": 0,
717
+ "unit_file_/lib/systemd/system/uuidd.service_state_indirect": 1,
718
+ "unit_file_/lib/systemd/system/uuidd.service_state_linked": 0,
719
+ "unit_file_/lib/systemd/system/uuidd.service_state_linked-runtime": 0,
720
+ "unit_file_/lib/systemd/system/uuidd.service_state_masked": 0,
721
+ "unit_file_/lib/systemd/system/uuidd.service_state_masked-runtime": 0,
722
+ "unit_file_/lib/systemd/system/uuidd.service_state_static": 0,
723
+ "unit_file_/lib/systemd/system/uuidd.service_state_transient": 0,
724
+ "unit_file_/lib/systemd/system/x11-common.service_state_alias": 0,
725
+ "unit_file_/lib/systemd/system/x11-common.service_state_bad": 0,
726
+ "unit_file_/lib/systemd/system/x11-common.service_state_disabled": 0,
727
+ "unit_file_/lib/systemd/system/x11-common.service_state_enabled": 0,
728
+ "unit_file_/lib/systemd/system/x11-common.service_state_enabled-runtime": 0,
729
+ "unit_file_/lib/systemd/system/x11-common.service_state_generated": 0,
730
+ "unit_file_/lib/systemd/system/x11-common.service_state_indirect": 0,
731
+ "unit_file_/lib/systemd/system/x11-common.service_state_linked": 0,
732
+ "unit_file_/lib/systemd/system/x11-common.service_state_linked-runtime": 0,
733
+ "unit_file_/lib/systemd/system/x11-common.service_state_masked": 1,
734
+ "unit_file_/lib/systemd/system/x11-common.service_state_masked-runtime": 0,
735
+ "unit_file_/lib/systemd/system/x11-common.service_state_static": 0,
736
+ "unit_file_/lib/systemd/system/x11-common.service_state_transient": 0,
737
+ "unit_file_/run/systemd/generator.late/monit.service_state_alias": 0,
738
+ "unit_file_/run/systemd/generator.late/monit.service_state_bad": 0,
739
+ "unit_file_/run/systemd/generator.late/monit.service_state_disabled": 0,
740
+ "unit_file_/run/systemd/generator.late/monit.service_state_enabled": 0,
741
+ "unit_file_/run/systemd/generator.late/monit.service_state_enabled-runtime": 0,
742
+ "unit_file_/run/systemd/generator.late/monit.service_state_generated": 1,
743
+ "unit_file_/run/systemd/generator.late/monit.service_state_indirect": 0,
744
+ "unit_file_/run/systemd/generator.late/monit.service_state_linked": 0,
745
+ "unit_file_/run/systemd/generator.late/monit.service_state_linked-runtime": 0,
746
+ "unit_file_/run/systemd/generator.late/monit.service_state_masked": 0,
747
+ "unit_file_/run/systemd/generator.late/monit.service_state_masked-runtime": 0,
748
+ "unit_file_/run/systemd/generator.late/monit.service_state_static": 0,
749
+ "unit_file_/run/systemd/generator.late/monit.service_state_transient": 0,
750
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_alias": 0,
751
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_bad": 0,
752
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_disabled": 0,
753
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled": 0,
754
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_enabled-runtime": 0,
755
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_generated": 1,
756
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_indirect": 0,
757
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_linked": 0,
758
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_linked-runtime": 0,
759
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_masked": 0,
760
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_masked-runtime": 0,
761
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_static": 0,
762
+ "unit_file_/run/systemd/generator.late/sendmail.service_state_transient": 0,
763
+ "unit_systemd-ask-password-wall_service_state_activating": 0,
764
+ "unit_systemd-ask-password-wall_service_state_active": 0,
765
+ "unit_systemd-ask-password-wall_service_state_deactivating": 0,
766
+ "unit_systemd-ask-password-wall_service_state_failed": 0,
767
+ "unit_systemd-ask-password-wall_service_state_inactive": 1,
768
+ "unit_systemd-fsck-root_service_state_activating": 0,
769
+ "unit_systemd-fsck-root_service_state_active": 0,
770
+ "unit_systemd-fsck-root_service_state_deactivating": 0,
771
+ "unit_systemd-fsck-root_service_state_failed": 0,
772
+ "unit_systemd-fsck-root_service_state_inactive": 1,
773
+ "unit_user-runtime-dir@1000_service_state_activating": 0,
774
+ "unit_user-runtime-dir@1000_service_state_active": 1,
775
+ "unit_user-runtime-dir@1000_service_state_deactivating": 0,
776
+ "unit_user-runtime-dir@1000_service_state_failed": 0,
777
+ "unit_user-runtime-dir@1000_service_state_inactive": 0,
778
+ "unit_user@1000_service_state_activating": 0,
779
+ "unit_user@1000_service_state_active": 1,
780
+ "unit_user@1000_service_state_deactivating": 0,
781
+ "unit_user@1000_service_state_failed": 0,
782
+ "unit_user@1000_service_state_inactive": 0,
783
},
784
},
785
"fails when all unites are filtered": {