enhance indent

This commit is contained in:
garnier-quentin 2019-10-09 17:55:00 +02:00
parent fda2e8f6cd
commit 7f46a861bc
11 changed files with 202 additions and 178 deletions

View File

@ -31,24 +31,24 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'hostname:s' => { name => 'hostname' },
"hostname:s" => { name => 'hostname' }, 'remote' => { name => 'remote' },
"remote" => { name => 'remote' }, 'ssh-option:s@' => { name => 'ssh_option' },
"ssh-option:s@" => { name => 'ssh_option' }, 'ssh-path:s' => { name => 'ssh_path' },
"ssh-path:s" => { name => 'ssh_path' }, 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 30 },
"timeout:s" => { name => 'timeout', default => 30 }, 'sudo' => { name => 'sudo' },
"sudo" => { name => 'sudo' }, 'command:s' => { name => 'command', default => 'format' },
"command:s" => { name => 'command', default => 'format' }, 'command-path:s' => { name => 'command_path', default => '/usr/sbin' },
"command-path:s" => { name => 'command_path', default => '/usr/sbin' }, 'command-options:s' => { name => 'command_options', default => '2>&1 << EOF
"command-options:s" => { name => 'command_options', default => '2>&1 << EOF
0 0
quit quit
EOF' }, EOF' },
"warning:s" => { name => 'warning', }, "warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', }, "critical:s" => { name => 'critical', },
}); });
return $self; return $self;
} }
@ -57,24 +57,26 @@ sub check_options {
$self->SUPER::init(%options); $self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output}, my $stdout = centreon::plugins::misc::execute(
options => $self->{option_results}, output => $self->{output},
sudo => $self->{option_results}->{sudo}, options => $self->{option_results},
command => $self->{option_results}->{command}, sudo => $self->{option_results}->{sudo},
command_path => $self->{option_results}->{command_path}, command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options}); command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
my $long_msg = $stdout; my $long_msg = $stdout;
$long_msg =~ s/\|/~/mg; $long_msg =~ s/\|/~/mg;
$self->{output}->output_add(long_msg => $long_msg); $self->{output}->output_add(long_msg => $long_msg);
@ -89,7 +91,7 @@ sub run {
} }
my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_errors, my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_errors,
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
if ($num_errors > 0) { if ($num_errors > 0) {
$self->{output}->output_add(severity => $exit_code, $self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("Disks$disks_name are on errors.")); short_msg => sprintf("Disks$disks_name are on errors."));

View File

@ -32,21 +32,21 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'hostname:s' => { name => 'hostname' },
"hostname:s" => { name => 'hostname' }, 'remote' => { name => 'remote' },
"remote" => { name => 'remote' }, 'ssh-option:s@' => { name => 'ssh_option' },
"ssh-option:s@" => { name => 'ssh_option' }, 'ssh-path:s' => { name => 'ssh_path' },
"ssh-path:s" => { name => 'ssh_path' }, 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 30 },
"timeout:s" => { name => 'timeout', default => 30 }, 'sudo' => { name => 'sudo' },
"sudo" => { name => 'sudo' }, 'command:s' => { name => 'command', default => 'kstat' },
"command:s" => { name => 'command', default => 'kstat' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-n sys 2>&1' },
"command-options:s" => { name => 'command_options', default => '-n sys 2>&1' }, 'warning:s' => { name => 'warning' },
"warning:s" => { name => 'warning', }, 'critical:s' => { name => 'critical' },
"critical:s" => { name => 'critical', }, });
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
$self->{hostname} = undef; $self->{hostname} = undef;
return $self; return $self;
@ -75,12 +75,14 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output}, my $stdout = centreon::plugins::misc::execute(
options => $self->{option_results}, output => $self->{output},
sudo => $self->{option_results}->{sudo}, options => $self->{option_results},
command => $self->{option_results}->{command}, sudo => $self->{option_results}->{sudo},
command_path => $self->{option_results}->{command_path}, command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options}); command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
$self->{statefile_cache}->read(statefile => 'cache_solaris_local_' . $self->{hostname} . '_' . $self->{mode}); $self->{statefile_cache}->read(statefile => 'cache_solaris_local_' . $self->{hostname} . '_' . $self->{mode});
my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp'); my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp');
my $datas = {}; my $datas = {};
@ -128,11 +130,13 @@ sub run {
$self->{output}->output_add(severity => $exit_code, $self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("CPU %d %.2f%%", $cpu_number, $cpu_ratio_usetime)); short_msg => sprintf("CPU %d %.2f%%", $cpu_number, $cpu_ratio_usetime));
} }
$self->{output}->perfdata_add(label => 'cpu_' . $cpu_number, unit => '%', $self->{output}->perfdata_add(
value => sprintf("%.2f", $cpu_ratio_usetime), label => 'cpu_' . $cpu_number, unit => '%',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), value => sprintf("%.2f", $cpu_ratio_usetime),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
min => 0, max => 100); critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0, max => 100
);
} }
$self->{statefile_cache}->write(data => $datas); $self->{statefile_cache}->write(data => $datas);

View File

@ -31,18 +31,18 @@ sub new {
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( %{$self->{modes}} = (
'prtdiag' => 'os::solaris::local::mode::prtdiag', 'prtdiag' => 'os::solaris::local::mode::prtdiag',
'cpu' => 'os::solaris::local::mode::cpu', 'cpu' => 'os::solaris::local::mode::cpu',
'fc-connected' => 'os::solaris::local::mode::fcconnected', 'fc-connected' => 'os::solaris::local::mode::fcconnected',
'hardware-fmadm' => 'os::solaris::local::mode::fmadm', 'hardware-fmadm' => 'os::solaris::local::mode::fmadm',
'analyze-disks' => 'os::solaris::local::mode::analyzedisks', 'analyze-disks' => 'os::solaris::local::mode::analyzedisks',
'vx-disks' => 'os::solaris::local::mode::vxdisks', 'vx-disks' => 'os::solaris::local::mode::vxdisks',
'svm-disks' => 'os::solaris::local::mode::svmdisks', 'svm-disks' => 'os::solaris::local::mode::svmdisks',
'hwraidctl-status' => 'os::solaris::local::mode::hwraidctl', 'hwraidctl-status' => 'os::solaris::local::mode::hwraidctl',
'hwsas2ircu-status' => 'os::solaris::local::mode::hwsas2ircu', 'hwsas2ircu-status' => 'os::solaris::local::mode::hwsas2ircu',
'lom-v120-status' => 'os::solaris::local::mode::lomv120', 'lom-v120-status' => 'os::solaris::local::mode::lomv120',
'lom-v1280-status' => 'os::solaris::local::mode::lomv1280', 'lom-v1280-status' => 'os::solaris::local::mode::lomv1280',
); );
return $self; return $self;
} }

View File

@ -32,16 +32,16 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning-time:s' => { name => 'warning_time' },
"warning-time:s" => { name => 'warning_time' }, 'critical-time:s' => { name => 'critical_time' },
"critical-time:s" => { name => 'critical_time' }, 'timeout:s' => { name => 'timeout', default => 30 },
"timeout:s" => { name => 'timeout', default => 30 }, 'command:s' => { name => 'command' },
"command:s" => { name => 'command' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options' },
"command-options:s" => { name => 'command_options' }, 'manage-returns:s' => { name => 'manage_returns', default => '' },
"manage-returns:s" => { name => 'manage_returns', default => '' }, });
});
$self->{manage_returns} = {}; $self->{manage_returns} = {};
return $self; return $self;
} }
@ -83,12 +83,14 @@ sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $timing0 = [gettimeofday]; my $timing0 = [gettimeofday];
my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, my ($stdout, $exit_code) = centreon::plugins::misc::execute(
options => $self->{option_results}, output => $self->{output},
command => $self->{option_results}->{command}, options => $self->{option_results},
command_path => $self->{option_results}->{command_path}, command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options}, command_path => $self->{option_results}->{command_path},
no_quit => 1); command_options => $self->{option_results}->{command_options},
no_quit => 1
);
my $timeelapsed = tv_interval($timing0, [gettimeofday]); my $timeelapsed = tv_interval($timing0, [gettimeofday]);
my $long_msg = $stdout; my $long_msg = $stdout;
@ -107,8 +109,10 @@ sub run {
} }
if (defined($exit_code)) { if (defined($exit_code)) {
$self->{output}->perfdata_add(label => "code", $self->{output}->perfdata_add(
value => $exit_code); label => 'code',
value => $exit_code
);
} }
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
@ -118,11 +122,13 @@ sub run {
short_msg => sprintf("Response time %.3fs", $timeelapsed)); short_msg => sprintf("Response time %.3fs", $timeelapsed));
} }
$self->{output}->perfdata_add(label => 'time', unit => 's', $self->{output}->perfdata_add(
value => sprintf('%.3f', $timeelapsed), label => 'time', unit => 's',
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_time'), value => sprintf('%.3f', $timeelapsed),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_time'), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_time'),
min => 0); critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_time'),
min => 0
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();

View File

@ -32,16 +32,15 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'no-ps' => { name => 'no_ps', },
'timeout:s' => { name => 'timeout', default => 50 },
'command:s' => { name => 'command', default => 'powershell.exe' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
'ps-exec-only' => { name => 'ps_exec_only', }
});
"no-ps" => { name => 'no_ps', },
"timeout:s" => { name => 'timeout', default => 50 },
"command:s" => { name => 'command', default => 'powershell.exe' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"ps-exec-only" => { name => 'ps_exec_only', }
});
return $self; return $self;
} }
@ -57,11 +56,13 @@ sub run {
$self->{option_results}->{command_options} .= " " . $ps; $self->{option_results}->{command_options} .= " " . $ps;
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, my ($stdout) = centreon::plugins::misc::windows_execute(
timeout => $self->{option_results}->{timeout}, output => $self->{output},
command => $self->{option_results}->{command}, timeout => $self->{option_results}->{timeout},
command_path => $self->{option_results}->{command_path}, command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options}); command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
if (defined($self->{option_results}->{ps_exec_only})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(severity => 'OK',
short_msg => $stdout); short_msg => $stdout);
@ -87,11 +88,13 @@ sub disco_show {
my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps}); my $ps = centreon::common::powershell::windows::liststorages::get_powershell(no_ps => $self->{option_results}->{no_ps});
$self->{option_results}->{command_options} .= " " . $ps; $self->{option_results}->{command_options} .= " " . $ps;
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output}, my ($stdout) = centreon::plugins::misc::windows_execute(
timeout => $self->{option_results}->{timeout}, output => $self->{output},
command => $self->{option_results}->{command}, timeout => $self->{option_results}->{timeout},
command_path => $self->{option_results}->{command_path}, command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options}); command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
centreon::common::powershell::windows::liststorages::disco_show($self, stdout => $stdout); centreon::common::powershell::windows::liststorages::disco_show($self, stdout => $stdout);
} }

View File

@ -37,11 +37,11 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'ntp-hostname:s' => { name => 'ntp_hostname' }, 'ntp-hostname:s' => { name => 'ntp_hostname' },
'ntp-port:s' => { name => 'ntp_port', default => 123 }, 'ntp-port:s' => { name => 'ntp_port', default => 123 },
'warning:s' => { name => 'warning' }, 'warning:s' => { name => 'warning' },
'critical:s' => { name => 'critical' }, 'critical:s' => { name => 'critical' },
'timeout:s' => { name => 'timeout', default => 30 }, 'timeout:s' => { name => 'timeout', default => 30 },
}); });
return $self; return $self;

View File

@ -31,13 +31,15 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf('Reboot Pending: %s [Windows Update: %s][Component Based Servicing: %s][SCCM Client: %s][File Rename Operations: %s][Computer Name Change: %s]', my $msg = sprintf(
$self->{result_values}->{RebootPending}, 'Reboot Pending: %s [Windows Update: %s][Component Based Servicing: %s][SCCM Client: %s][File Rename Operations: %s][Computer Name Change: %s]',
$self->{result_values}->{WindowsUpdate}, $self->{result_values}->{RebootPending},
$self->{result_values}->{CBServicing}, $self->{result_values}->{WindowsUpdate},
$self->{result_values}->{CCMClientSDK}, $self->{result_values}->{CBServicing},
$self->{result_values}->{PendFileRename}, $self->{result_values}->{CCMClientSDK},
$self->{result_values}->{PendComputerRename}); $self->{result_values}->{PendFileRename},
$self->{result_values}->{PendComputerRename}
);
return $msg; return $msg;
} }
@ -77,17 +79,17 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'timeout:s' => { name => 'timeout', default => 50 },
"timeout:s" => { name => 'timeout', default => 50 }, 'command:s' => { name => 'command', default => 'powershell.exe' },
"command:s" => { name => 'command', default => 'powershell.exe' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, 'no-ps' => { name => 'no_ps' },
"no-ps" => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' },
"ps-exec-only" => { name => 'ps_exec_only' }, 'warning-status:s' => { name => 'warning_status', default => '%{RebootPending} =~ /true/i' },
"warning-status:s" => { name => 'warning_status', default => '%{RebootPending} =~ /true/i' }, 'critical-status:s' => { name => 'critical_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' }, });
});
return $self; return $self;
} }
@ -105,11 +107,13 @@ sub manage_selection {
no_ps => $self->{option_results}->{no_ps}); no_ps => $self->{option_results}->{no_ps});
$self->{option_results}->{command_options} .= " " . $ps; $self->{option_results}->{command_options} .= " " . $ps;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, my ($stdout) = centreon::plugins::misc::execute(
options => $self->{option_results}, output => $self->{output},
command => $self->{option_results}->{command}, options => $self->{option_results},
command_path => $self->{option_results}->{command_path}, command => $self->{option_results}->{command},
command_options => $self->{option_results}->{command_options}); command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
if (defined($self->{option_results}->{ps_exec_only})) { if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(severity => 'OK',
short_msg => $stdout); short_msg => $stdout);

View File

@ -31,12 +31,12 @@ sub new {
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( %{$self->{modes}} = (
'cmd-return' => 'os::windows::local::mode::cmdreturn', 'cmd-return' => 'os::windows::local::mode::cmdreturn',
'pending-reboot' => 'os::windows::local::mode::pendingreboot', 'list-storages' => 'os::windows::local::mode::liststorages',
'sessions' => 'os::windows::local::mode::sessions', 'pending-reboot' => 'os::windows::local::mode::pendingreboot',
'time' => 'os::windows::local::mode::ntp', 'sessions' => 'os::windows::local::mode::sessions',
'list-storages' => 'os::windows::local::mode::liststorages', 'time' => 'os::windows::local::mode::ntp',
); );
return $self; return $self;
} }

View File

@ -30,11 +30,10 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'name:s' => { name => 'name' },
"name:s" => { name => 'name' }, 'regexp' => { name => 'use_regexp' },
"regexp" => { name => 'use_regexp' }, });
});
return $self; return $self;
} }
@ -47,10 +46,12 @@ sub check_options {
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result} = $self->{wsman}->request(uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', $self->{result} = $self->{wsman}->request(
wql_filter => 'Select Name, DisplayName, StartMode, State From Win32_Service', uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*',
result_type => 'hash', wql_filter => 'Select Name, DisplayName, StartMode, State From Win32_Service',
hash_key => 'Name'); result_type => 'hash',
hash_key => 'Name'
);
foreach my $name (sort(keys %{$self->{result}})) { foreach my $name (sort(keys %{$self->{result}})) {
# Get all without a name # Get all without a name
next if (!defined($self->{option_results}->{name})); next if (!defined($self->{option_results}->{name}));
@ -95,11 +96,12 @@ sub disco_show {
$self->manage_selection(); $self->manage_selection();
foreach my $name (sort(keys %{$self->{result}})) { foreach my $name (sort(keys %{$self->{result}})) {
$self->{output}->add_disco_entry(name => $name, $self->{output}->add_disco_entry(
display_name => $self->{output}->to_utf8($self->{result}->{$name}->{DisplayName}), name => $name,
start_mode => $self->{result}->{$name}->{StartMode}, display_name => $self->{output}->to_utf8($self->{result}->{$name}->{DisplayName}),
state => $self->{result}->{$name}->{State} start_mode => $self->{result}->{$name}->{StartMode},
); state => $self->{result}->{$name}->{State}
);
} }
} }

View File

@ -30,14 +30,14 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning' => { name => 'warning' },
"warning" => { name => 'warning', }, 'critical' => { name => 'critical' },
"critical" => { name => 'critical', }, 'services:s' => { name => 'services' },
"services:s" => { name => 'services', }, 'auto' => { name => 'auto' },
"auto" => { name => 'auto', }, 'exclude:s' => { name => 'exclude' },
"exclude:s" => { name => 'exclude', }, });
});
$self->{service_rules} = {}; $self->{service_rules} = {};
$self->{wql_filter} = ''; $self->{wql_filter} = '';
$self->{threshold} = 'CRITICAL'; $self->{threshold} = 'CRITICAL';
@ -97,10 +97,12 @@ sub check_options {
sub check_auto { sub check_auto {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result} = $self->{wsman}->request(uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', $self->{result} = $self->{wsman}->request(
wql_filter => "Select Name, State From Win32_Service Where StartMode = 'Auto'", uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*',
result_type => 'hash', wql_filter => "Select Name, State From Win32_Service Where StartMode = 'Auto'",
hash_key => 'Name'); result_type => 'hash',
hash_key => 'Name'
);
foreach my $name (sort(keys %{$self->{result}})) { foreach my $name (sort(keys %{$self->{result}})) {
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} ne '' && $self->{result}->{$name}->{Name} =~ /$self->{option_results}->{exclude}/) { if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} ne '' && $self->{result}->{$name}->{Name} =~ /$self->{option_results}->{exclude}/) {
$self->{output}->output_add(long_msg => "Skipping Service '" . $self->{result}->{$name}->{Name} . "'"); $self->{output}->output_add(long_msg => "Skipping Service '" . $self->{result}->{$name}->{Name} . "'");
@ -118,10 +120,12 @@ sub check_auto {
sub check { sub check {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result} = $self->{wsman}->request(uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*', $self->{result} = $self->{wsman}->request(
wql_filter => 'Select Name, State From Win32_Service Where ' . $self->{wql_filter}, uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/*',
result_type => 'hash', wql_filter => 'Select Name, State From Win32_Service Where ' . $self->{wql_filter},
hash_key => 'Name'); result_type => 'hash',
hash_key => 'Name'
);
foreach my $name (sort(keys %{$self->{service_rules}})) { foreach my $name (sort(keys %{$self->{service_rules}})) {
if (!defined($self->{result}->{$name})) { if (!defined($self->{result}->{$name})) {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(severity => 'UNKNOWN',
@ -144,7 +148,6 @@ sub check {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
# $options{wsman} = wsman object
$self->{wsman} = $options{wsman}; $self->{wsman} = $options{wsman};
$self->{output}->output_add(severity => 'OK', $self->{output}->output_add(severity => 'OK',

View File

@ -31,9 +31,9 @@ sub new {
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( %{$self->{modes}} = (
'list-services' => 'os::windows::wsman::mode::listservices', 'list-services' => 'os::windows::wsman::mode::listservices',
'service' => 'os::windows::wsman::mode::service', 'service' => 'os::windows::wsman::mode::service',
); );
return $self; return $self;
} }