Skip to content

Commit 3571bfc

Browse files
authored
feat(network::kairos::snmp): new plugin (#5998)
Co-authored-by: garnier-quentin <garnier.quentin@gmail.com> Refs: CTOR-2127
1 parent 784467e commit 3571bfc

13 files changed

Lines changed: 997 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": [
3+
"libsnmp-perl"
4+
]
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"pkg_name": "centreon-plugin-Network-Kairos-Snmp",
3+
"pkg_summary": "Centreon Plugin Kairos SNMP",
4+
"plugin_name": "centreon_kairos_snmp.pl",
5+
"files": [
6+
"centreon/plugins/script_snmp.pm",
7+
"centreon/plugins/snmp.pm",
8+
"snmp_standard/mode/cpu.pm",
9+
"snmp_standard/mode/cpudetailed.pm",
10+
"snmp_standard/mode/interfaces.pm",
11+
"snmp_standard/mode/listinterfaces.pm",
12+
"snmp_standard/mode/loadaverage.pm",
13+
"snmp_standard/mode/memory.pm",
14+
"snmp_standard/mode/resources/",
15+
"snmp_standard/mode/uptime.pm",
16+
"network/kairos/snmp/"
17+
]
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": [
3+
"perl(SNMP)"
4+
]
5+
}
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#
2+
# Copyright 2026-Present 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 network::kairos::snmp::mode::alarms;
22+
23+
use base qw(centreon::plugins::templates::counter);
24+
25+
use strict;
26+
use warnings;
27+
use centreon::plugins::constants qw(:counters);
28+
use centreon::plugins::misc qw(is_excluded);
29+
use Digest::MD5 qw(md5_hex);
30+
31+
sub custom_output {
32+
my ($self, %options) = @_;
33+
34+
return sprintf(
35+
"alarm '%s' count: %d [%s]",
36+
$self->{result_values}->{description},
37+
$self->{result_values}->{count},
38+
$self->{result_values}->{name}
39+
);
40+
}
41+
42+
sub custom_perfdata {
43+
my ($self, %options) = @_;
44+
45+
$self->{output}->perfdata_add(
46+
nlabel => 'alarm.' . $self->{result_values}->{name} . '.count',
47+
value => $self->{result_values}->{count},
48+
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
49+
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel})
50+
);
51+
}
52+
53+
sub set_counters {
54+
my ($self, %options) = @_;
55+
56+
$self->{maps_counters_type} = [
57+
{ name => 'alarms', type => COUNTER_TYPE_INSTANCE, message_multiple => 'All alarms are ok' }
58+
];
59+
60+
$self->{maps_counters}->{alarms} = [
61+
{ label => 'count', set => {
62+
key_values => [ { name => 'name' }, { name => 'description' }, { name => 'count', diff => 1 } ],
63+
closure_custom_output => $self->can('custom_output'),
64+
threshold_use => 'count',
65+
closure_custom_perfdata => $self->can('custom_perfdata'),
66+
}
67+
}
68+
];
69+
}
70+
71+
sub new {
72+
my ($class, %options) = @_;
73+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
74+
bless $self, $class;
75+
76+
$options{options}->add_options(arguments => {
77+
'filter-instance:s' => { name => 'filter_instance', default => '' },
78+
'filter-name:s' => { name => 'filter_name', default => '' }
79+
});
80+
81+
return $self;
82+
}
83+
84+
sub manage_selection {
85+
my ($self, %options) = @_;
86+
87+
$self->{cache_name} = "kairos_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
88+
md5_hex(
89+
($self->{option_results}->{filter_counters} // '') . '_' .
90+
$self->{option_results}->{filter_name} . '_' .
91+
$self->{option_results}->{filter_instance}
92+
);
93+
94+
my %map_name = (
95+
1 => 'IO1Contact',
96+
2 => 'IO2Contact',
97+
3 => 'LogicSupply',
98+
4 => 'SupplyHigh',
99+
5 => 'SupplyLow',
100+
6 => 'EthLink',
101+
7 => 'PldData',
102+
8 => 'DspUpAndRun',
103+
9 => 'Gnss',
104+
10 => 'Vocoder',
105+
11 => 'BsTemperature',
106+
12 => 'TxTemperature',
107+
13 => 'NoTxPower',
108+
14 => 'TxPowerLow',
109+
15 => 'TxPowerHigh',
110+
16 => 'SWRPower',
111+
17 => 'ROS',
112+
18 => 'TxPowerReduced',
113+
19 => 'SynchSource',
114+
20 => 'Synch',
115+
21 => 'BoardVTunes',
116+
22 => 'TrxVTunes',
117+
23 => 'BoardClock',
118+
24 => 'TrxClock',
119+
25 => 'BoardPllLock',
120+
26 => 'TrxPllLock',
121+
27 => 'PldFault',
122+
28 => 'PldDspComm',
123+
29 => 'IFRxGen',
124+
30 => 'RxGen',
125+
31 => 'RfNoise',
126+
32 => 'RegMaster',
127+
33 => 'RegSlave',
128+
34 => 'DeregSlave',
129+
35 => 'LossSlave',
130+
36 => 'MasterRole',
131+
37 => 'BckMasterConn',
132+
38 => 'DmrEmerCall',
133+
39 => '1Plus1BsActive',
134+
40 => '1Plus1BsHotSpare',
135+
41 => 'TrxLayer',
136+
42 => 'BsLayer',
137+
43 => 'SipNameResolve',
138+
44 => 'FailSipReg',
139+
45 => 'SipReg',
140+
46 => 'SipDereg',
141+
47 => 'SipServerChange',
142+
48 => 'SipTrunk'
143+
);
144+
145+
$self->{alarms} = {};
146+
147+
my $oid_alarmTable = '.1.3.6.1.4.1.37755.51';
148+
149+
150+
151+
my $snmp_result = $options{snmp}->get_table(oid => $oid_alarmTable, nothing_quit => 1);
152+
foreach my $oid (keys %$snmp_result) {
153+
next if ($oid !~ /^$oid_alarmTable\.(\d+)\.\d+$/);
154+
my $instance = $1;
155+
next if ($snmp_result->{$oid} !~ /^Alarm\s+(.*?)\s+->\s+Tot:(\d+)/i);
156+
my ($name, $description, $count) = ($map_name{$instance}, $1, $2);
157+
158+
next if is_excluded($instance, $self->{option_results}->{filter_instance});
159+
next if is_excluded($name, quotemeta($self->{option_results}->{filter_name}));
160+
161+
$self->{alarms}->{$instance} = {
162+
instance => $instance,
163+
name => $name,
164+
description => $description,
165+
count => $count
166+
};
167+
}
168+
}
169+
170+
1;
171+
172+
__END__
173+
174+
=head1 MODE
175+
176+
Check alarms.
177+
178+
=over 8
179+
180+
=item B<--filter-instance>
181+
182+
Filter on alarm instance (Can be a regexp).
183+
184+
=item B<--filter-name>
185+
186+
Filter on alarm name (Can be a regexp).
187+
188+
=item B<--warning-count>
189+
190+
Thresholds.
191+
192+
=item B<--critical-count>
193+
194+
Thresholds.
195+
196+
=back
197+
198+
=cut
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#
2+
# Copyright 2026-Present 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 network::kairos::snmp::mode::hardware;
22+
23+
use base qw(centreon::plugins::templates::counter);
24+
25+
use strict;
26+
use warnings;
27+
28+
use centreon::plugins::constants qw(:counters);
29+
30+
sub prefix_board_output {
31+
my ($self, %options) = @_;
32+
33+
return 'Board ';
34+
}
35+
36+
sub set_counters {
37+
my ($self, %options) = @_;
38+
39+
$self->{maps_counters_type} = [
40+
{ name => 'board', type => COUNTER_TYPE_GLOBAL, cb_prefix_output => 'prefix_board_output' }
41+
];
42+
43+
$self->{maps_counters}->{board} = [
44+
{
45+
label => 'board-voltage', nlabel => 'board.voltage.volt',
46+
set => {
47+
key_values => [ { name => 'inputVoltage' } ],
48+
output_template => 'voltage: %.2fV',
49+
perfdatas => [ { template => '%.2f', unit => 'V' } ]
50+
}
51+
},
52+
{
53+
label => 'board-tx-current', nlabel => 'board.tx.current.ampere',
54+
set => {
55+
key_values => [ { name => 'txCurrent' } ],
56+
output_template => 'TX current: %.2fA',
57+
perfdatas => [ { template => '%.2f', unit => 'A' } ]
58+
}
59+
},
60+
{ label => 'board-temperature', nlabel => 'board.temperature.celsius',
61+
set => {
62+
key_values => [ { name => 'boardTemp' } ],
63+
output_template => 'temperature is %s C',
64+
perfdatas => [
65+
{ template => '%s', unit => 'C' }
66+
]
67+
}
68+
},
69+
{ label => 'board-tx-temperature', nlabel => 'board.tx.temperature.celsius',
70+
set => {
71+
key_values => [ { name => 'txTemp' } ],
72+
output_template => 'TX temperature is %s C',
73+
perfdatas => [
74+
{ template => '%s', unit => 'C' }
75+
]
76+
}
77+
}
78+
];
79+
}
80+
81+
sub new {
82+
my ($class, %options) = @_;
83+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
84+
bless $self, $class;
85+
86+
return $self;
87+
}
88+
89+
sub manage_selection {
90+
my ($self, %options) = @_;
91+
92+
my $oid_kairosHndMainStatusInputVoltage = '.1.3.6.1.4.1.37755.61.2.1.1.0';
93+
my $oid_kairosHndMainStatusBoardTemp = '.1.3.6.1.4.1.37755.61.2.1.2.0';
94+
my $oid_kairosHndMainStatusTxTemp = '.1.3.6.1.4.1.37755.61.2.1.3.0';
95+
my $oid_kairosHndMainStatusTxCurrent = '.1.3.6.1.4.1.37755.61.2.1.4.0';
96+
97+
my $snmp_result = $options{snmp}->get_leef(
98+
oids => [
99+
$oid_kairosHndMainStatusInputVoltage,
100+
$oid_kairosHndMainStatusBoardTemp,
101+
$oid_kairosHndMainStatusTxTemp,
102+
$oid_kairosHndMainStatusTxCurrent
103+
],
104+
nothing_quit => 1
105+
);
106+
107+
$self->{board} = {
108+
inputVoltage => $snmp_result->{$oid_kairosHndMainStatusInputVoltage},
109+
txCurrent => $snmp_result->{$oid_kairosHndMainStatusTxCurrent},
110+
boardTemp => $snmp_result->{$oid_kairosHndMainStatusBoardTemp},
111+
txTemp => $snmp_result->{$oid_kairosHndMainStatusTxTemp}
112+
};
113+
}
114+
115+
1;
116+
117+
__END__
118+
119+
=head1 MODE
120+
121+
Check hardware sensors.
122+
123+
=over 8
124+
125+
=item B<--warning-board-temperature>
126+
127+
Threshold in C.
128+
129+
=item B<--critical-board-temperature>
130+
131+
Threshold in C.
132+
133+
=item B<--warning-board-tx-current>
134+
135+
Threshold in Amperes.
136+
137+
=item B<--critical-board-tx-current>
138+
139+
Threshold in Amperes.
140+
141+
=item B<--warning-board-tx-temperature>
142+
143+
Threshold in C.
144+
145+
=item B<--critical-board-tx-temperature>
146+
147+
Threshold in C.
148+
149+
=item B<--warning-board-voltage>
150+
151+
Threshold in Volts.
152+
153+
=item B<--critical-board-voltage>
154+
155+
Threshold in Volts.
156+
157+
=back
158+
159+
=cut

0 commit comments

Comments
 (0)