|
| 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 |
0 commit comments