Debian Codegraph @

src/apps/microsoft/iis/wsman/mode/applicationpools.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package apps::microsoft::iis::wsman::mode::applicationpools;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'state: %s [auto: %s]',
34 $self->{result_values}->{state},
35 $self->{result_values}->{auto_start}
36 );
37 }
38
39 sub prefix_pool_output {
40 my ($self, %options) = @_;
41
42 return "Application pool '" . $options{instance_value}->{name} . "' ";
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'global', type => 0 },
50 { name => 'pools', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All application pools are ok' }
51 ];
52
53 $self->{maps_counters}->{global} = [
54 { label => 'pools-detected', display_ok => 0, nlabel => 'pools.detected.count', set => {
55 key_values => [ { name => 'detected' } ],
56 output_template => 'application pools detected: %s',
57 perfdatas => [
58 { template => '%s', min => 0 }
59 ]
60 }
61 }
62 ];
63
64 $self->{maps_counters}->{pools} = [
65 { label => 'status', type => 2, critical_default => '%{auto_start} eq "on" and not %{state} =~ /started|starting/', set => {
66 key_values => [ { name => 'name' }, { name => 'auto_start' }, { name => 'state' } ],
67 closure_custom_output => $self->can('custom_status_output'),
68 closure_custom_perfdata => sub { return 0; },
69 closure_custom_threshold_check => \&catalog_status_threshold_ng
70 }
71 }
72 ];
73 }
74
75 sub new {
76 my ($class, %options) = @_;
77 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
78 bless $self, $class;
79
80 $options{options}->add_options(arguments => {
81 'filter-name:s' => { name => 'filter_name' }
82 });
83
84 return $self;
85 }
86
87 my $state_map = {
88 1 => 'started',
89 2 => 'starting',
90 3 => 'stopped',
91 4 => 'stopping'
92 };
93
94 sub manage_selection {
95 my ($self, %options) = @_;
96
97 my $results = $options{wsman}->request(
98 uri => 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/MicrosoftIISv2/*',
99 wql_filter => 'Select Name, AppPoolState, AppPoolAutoStart From IIsApplicationPoolSetting',
100 result_type => 'hash',
101 hash_key => 'Name'
102 );
103
104 $self->{pools} = {};
105 foreach my $name (keys %$results) {
106 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
107 $name !~ /$self->{option_results}->{filter_name}/) {
108 $self->{output}->output_add(long_msg => "skipping pool '" . $name . "': no matching filter.", debug => 1);
109 next;
110 }
111
112 $self->{pools}->{$name} = {
113 name => $name,
114 state => $state_map->{ $results->{$name}->{AppPoolState} },
115 auto_start => $results->{$name}->{AppPoolAutoStart} =~ /^(?:1|true)$/i ? 'on' : 'off'
116 };
117 }
118
119 if (scalar(keys %{$self->{pools}}) <= 0) {
120 $self->{output}->add_option_msg(short_msg => 'No application pool found');
121 $self->{output}->option_exit();
122 }
123 }
124
125 1;
126
127 __END__
128
129 =head1 MODE
130
131 Check IIS application pools.
132
133 =over 8
134
135 =item B<--filter-name>
136
137 Filter application pool name (can be a regexp).
138
139 =item B<--unknown-status>
140
141 Define the conditions to match for the status to be UNKNOWN.
142 You can use the following variables: %{name}, %{state}, %{auto_start}.
143
144 =item B<--warning-status>
145
146 Define the conditions to match for the status to be WARNING.
147 You can use the following variables: %{name}, %{state}, %{auto_start}.
148
149 =item B<--critical-status>
150
151 Define the conditions to match for the status to be CRITICAL (default: '%{auto_start} eq "on" and not %{state} =~ /started|starting/').
152 You can use the following variables: %{name}, %{state}, %{auto_start}.
153
154 =item B<--warning-*> B<--critical-*>
155
156 Thresholds.
157 Can be: 'pools-detected'.
158
159 =back
160
161 =cut