Debian Codegraph @

src/cloud/azure/common/appservice/mode/filesystem.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 cloud::azure::common::appservice::mode::filesystem;
22
23 use base qw(cloud::azure::custom::mode);
24
25 use strict;
26 use warnings;
27
28 sub get_metrics_mapping {
29 my ($self, %options) = @_;
30
31 my $metrics_mapping = {
32 'filesystemusage' => {
33 'output' => 'File System Usage',
34 'label' => 'usage',
35 'nlabel' => 'appservice.filesystem.usage.bytes',
36 'unit' => 'B',
37 'min' => '0',
38 'max' => ''
39 }
40 };
41
42 return $metrics_mapping;
43 }
44
45 sub new {
46 my ($class, %options) = @_;
47 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
48 bless $self, $class;
49
50 $options{options}->add_options(arguments => {
51 'filter-metric:s' => { name => 'filter_metric' },
52 'resource:s' => { name => 'resource' },
53 'resource-group:s' => { name => 'resource_group' }
54 });
55 return $self;
56 }
57
58 sub check_options {
59 my ($self, %options) = @_;
60 $self->SUPER::check_options(%options);
61
62 if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
63 $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource <name> with --resource-group option or --resource <id>.');
64 $self->{output}->option_exit();
65 }
66 my $resource = $self->{option_results}->{resource};
67 my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : '';
68 if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.Web\/sites\/(.*)$/) {
69 $resource_group = $1;
70 $resource = $2;
71 }
72
73 $self->{az_resource} = $resource;
74 $self->{az_resource_group} = $resource_group;
75 $self->{az_resource_type} = 'sites';
76 $self->{az_resource_namespace} = 'Microsoft.Web';
77 $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900;
78 $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT6H';
79 $self->{az_aggregations} = ['Average'];
80 if (defined($self->{option_results}->{aggregation})) {
81 $self->{az_aggregations} = [];
82 foreach my $stat (@{$self->{option_results}->{aggregation}}) {
83 if ($stat ne '') {
84 push @{$self->{az_aggregations}}, ucfirst(lc($stat));
85 }
86 }
87 }
88
89 foreach my $metric (keys %{$self->{metrics_mapping}}) {
90 next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
91 && $metric !~ /$self->{option_results}->{filter_metric}/);
92 push @{$self->{az_metrics}}, $metric;
93 }
94 }
95
96 1;
97
98 __END__
99
100 =head1 MODE
101
102 Check Azure App Service file system usage.
103
104 Example:
105
106 Using resource name:
107
108 perl centreon_plugins.pl --plugin=cloud::azure::common::appservice::plugin --mode=filesystem-usage --custommode=api
109 --resource=<sites_id> --resource-group=<resourcegroup_id> --aggregation='average'
110 --warning-usage='80000' --critical-usage='90000'
111
112 Using resource ID:
113
114 perl centreon_plugins.pl --plugin=cloud::azure::common::appservice::plugin --mode=filesystem-usage --custommode=api
115 --resource='/subscriptions/<subscription_id>/resourceGroups/<resourcegroup_id>/providers/Microsoft.Web/sites/<sites_id>'
116 --aggregation='average' --warning-usage='80000' --critical-usage='90000'
117
118 Default aggregation: 'average' / 'minimum', 'maximum' and 'total' are valid.
119
120 =over 8
121
122 =item B<--resource>
123
124 Set resource name or ID (required).
125
126 =item B<--resource-group>
127
128 Set resource group (required if resource's name is used).
129
130 =item B<--warning-usage>
131
132 File system usage warning threshold.
133
134 =item B<--critical-usage>
135
136 File system usage critical threshold.
137
138 =back
139
140 =cut