mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-01 02:44:39 +02:00
break change: iis local refactoring (Fix #2095)
This commit is contained in:
parent
6927c34b4c
commit
0156d4b098
@ -20,90 +20,78 @@
|
|||||||
|
|
||||||
package apps::iis::local::mode::applicationpoolstate;
|
package apps::iis::local::mode::applicationpoolstate;
|
||||||
|
|
||||||
use base qw(centreon::plugins::mode);
|
use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Win32::OLE;
|
use Win32::OLE;
|
||||||
|
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||||
|
|
||||||
my %state_map = (
|
sub custom_status_output {
|
||||||
0 => 'starting',
|
my ($self, %options) = @_;
|
||||||
1 => 'started',
|
|
||||||
2 => 'stopping',
|
return sprintf(
|
||||||
3 => 'stopped',
|
'state: %s [auto: %s]',
|
||||||
4 => 'unknown',
|
$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 {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
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 => {
|
||||||
{
|
'filter-name:s' => { name => 'filter_name' },
|
||||||
"warning" => { name => 'warning', },
|
'unknown-status:s' => { name => 'unknown_status', default => '' },
|
||||||
"critical" => { name => 'critical', },
|
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||||
"pools:s" => { name => 'pools', },
|
'critical-status:s' => { name => 'critical_status', default => '%{auto_start} eq "on" and not %{state} =~ /started|starting/' }
|
||||||
"auto" => { name => 'auto', },
|
|
||||||
"exclude:s" => { name => 'exclude', },
|
|
||||||
});
|
});
|
||||||
$self->{pools_rules} = {};
|
|
||||||
$self->{wql_filter} = '';
|
|
||||||
$self->{threshold} = 'CRITICAL';
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_options {
|
sub check_options {
|
||||||
my ($self, %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->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
|
||||||
$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 $state_map = {
|
||||||
my $append = '';
|
0 => 'starting',
|
||||||
foreach my $rule (split /,/, $self->{option_results}->{pools}) {
|
1 => 'started',
|
||||||
if ($rule !~ /^([^\!=]*)(\!=|=){0,1}(.*){0,1}/) {
|
2 => 'stopping',
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong rule in --pools option: " . $rule);
|
3 => 'stopped',
|
||||||
$self->{output}->option_exit();
|
4 => 'unknown'
|
||||||
}
|
};
|
||||||
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;
|
sub manage_selection {
|
||||||
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}));
|
|
||||||
}
|
|
||||||
|
|
||||||
sub check_auto {
|
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $wmi = Win32::OLE->GetObject('winmgmts:root\WebAdministration');
|
my $wmi = Win32::OLE->GetObject('winmgmts:root\WebAdministration');
|
||||||
@ -113,74 +101,29 @@ sub check_auto {
|
|||||||
}
|
}
|
||||||
my $query = "Select Name, AutoStart From ApplicationPool";
|
my $query = "Select Name, AutoStart From ApplicationPool";
|
||||||
my $resultset = $wmi->ExecQuery($query);
|
my $resultset = $wmi->ExecQuery($query);
|
||||||
|
|
||||||
|
$self->{pools} = {};
|
||||||
foreach my $obj (in $resultset) {
|
foreach my $obj (in $resultset) {
|
||||||
my $name = $obj->{Name};
|
my $name = $obj->{Name};
|
||||||
my $state = $obj->GetState();
|
my $state = $state_map->{ $obj->GetState() };
|
||||||
|
|
||||||
# Not an Auto service
|
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||||
next if ($obj->{AutoStart} == 0);
|
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||||
|
$self->{output}->output_add(long_msg => "skipping pool '" . $name . "': no matching filter.", debug => 1);
|
||||||
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 . "'");
|
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Pool '" . $name . "' state: " . $state_map{$state});
|
$self->{pools}->{$name} = {
|
||||||
if ($state_map{$state} !~ /^started$/i) {
|
name => $name,
|
||||||
$self->{output}->output_add(severity => $self->{threshold},
|
state => $state,
|
||||||
short_msg => "Service '" . $name . "' is " . $state_map{$state});
|
auto_start => $obj->{AutoStart} == 0 ? 'off' : 'on'
|
||||||
}
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check {
|
if (scalar(keys %{$self->{pools}}) <= 0) {
|
||||||
my ($self, %options) = @_;
|
$self->{output}->add_option_msg(short_msg => 'No application pool found');
|
||||||
|
|
||||||
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->{output}->option_exit();
|
$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;
|
1;
|
||||||
@ -189,36 +132,28 @@ __END__
|
|||||||
|
|
||||||
=head1 MODE
|
=head1 MODE
|
||||||
|
|
||||||
Check IIS Application Pools State.
|
Check IIS application pools.
|
||||||
|
|
||||||
=over 8
|
=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.
|
Set warning threshold for status.
|
||||||
Syntax: [pool_name[[=|!=]state]],...
|
Can used special variables like: %{name}, %{state}, %{auto_start}.
|
||||||
Available states are:
|
|
||||||
- 'started',
|
|
||||||
- 'starting',
|
|
||||||
- 'stopped',
|
|
||||||
- 'stopping'
|
|
||||||
- 'unknown'
|
|
||||||
|
|
||||||
=item B<--auto>
|
=item B<--critical-status>
|
||||||
|
|
||||||
Return threshold for auto start pools not starting.
|
Set critical threshold for status (Default: '%{auto_start} eq "on" and not %{state} =~ /started|starting/').
|
||||||
|
Can used special variables like: %{name}, %{state}, %{auto_start}.
|
||||||
=item B<--exclude>
|
|
||||||
|
|
||||||
Exclude some pool for --auto option (Can be a regexp).
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
@ -39,12 +39,12 @@ 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' },
|
'filter-state:s' => { name => 'filter_state' }
|
||||||
"filter-state:s" => { name => 'filter_state' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->{result} = {};
|
$self->{result} = {};
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -93,13 +93,17 @@ sub run {
|
|||||||
|
|
||||||
$self->manage_selection();
|
$self->manage_selection();
|
||||||
foreach my $name (sort(keys %{$self->{result}})) {
|
foreach my $name (sort(keys %{$self->{result}})) {
|
||||||
$self->{output}->output_add(long_msg => "'" . $name . "' [AutoStart = " . $self->{result}->{$name}->{AutoStart} . '] [' .
|
$self->{output}->output_add(long_msg =>
|
||||||
'State = ' . $state_map{$self->{result}->{$name}->{State}} .
|
"'" . $name . "' .
|
||||||
']');
|
'[AutoStart = " . $self->{result}->{$name}->{AutoStart} . ']' .
|
||||||
|
'[State = ' . $state_map{$self->{result}->{$name}->{State}} . ']'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(
|
||||||
short_msg => 'List application pools:');
|
severity => 'OK',
|
||||||
|
short_msg => 'List application pools:'
|
||||||
|
);
|
||||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
@ -115,7 +119,8 @@ 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(
|
||||||
|
name => $name,
|
||||||
auto_start => $self->{result}->{$name}->{AutoStart},
|
auto_start => $self->{result}->{$name}->{AutoStart},
|
||||||
state => $state_map{$self->{result}->{$name}->{State}}
|
state => $state_map{$self->{result}->{$name}->{State}}
|
||||||
);
|
);
|
||||||
|
@ -31,7 +31,7 @@ my %state_map = (
|
|||||||
1 => 'started',
|
1 => 'started',
|
||||||
2 => 'stopping',
|
2 => 'stopping',
|
||||||
3 => 'stopped',
|
3 => 'stopped',
|
||||||
4 => 'unknown',
|
4 => 'unknown'
|
||||||
);
|
);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
@ -39,12 +39,12 @@ 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' },
|
'filter-state:s' => { name => 'filter_state' }
|
||||||
"filter-state:s" => { name => 'filter_state' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->{result} = {};
|
$self->{result} = {};
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -20,87 +20,117 @@
|
|||||||
|
|
||||||
package apps::iis::local::mode::webservicestatistics;
|
package apps::iis::local::mode::webservicestatistics;
|
||||||
|
|
||||||
use base qw(centreon::plugins::mode);
|
use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Win32::OLE;
|
use Win32::OLE;
|
||||||
use File::Spec;
|
|
||||||
use centreon::plugins::statefile;
|
|
||||||
use Digest::MD5 qw(md5_hex);
|
use Digest::MD5 qw(md5_hex);
|
||||||
|
|
||||||
# 1 means by default
|
sub prefix_site_output {
|
||||||
my $counters = {
|
my ($self, %options) = @_;
|
||||||
TotalAnonymousUsers => { selected => 1, unit => 'users/s'},
|
|
||||||
TotalConnectionAttemptsAllInstances => { selected => 1, unit => 'con/s'},
|
return "Site '" . $options{instance_value}->{name} . "' ";
|
||||||
TotalGetRequests => { selected => 1, unit => 'requests/s'},
|
}
|
||||||
TotalPostRequests => { selected => 1, unit => 'requests/s'},
|
|
||||||
TotalBytesReceived => { selected => 0, unit => 'b/s'},
|
sub set_counters {
|
||||||
TotalBytesSent => { selected => 0, unit => 'b/s'},
|
my ($self, %options) = @_;
|
||||||
TotalFilesReceived => { selected => 0, unit => 'files/s'},
|
|
||||||
TotalFilesSent => { selected => 0, unit => 'files/s'}
|
$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 {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
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;
|
bless $self, $class;
|
||||||
|
|
||||||
foreach my $name (keys %$counters) {
|
$options{options}->add_options(arguments => {
|
||||||
$options{options}->add_options(arguments =>
|
'filter-name:s' => { name => 'filter_name' }
|
||||||
{
|
|
||||||
"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);
|
|
||||||
return $self;
|
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 ($self, %options) = @_;
|
||||||
|
|
||||||
my $wmi = Win32::OLE->GetObject('winmgmts:root\cimv2');
|
my $wmi = Win32::OLE->GetObject('winmgmts:root\cimv2');
|
||||||
@ -108,120 +138,39 @@ sub get_counters {
|
|||||||
$self->{output}->add_option_msg(short_msg => "Cant create server object:" . Win32::OLE->LastError());
|
$self->{output}->add_option_msg(short_msg => "Cant create server object:" . Win32::OLE->LastError());
|
||||||
$self->{output}->option_exit();
|
$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);
|
my $resultset = $wmi->ExecQuery($query);
|
||||||
|
$self->{sites} = {};
|
||||||
foreach my $obj (in $resultset) {
|
foreach my $obj (in $resultset) {
|
||||||
my $site_name = $obj->{Name};
|
my $name = $obj->{Name};
|
||||||
|
|
||||||
if (defined($self->{option_results}->{name})) {
|
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||||
next if (defined($self->{option_results}->{use_regexp}) && $site_name !~ /$self->{option_results}->{name}/);
|
$name !~ /$self->{option_results}->{filter_name}/) {
|
||||||
next if (!defined($self->{option_results}->{use_regexp}) && $site_name ne $self->{option_results}->{name});
|
$self->{output}->output_add(long_msg => "skipping site '" . $name . "': no matching filter.", debug => 1);
|
||||||
}
|
|
||||||
|
|
||||||
$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} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scalar(keys %{$self->{result}}) <= 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;
|
next;
|
||||||
}
|
}
|
||||||
if ($self->{result}->{$site_name}->{$name}->{current_value} < $self->{result}->{$site_name}->{$name}->{old_value}) {
|
|
||||||
# We set 0. Has reboot.
|
$self->{sites}->{$name} = {
|
||||||
$self->{result}->{$site_name}->{$name}->{old_value} = 0;
|
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}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $value_per_seconds = ($self->{result}->{$site_name}->{$name}->{current_value} - $self->{result}->{$site_name}->{$name}->{old_value}) / $time_delta;
|
if (scalar(keys %{$self->{sites}}) <= 0) {
|
||||||
push @$exits, $self->{perfdata}->threshold_check(value => $value_per_seconds,
|
$self->{output}->add_option_msg(short_msg => 'No site found');
|
||||||
threshold => [ { label => 'critical_' . $name, exit_litteral => 'critical' },
|
$self->{output}->option_exit();
|
||||||
{ 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.
|
$self->{cache_name} = 'iis_' . $self->{mode} . '_' .
|
||||||
next if (scalar(@$exits) == 0);
|
(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'));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
@ -230,34 +179,20 @@ __END__
|
|||||||
|
|
||||||
=head1 MODE
|
=head1 MODE
|
||||||
|
|
||||||
Check IIS Site Statistics.
|
Check IIS site statistics.
|
||||||
Available counters are: TotalAnonymousUsers, TotalConnectionAttemptsAllInstances, TotalGetRequests, TotalPostRequests, TotalBytesReceived, TotalBytesSent, TotalFilesReceived, TotalFilesSent
|
|
||||||
|
|
||||||
Counters are per seconds.
|
|
||||||
|
|
||||||
=over 8
|
=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.
|
Thresholds.
|
||||||
|
Can be: 'connections-attempt', 'users-anonymous',
|
||||||
=item B<--name>
|
'requests-post', 'requests-get', 'traffic-in', 'traffic-out'.
|
||||||
|
'files-received', 'files-sent'.
|
||||||
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.
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
@ -30,12 +30,12 @@ sub new {
|
|||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{version} = '0.1';
|
$self->{version} = '0.1';
|
||||||
%{$self->{modes}} = (
|
$self->{modes} = {
|
||||||
'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate',
|
'applicationpool-state' => 'apps::iis::local::mode::applicationpoolstate',
|
||||||
'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools',
|
'list-applicationpools' => 'apps::iis::local::mode::listapplicationpools',
|
||||||
'list-sites' => 'apps::iis::local::mode::listsites',
|
'list-sites' => 'apps::iis::local::mode::listsites',
|
||||||
'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics',
|
'webservice-statistics' => 'apps::iis::local::mode::webservicestatistics',
|
||||||
);
|
};
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user