From 1a3f490bdb76ad168b20d8813b9fa148baaa5594 Mon Sep 17 00:00:00 2001 From: Graham Knop <haarg@haarg.org> Date: Tue, 22 Nov 2011 18:12:14 -0500 Subject: [PATCH] allow pattern to be specified on SmfDisabled monitor --- lib/Core/SmfDisabled.pm | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/Core/SmfDisabled.pm b/lib/Core/SmfDisabled.pm index ca1bd5d..ef1ea65 100644 --- a/lib/Core/SmfDisabled.pm +++ b/lib/Core/SmfDisabled.pm @@ -66,16 +66,27 @@ sub handler { my $config = $self->{config}; # All configuration is in here my $svcs_path = $config->{svcs_path} || 'svcs'; + my $pattern = $config->{pattern} || '.*'; + $pattern = qr/$pattern/; - my $output = run_command("$svcs_path"); - my @disabled_services = map((split(/\s+/, $_))[2], - grep(/^disabled/, split(/\n/, $output))); - - - return { - "count" => [scalar(@disabled_services), "i"], - "services" => [join(" ", @disabled_services), "s"] + my $output = { + count => 0, }; -}; + my $svcs_output = run_command("$svcs_path -a"); + my @lines = grep { $_ ne '' } split /\n/, $svcs_output; + for my $line (@lines) { + my ($state, $start, $name) = split /\s+/, $line, 3; + if ($name =~ $pattern) { + if ($state eq 'disabled') { + $output->{count}++; + $output->{$name} = 1; + } + else { + $output->{$name} = 0; + } + } + } + return $output; +} 1; -- GitLab