break change: iis local refactoring (Fix #2095)
This commit is contained in:
parent
6927c34b4c
commit
0156d4b098
|
@ -20,92 +20,80 @@
|
|||
|
||||
package apps::iis::local::mode::applicationpoolstate;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Win32::OLE;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
my %state_map = (
|
||||
0 => 'starting',
|
||||
1 => 'started',
|
||||
2 => 'stopping',
|
||||
3 => 'stopped',
|
||||
4 => 'unknown',
|
||||
);
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf(
|
||||
'state: %s [auto: %s]',
|
||||
$self->{result_values}->{state},
|
||||
$self->{result_values}->{auto_start}
|
||||
);
|
||||
}
|
||||
|
||||
sub prefix_pool_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Application pool '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'pools', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All application pools are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{pools} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'name' }, { name => 'auto_start' }, { name => 'state' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning" => { name => 'warning', },
|
||||
"critical" => { name => 'critical', },
|
||||
"pools:s" => { name => 'pools', },
|
||||
"auto" => { name => 'auto', },
|
||||
"exclude:s" => { name => 'exclude', },
|
||||
});
|
||||
$self->{pools_rules} = {};
|
||||
$self->{wql_filter} = '';
|
||||
$self->{threshold} = 'CRITICAL';
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'unknown-status:s' => { name => 'unknown_status', default => '' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{auto_start} eq "on" and not %{state} =~ /started|starting/' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{pools}) && !defined($self->{option_results}->{auto})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify at least '--pools' or '--auto' option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{pools})) {
|
||||
my $append = '';
|
||||
foreach my $rule (split /,/, $self->{option_results}->{pools}) {
|
||||
if ($rule !~ /^([^\!=]*)(\!=|=){0,1}(.*){0,1}/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong rule in --pools option: " . $rule);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($1) || $1 eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need pool name for rule: " . $rule);
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $poolname = $1;
|
||||
my $operator = defined($2) && $2 ne '' ? $2 : '!=';
|
||||
my $state = defined($3) && $3 ne '' ? lc($3) : 'started';
|
||||
|
||||
if ($operator !~ /^(=|\!=)$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong operator for rule: " . $rule . ". Should be '=' or '!='.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
if ($state !~ /^(started|starting|stopped|stopping|unknown)$/i) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong state for rule: " . $rule . ". See help for available state.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{service_rules}->{$poolname} = {operator => $operator, state => $state};
|
||||
$self->{wql_filter} .= $append . "Name = '" . $poolname . "'";
|
||||
$append = ' Or ';
|
||||
}
|
||||
|
||||
if ($self->{wql_filter} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify one rule for --pools option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
$self->{threshold} = 'WARNING' if (defined($self->{option_results}->{warning}));
|
||||
$self->{threshold} = 'CRITICAL' if (defined($self->{option_results}->{critical}));
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
|
||||
}
|
||||
|
||||
sub check_auto {
|
||||
my $state_map = {
|
||||
0 => 'starting',
|
||||
1 => 'started',
|
||||
2 => 'stopping',
|
||||
3 => 'stopped',
|
||||
4 => 'unknown'
|
||||
};
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
my $wmi = Win32::OLE->GetObject('winmgmts:root\WebAdministration');
|
||||
if (!defined($wmi)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cant create server object:" . Win32::OLE->LastError());
|
||||
|
@ -113,74 +101,29 @@ sub check_auto {
|
|||
}
|
||||
my $query = "Select Name, AutoStart From ApplicationPool";
|
||||
my $resultset = $wmi->ExecQuery($query);
|
||||
|
||||
$self->{pools} = {};
|
||||
foreach my $obj (in $resultset) {
|
||||
my $name = $obj->{Name};
|
||||
my $state = $obj->GetState();
|
||||
|
||||
# Not an Auto service
|
||||
next if ($obj->{AutoStart} == 0);
|
||||
my $state = $state_map->{ $obj->GetState() };
|
||||
|
||||
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} ne '' && $name =~ /$self->{option_results}->{exclude}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping pool '" . $name . "'");
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping pool '" . $name . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "Pool '" . $name . "' state: " . $state_map{$state});
|
||||
if ($state_map{$state} !~ /^started$/i) {
|
||||
$self->{output}->output_add(severity => $self->{threshold},
|
||||
short_msg => "Service '" . $name . "' is " . $state_map{$state});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $result = {};
|
||||
my $wmi = Win32::OLE->GetObject('winmgmts:root\WebAdministration');
|
||||
if (!defined($wmi)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cant create server object:" . Win32::OLE->LastError());
|
||||
$self->{pools}->{$name} = {
|
||||
name => $name,
|
||||
state => $state,
|
||||
auto_start => $obj->{AutoStart} == 0 ? 'off' : 'on'
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{pools}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'No application pool found');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
my $query = 'Select Name From ApplicationPool Where ' . $self->{wql_filter};
|
||||
my $resultset = $wmi->ExecQuery($query);
|
||||
foreach my $obj (in $resultset) {
|
||||
$result->{$obj->{Name}} = {state => $obj->GetState()};
|
||||
}
|
||||
|
||||
foreach my $name (sort(keys %{$self->{service_rules}})) {
|
||||
if (!defined($result->{$name})) {
|
||||
$self->{output}->output_add(severity => 'UNKNOWN',
|
||||
short_msg => "Pool '" . $name . "' not found");
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{output}->output_add(long_msg => "Pool '" . $name . "' state: " . $state_map{$result->{$name}->{state}});
|
||||
if ($self->{service_rules}->{$name}->{operator} eq '=' &&
|
||||
$state_map{$result->{$name}->{state}} eq $self->{service_rules}->{$name}->{state}) {
|
||||
$self->{output}->output_add(severity => $self->{threshold},
|
||||
short_msg => "Pool '" . $name . "' is " . $state_map{$result->{$name}->{state}});
|
||||
} elsif ($self->{service_rules}->{$name}->{operator} eq '!=' &&
|
||||
$state_map{$result->{$name}->{state}} ne $self->{service_rules}->{$name}->{state}) {
|
||||
$self->{output}->output_add(severity => $self->{threshold},
|
||||
short_msg => "Service '" . $name . "' is " . $state_map{$result->{$name}->{state}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All application pools are ok');
|
||||
if (defined($self->{option_results}->{auto})) {
|
||||
$self->check_auto();
|
||||
} else {
|
||||
$self->check();
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -189,37 +132,29 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check IIS Application Pools State.
|
||||
Check IIS application pools.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
=item B<--filter-name>
|
||||
|
||||
Return warning.
|
||||
Filter application pool name (can be a regexp).
|
||||
|
||||
=item B<--critical>
|
||||
=item B<--unknown-status>
|
||||
|
||||
Return critical.
|
||||
Set unknown threshold for status.
|
||||
Can used special variables like: %{name}, %{state}, %{auto_start}.
|
||||
|
||||
=item B<--pools>
|
||||
=item B<--warning-status>
|
||||
|
||||
Application Pool to monitor.
|
||||
Syntax: [pool_name[[=|!=]state]],...
|
||||
Available states are:
|
||||
- 'started',
|
||||
- 'starting',
|
||||
- 'stopped',
|
||||
- 'stopping'
|
||||
- 'unknown'
|
||||
Set warning threshold for status.
|
||||
Can used special variables like: %{name}, %{state}, %{auto_start}.
|
||||
|
||||
=item B<--auto>
|
||||
=item B<--critical-status>
|
||||
|
||||
Return threshold for auto start pools not starting.
|
||||
|
||||
=item B<--exclude>
|
||||
|
||||
Exclude some pool for --auto option (Can be a regexp).
|
||||
Set critical threshold for status (Default: '%{auto_start} eq "on" and not %{state} =~ /started|starting/').
|
||||
Can used special variables like: %{name}, %{state}, %{auto_start}.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
=cut
|
||||
|
|
|
@ -39,12 +39,12 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"filter-state:s" => { name => 'filter_state' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'name:s' => { name => 'name' },
|
||||
'regexp' => { name => 'use_regexp' },
|
||||
'filter-state:s' => { name => 'filter_state' }
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
return $self;
|
||||
}
|
||||
|
@ -93,13 +93,17 @@ sub run {
|
|||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . '] [' .
|
||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
||||
']');
|
||||
$self->{output}->output_add(long_msg =>
|
||||
"'" . $name . "' .
|
||||
'[AutoStart = " . $self->{result}->{$name}->{AutoStart} . ']' .
|
||||
'[State = ' . $state_map{$self->{result}->{$name}->{State}} . ']'
|
||||
);
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List application pools:');
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'List application pools:'
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -115,10 +119,11 @@ sub disco_show {
|
|||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$self->{output}->add_disco_entry(name => $name,
|
||||
auto_start => $self->{result}->{$name}->{AutoStart},
|
||||
state => $state_map{$self->{result}->{$name}->{State}}
|
||||
);
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $name,
|
||||
auto_start => $self->{result}->{$name}->{AutoStart},
|
||||
state => $state_map{$self->{result}->{$name}->{State}}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,4 +157,4 @@ Available states are:
|
|||
|
||||
=back
|
||||
|
||||
=cut
|
||||
=cut
|
||||
|
|
|
@ -31,7 +31,7 @@ my %state_map = (
|
|||
1 => 'started',
|
||||
2 => 'stopping',
|
||||
3 => 'stopped',
|
||||
4 => 'unknown',
|
||||
4 => 'unknown'
|
||||
);
|
||||
|
||||
sub new {
|
||||
|
@ -39,12 +39,12 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"filter-state:s" => { name => 'filter_state' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'name:s' => { name => 'name' },
|
||||
'regexp' => { name => 'use_regexp' },
|
||||
'filter-state:s' => { name => 'filter_state' }
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
return $self;
|
||||
}
|
||||
|
@ -147,4 +147,4 @@ Available states are: 'started', 'starting', 'stopped', 'stopping', 'unknown'
|
|||
|
||||
=back
|
||||
|
||||
=cut
|
||||
=cut
|
||||
|
|
|
@ -20,208 +20,157 @@
|
|||
|
||||
package apps::iis::local::mode::webservicestatistics;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Win32::OLE;
|
||||
use File::Spec;
|
||||
use centreon::plugins::statefile;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
# 1 means by default
|
||||
my $counters = {
|
||||
TotalAnonymousUsers => { selected => 1, unit => 'users/s'},
|
||||
TotalConnectionAttemptsAllInstances => { selected => 1, unit => 'con/s'},
|
||||
TotalGetRequests => { selected => 1, unit => 'requests/s'},
|
||||
TotalPostRequests => { selected => 1, unit => 'requests/s'},
|
||||
TotalBytesReceived => { selected => 0, unit => 'b/s'},
|
||||
TotalBytesSent => { selected => 0, unit => 'b/s'},
|
||||
TotalFilesReceived => { selected => 0, unit => 'files/s'},
|
||||
TotalFilesSent => { selected => 0, unit => 'files/s'}
|
||||
};
|
||||
sub prefix_site_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Site '" . $options{instance_value}->{name} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'sites', type => 1, cb_prefix_output => 'prefix_site_output', message_multiple => 'All sites are ok' }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{sites} = [
|
||||
{ label => 'connections-attempt', nlabel => 'site.connections.attempt.persecond', set => {
|
||||
key_values => [ { name => 'connections_attempt', per_second => 1 } ],
|
||||
output_template => 'connections attempt: %s/s',
|
||||
perfdatas => [
|
||||
{ template => '%d', unit => '/s', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'users-anonymous', nlabel => 'site.users.anonymous.persecond', display_ok => 0, set => {
|
||||
key_values => [ { name => 'anonymous_users', per_second => 1 } ],
|
||||
output_template => 'anonymous users: %s/s',
|
||||
perfdatas => [
|
||||
{ template => '%d', unit => '/s', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'connections-attempt', nlabel => 'site.connections.attempt.persecond', set => {
|
||||
key_values => [ { name => 'connections_attempt', per_second => 1 } ],
|
||||
output_template => 'connections attempt: %s/s',
|
||||
perfdatas => [
|
||||
{ template => '%d', unit => '/s', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'requests-post', nlabel => 'site.requests.post.persecond', set => {
|
||||
key_values => [ { name => 'requests_post', per_second => 1 } ],
|
||||
output_template => 'requests post: %s/s',
|
||||
perfdatas => [
|
||||
{ template => '%d', unit => '/s', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'requests-get', nlabel => 'site.requests.get.persecond', set => {
|
||||
key_values => [ { name => 'requests_get', per_second => 1 } ],
|
||||
output_template => 'requests get: %s/s',
|
||||
perfdatas => [
|
||||
{ template => '%d', unit => '/s', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'traffic-in', nlabel => 'site.traffic.in.bitspersecond', set => {
|
||||
key_values => [ { name => 'traffic_in', per_second => 1 } ],
|
||||
output_template => 'traffic in: %s %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'traffic-out', nlabel => 'site.traffic.out.bitspersecond', set => {
|
||||
key_values => [ { name => 'traffic_out', per_second => 1 } ],
|
||||
output_template => 'traffic out: %s %s/s',
|
||||
output_change_bytes => 2,
|
||||
perfdatas => [
|
||||
{ template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'files-received', nlabel => 'site.files.received.count', display_ok => 0, set => {
|
||||
key_values => [ { name => 'files_received', diff => 1 } ],
|
||||
output_template => 'files received: %s',
|
||||
perfdatas => [
|
||||
{ template => '%d', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'files-sent', nlabel => 'site.files.sent.count', display_ok => 0, set => {
|
||||
key_values => [ { name => 'files_sent', diff => 1 } ],
|
||||
output_template => 'files sent: %s',
|
||||
perfdatas => [
|
||||
{ template => '%d', min => 0, label_extra_instance => 1 }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
foreach my $name (keys %$counters) {
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"warning-" . $name . ":s" => { name => 'warning_' . $name, },
|
||||
"critical-" . $name . ":s" => { name => 'critical_' . $name, },
|
||||
});
|
||||
}
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"name:s" => { name => 'name', },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"add-counters:s" => { name => 'add_counters', },
|
||||
});
|
||||
$self->{result} = {};
|
||||
$self->{new_datas} = {};
|
||||
$self->{wql_names} = '';
|
||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
|
||||
foreach my $name (keys %$counters) {
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning_' . $name, value => $self->{option_results}->{'warning_' . $name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-$name threshold '" . $self->{option_results}->{'warning_' . $name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical_' . $name, value => $self->{option_results}->{'critical_' . $name})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-$name threshold '" . $self->{option_results}->{'critical_' . $name} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($self->{option_results}->{add_counters})) {
|
||||
foreach my $counter (split /,/, $self->{option_results}->{add_counters}) {
|
||||
next if ($counter eq '');
|
||||
if (!defined($counters->{$counter})) {
|
||||
$self->{output}->add_option_msg(short_msg => "Counter '$counter' unknown.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$counters->{$counter}->{selected} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$self->{wql_names} = 'Name';
|
||||
foreach my $name (keys %$counters) {
|
||||
$self->{wql_names} .= ', ' . $name;
|
||||
}
|
||||
|
||||
$self->{statefile_value}->check_options(%options);
|
||||
}
|
||||
|
||||
sub get_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $wmi = Win32::OLE->GetObject('winmgmts:root\cimv2');
|
||||
if (!defined($wmi)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Cant create server object:" . Win32::OLE->LastError());
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
my $query = 'Select ' . $self->{wql_names} . ' From Win32_PerfRawData_W3SVC_WebService';
|
||||
my $query = 'Select * From Win32_PerfRawData_W3SVC_WebService';
|
||||
my $resultset = $wmi->ExecQuery($query);
|
||||
$self->{sites} = {};
|
||||
foreach my $obj (in $resultset) {
|
||||
my $site_name = $obj->{Name};
|
||||
|
||||
if (defined($self->{option_results}->{name})) {
|
||||
next if (defined($self->{option_results}->{use_regexp}) && $site_name !~ /$self->{option_results}->{name}/);
|
||||
next if (!defined($self->{option_results}->{use_regexp}) && $site_name ne $self->{option_results}->{name});
|
||||
}
|
||||
|
||||
$self->{result}->{$site_name} = {};
|
||||
foreach my $name (keys %$counters) {
|
||||
next if ($counters->{$name}->{selected} == 0);
|
||||
$self->{new_datas}->{$site_name . '_' . $name} = $obj->{$name};
|
||||
$self->{result}->{$site_name}->{$name} = { old_value => undef, current_value => $obj->{$name} };
|
||||
my $name = $obj->{Name};
|
||||
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping site '" . $name . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{sites}->{$name} = {
|
||||
name => $name,
|
||||
anonymous_users => $obj->{TotalAnonymousUsers},
|
||||
connections_attempt => $obj->{TotalConnectionAttemptsAllInstances},
|
||||
requests_get => $obj->{TotalGetRequests},
|
||||
requests_post => $obj->{TotalPostRequests},
|
||||
traffic_in => $obj->{TotalBytesReceived},
|
||||
traffic_out => $obj->{TotalBytesSent},
|
||||
files_received => $obj->{TotalFilesReceived},
|
||||
files_sent => $obj->{TotalFilesSent}
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{result}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No site found");
|
||||
|
||||
if (scalar(keys %{$self->{sites}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'No site found');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{statefile_value}->read(statefile => "iis_" . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
|
||||
$self->{new_datas}->{last_timestamp} = time();
|
||||
my $old_timestamp;
|
||||
$old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
|
||||
|
||||
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'All sites are ok');
|
||||
}
|
||||
|
||||
foreach my $site_name (keys %{$self->{result}}) {
|
||||
|
||||
next if (!defined($old_timestamp));
|
||||
|
||||
my $time_delta = $self->{new_datas}->{last_timestamp} - $old_timestamp;
|
||||
if ($time_delta <= 0) {
|
||||
# At least one second. two fast calls ;)
|
||||
$time_delta = 1;
|
||||
}
|
||||
|
||||
my $exits = [];
|
||||
my $str_display = "Site '" . $site_name . "': ";
|
||||
my $str_display_append = '';
|
||||
|
||||
foreach my $name (keys %$counters) {
|
||||
next if ($counters->{$name}->{selected} == 0);
|
||||
$self->{result}->{$site_name}->{$name}->{old_value} = $self->{statefile_value}->get(name => $site_name . '_' . $name);
|
||||
if (!defined($self->{result}->{$site_name}->{$name}->{old_value})) {
|
||||
next;
|
||||
}
|
||||
if ($self->{result}->{$site_name}->{$name}->{current_value} < $self->{result}->{$site_name}->{$name}->{old_value}) {
|
||||
# We set 0. Has reboot.
|
||||
$self->{result}->{$site_name}->{$name}->{old_value} = 0;
|
||||
}
|
||||
|
||||
my $value_per_seconds = ($self->{result}->{$site_name}->{$name}->{current_value} - $self->{result}->{$site_name}->{$name}->{old_value}) / $time_delta;
|
||||
push @$exits, $self->{perfdata}->threshold_check(value => $value_per_seconds,
|
||||
threshold => [ { label => 'critical_' . $name, exit_litteral => 'critical' },
|
||||
{ label => 'warning_' . $name, exit_litteral => 'warning' } ]);
|
||||
my $value_display;
|
||||
if (defined($counters->{$name}->{unit}) && $counters->{$name}->{unit} eq 'b/s') {
|
||||
my ($trans_value, $trans_unit) = $self->{perfdata}->change_bytes(value => $value_per_seconds, network => 1);
|
||||
$value_display = $trans_value . ' ' . $trans_unit;
|
||||
} else {
|
||||
$value_display = sprintf("%.2f", $value_per_seconds);
|
||||
}
|
||||
$str_display .= $str_display_append . sprintf("%s %s /sec", $name, $value_display);
|
||||
$str_display_append = ', ';
|
||||
|
||||
my $extra_label;
|
||||
$extra_label = '_' . $site_name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
|
||||
$self->{output}->perfdata_add(
|
||||
label => $name, unit => $counters->{$name}->{unit},
|
||||
instances => $extra_label,
|
||||
value => sprintf("%.2f", $value_per_seconds),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_' . $name),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_' . $name),
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
|
||||
# No values computing.
|
||||
next if (scalar(@$exits) == 0);
|
||||
|
||||
my $exit = $self->{output}->get_most_critical(status => $exits);
|
||||
$self->{output}->output_add(long_msg => $str_display);
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $str_display);
|
||||
}
|
||||
}
|
||||
|
||||
$self->{statefile_value}->write(data => $self->{new_datas});
|
||||
if (!defined($old_timestamp)) {
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Buffer creation...");
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->get_counters();
|
||||
$self->check();
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{cache_name} = 'iis_' . $self->{mode} . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -230,34 +179,20 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check IIS Site Statistics.
|
||||
Available counters are: TotalAnonymousUsers, TotalConnectionAttemptsAllInstances, TotalGetRequests, TotalPostRequests, TotalBytesReceived, TotalBytesSent, TotalFilesReceived, TotalFilesSent
|
||||
|
||||
Counters are per seconds.
|
||||
Check IIS site statistics.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-COUNTER>
|
||||
=item B<--filter-name>
|
||||
|
||||
Warning threshold for counters.
|
||||
Filter site name (can be a regexp).
|
||||
|
||||
=item B<--critical-COUNTER>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Critical threshold for counters.
|
||||
|
||||
=item B<--name>
|
||||
|
||||
Set the site name.
|
||||
|
||||
=item B<--regexp>
|
||||
|
||||
Allows to use regexp to filter site name (with option --name).
|
||||
|
||||
=item B<--add-counters>
|
||||
|
||||
Can add the following counters (not by default): TotalBytesReceived, TotalBytesSent, TotalFilesReceived, TotalFilesSent
|
||||
|
||||
Counters are separated by comas.
|
||||
Thresholds.
|
||||
Can be: 'connections-attempt', 'users-anonymous',
|
||||
'requests-post', 'requests-get', 'traffic-in', 'traffic-out'.
|
||||
'files-received', 'files-sent'.
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate',
|
||||
'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools',
|
||||
'list-sites' => 'apps::iis::local::mode::listsites',
|
||||
'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics',
|
||||
);
|
||||
$self->{modes} = {
|
||||
'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate',
|
||||
'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools',
|
||||
'list-sites' => 'apps::iis::local::mode::listsites',
|
||||
'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics',
|
||||
};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue