Skip to content

Commit 27c5de1

Browse files
committed
Addressing #1 by complaining about missing services
1 parent cd06be7 commit 27c5de1

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

bin/check-systemd.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ def initialize
4141
@crit_service = []
4242
end
4343

44+
def all_service_names
45+
systemd_output = `systemctl --no-legend`
46+
systemd_output.split("\n").collect do |line|
47+
line.split(' ').first
48+
end
49+
end
50+
4451
def unit_services
4552
systemd_output = `systemctl --failed --no-legend`
4653
service_array = []
@@ -59,6 +66,10 @@ def unit_services
5966
end
6067

6168
def check_systemd
69+
@services.reject { |service| validate_presence_of(service) }.each do |gone|
70+
@crit_service << "#{gone} - Not Present"
71+
end
72+
6273
unit_services.each do |service|
6374
if service['active'] != 'active'
6475
@crit_service << "#{service['name']} - #{service['active']}"
@@ -72,6 +83,10 @@ def service_summary
7283
@crit_service.join(', ')
7384
end
7485

86+
def validate_presence_of(service)
87+
all_service_names.include?(service)
88+
end
89+
7590
def run
7691
check_systemd
7792
critical service_summary unless @crit_service.empty?

0 commit comments

Comments
 (0)