Debian Codegraph @

src/centreon/common/microsoft/skype/mssql/mode/poorcalls.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 centreon::common::microsoft::skype::mssql::mode::poorcalls;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'global', type => 0 },
33 { name => 'uri', type => 1, cb_prefix_output => 'prefix_uri_output', message_multiple => 'All users are ok' },
34
35 ];
36
37 $self->{maps_counters}->{global} = [
38 { label => 'global', set => {
39 key_values => [ { name => 'count' } ],
40 output_template => 'Poor Calls: %d',
41 perfdatas => [
42 { label => 'poor_calls', value => 'count', template => '%d',
43 unit => 'calls', min => 0 },
44 ],
45 }
46 },
47 ];
48 $self->{maps_counters}->{uri} = [
49 { label => 'user', set => {
50 key_values => [ { name => 'count' }, { name => 'display' } ],
51 output_template => 'poor calls count: %d',
52 }
53 },
54 ];
55 }
56
57 sub new {
58 my ($class, %options) = @_;
59 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
60 bless $self, $class;
61
62 $options{options}->add_options(arguments =>
63 {
64 "lookback:s" => { name => 'lookback', default => '65' }, # not used
65 "timeframe:s" => { name => 'timeframe', default => '900' },
66 "filter-user:s" => { name => 'filter_user' },
67 "filter-counters:s" => { name => 'filter_counters', default => '' },
68 });
69 return $self;
70 }
71
72 sub prefix_uri_output {
73 my ($self, %options) = @_;
74
75 return "User '" . $options{instance_value}->{display} . "' ";
76 }
77
78 sub manage_selection {
79 my ($self, %options) = @_;
80
81 $self->{sql} = $options{sql};
82 $self->{sql}->connect();
83
84 my $query = "SELECT URI, LastPoorCallTime
85 FROM [QoEMetrics].[dbo].[User]
86 WHERE LastPoorCallTime > (DATEADD(SECOND,-" . $self->{option_results}->{timeframe} . ",SYSUTCDATETIME()))
87 AND LastPoorCallTime < SYSUTCDATETIME()";
88
89 $self->{sql}->query(query => $query);
90
91 $self->{global}->{count} = 0;
92
93 while (my $row = $self->{sql}->fetchrow_hashref()) {
94 if (defined($self->{option_results}->{filter_user}) && $self->{option_results}->{filter_user} ne '' &&
95 $row->{URI} !~ /$self->{option_results}->{filter_user}/) {
96 $self->{output}->output_add(long_msg => "Skipping '" . $row->{URI} . "': no matching filter.", debug => 1);
97 next;
98 }
99 $self->{global}->{count}++;
100 $self->{uri}->{$row->{URI}} = { count => 0, display => $row->{URI} } if (!defined($self->{uri}->{$row->{URI}}));
101 $self->{uri}->{$row->{URI}}->{count}++;
102 }
103 }
104
105 1;
106
107 __END__
108
109 =head1 MODE
110
111 Check poor calls from SQL Server (Lync 2013, Skype 2015).
112
113 =over 8
114
115 =item B<--filter-user>
116
117 Filter user name (can be a regexp)
118
119 =item B<--filter-counters>
120
121 Only display some counters (regexp can be used).
122
123 =item B<--timeframe>
124
125 Set the timeframe to query in seconds (default: 900)
126
127 =item B<--warning-global>
128
129 Set warning threshold for number of poor calls.
130
131 =item B<--critical-global>
132
133 Set critical threshold for number of poor calls.
134
135 =back
136
137 =cut