Debian Codegraph @

src/centreon/common/ingrian/snmp/mode/requeststats.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::ingrian::snmp::mode::requeststats;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'rq', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All request statistics are ok' }
34 ];
35
36 $self->{maps_counters}->{rq} = [
37 { label => 'success', set => {
38 key_values => [ { name => 'success', diff => 1 }, { name => 'display' } ],
39 output_template => 'Success : %s',
40 perfdatas => [
41 { label => 'success', value => 'success', template => '%s', min => 0,
42 label_extra_instance => 1, instance_use => 'display' },
43 ],
44 }
45 },
46 { label => 'fail', set => {
47 key_values => [ { name => 'fail', diff => 1 }, { name => 'display' } ],
48 output_template => 'Fail : %s',
49 perfdatas => [
50 { label => 'fail', value => 'fail', template => '%s', min => 0,
51 label_extra_instance => 1, instance_use => 'display' },
52 ],
53 }
54 },
55 ];
56 }
57
58 sub prefix_disk_output {
59 my ($self, %options) = @_;
60
61 return "'" . $options{instance_value}->{display} . "' requests ";
62 }
63
64 sub new {
65 my ($class, %options) = @_;
66 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
67 bless $self, $class;
68
69 $options{options}->add_options(arguments =>
70 {
71 "filter-name:s" => { name => 'filter_name' },
72 });
73
74 return $self;
75 }
76
77 my @map = (
78 { label => 'Total', suffix => 1 },
79 { label => 'KeyGen', suffix => 2 },
80 { label => 'KeyInfo', suffix => 3 },
81 { label => 'KeyDel', suffix => 4 },
82 { label => 'KeyQuery', suffix => 5 },
83 { label => 'KeyImport', suffix => 6 },
84 { label => 'KeyExport', suffix => 7 },
85 { label => 'RandomGen', suffix => 8 },
86 { label => 'Cryptographic', suffix => 9 },
87 { label => 'Authenticate', suffix => 10 },
88 { label => 'KeyModify', suffix => 11 },
89 { label => 'KeyClone', suffix => 12 },
90 { label => 'CertificateExport', suffix => 13 },
91 { label => 'KeyVersionGenerate', suffix => 14 },
92 { label => 'KeyVersionModify', suffix => 15 },
93 { label => 'KeyCertificateExport', suffix => 16 },
94 { label => 'RecordEvent', suffix => 17 },
95 { label => 'PublicKeyExport', suffix => 18 },
96 { label => 'CAExport', suffix => 19 },
97 );
98 my $oid_naeServerStats = '.1.3.6.1.4.1.5595.3.3';
99
100 sub manage_selection {
101 my ($self, %options) = @_;
102
103 $self->{rq} = {};
104 my $snmp_result = $options{snmp}->get_table(oid => $oid_naeServerStats,
105 nothing_quit => 1);
106 foreach (@map) {
107 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
108 $_->{label} !~ /$self->{option_results}->{filter_name}/) {
109 $self->{output}->output_add(long_msg => "skipping '" . $_->{label} . "': no matching filter.", debug => 1);
110 next;
111 }
112
113 $self->{rq}->{$_->{suffix}} = {
114 display => $_->{label},
115 success => $snmp_result->{$oid_naeServerStats . '.' . $_->{suffix} . '.3.0'},
116 fail => $snmp_result->{$oid_naeServerStats . '.' . $_->{suffix} . '.4.0'}
117 };
118 }
119
120 $self->{cache_name} = "ingrian_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
121 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) .
122 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
123 }
124
125 1;
126
127 __END__
128
129 =head1 MODE
130
131 Check request statistics.
132
133 =over 8
134
135 =item B<--filter-name>
136
137 Filter by name (can be a regexp).
138
139 =item B<--warning-*>
140
141 Warning threshold.
142 Can be: 'success', 'fail'.
143
144 =item B<--critical-*>
145
146 Critical threshold.
147 Can be: 'success', 'fail'.
148
149 =back
150
151 =cut