Debian Codegraph @

src/centreon/common/cisco/standard/snmp/mode/configuration.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::cisco::standard::snmp::mode::configuration;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
28
29 sub custom_status_perfdata {
30 my ($self, %options) = @_;
31
32 $self->{output}->perfdata_add(label => 'running_last_changed', unit => 's',
33 value => sprintf("%d", $self->{result_values}->{running_last_changed}),
34 min => 0);
35 $self->{output}->perfdata_add(label => 'running_last_saved', unit => 's',
36 value => sprintf("%d", $self->{result_values}->{running_last_saved}),
37 min => 0);
38 $self->{output}->perfdata_add(label => 'startup_last_changed', unit => 's',
39 value => sprintf("%d", $self->{result_values}->{startup_last_changed}),
40 min => 0);
41 }
42
43 sub custom_status_output {
44 my ($self, %options) = @_;
45
46 my $msg = sprintf("Configuration Running Last Changed: %s, Running Last Saved: %s, Startup Last Changed: %s",
47 ($self->{result_values}->{running_last_changed} > 0) ? centreon::plugins::misc::change_seconds(value => $self->{result_values}->{running_last_changed}) : "-",
48 ($self->{result_values}->{running_last_saved} > 0) ? centreon::plugins::misc::change_seconds(value => $self->{result_values}->{running_last_saved}) : "-",
49 ($self->{result_values}->{startup_last_changed} > 0) ? centreon::plugins::misc::change_seconds(value => $self->{result_values}->{startup_last_changed}) : "-");
50 return $msg;
51 }
52
53 sub custom_status_calc {
54 my ($self, %options) = @_;
55
56 $self->{result_values}->{running_last_changed} = $options{new_datas}->{$self->{instance} . '_running_last_changed'};
57 $self->{result_values}->{running_last_saved} = $options{new_datas}->{$self->{instance} . '_running_last_saved'};
58 $self->{result_values}->{startup_last_changed} = $options{new_datas}->{$self->{instance} . '_startup_last_changed'};
59 return 0;
60 }
61
62 sub set_counters {
63 my ($self, %options) = @_;
64
65 $self->{maps_counters_type} = [
66 { name => 'global', type => 0 },
67 ];
68
69 $self->{maps_counters}->{global} = [
70 { label => 'status', threshold => 0, set => {
71 key_values => [ { name => 'running_last_changed' }, { name => 'running_last_saved' }, { name => 'startup_last_changed' } ],
72 closure_custom_calc => $self->can('custom_status_calc'),
73 closure_custom_output => $self->can('custom_status_output'),
74 closure_custom_perfdata => $self->can('custom_status_perfdata'),
75 closure_custom_threshold_check => \&catalog_status_threshold,
76 }
77 },
78 ];
79 }
80
81 sub new {
82 my ($class, %options) = @_;
83 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
84 bless $self, $class;
85
86 $options{options}->add_options(arguments =>
87 {
88 "warning-status:s" => { name => 'warning_status', default => '' },
89 "critical-status:s" => { name => 'critical_status', default => '%{running_last_changed} > %{running_last_saved}' },
90 });
91
92 return $self;
93 }
94
95 sub check_options {
96 my ($self, %options) = @_;
97 $self->SUPER::check_options(%options);
98
99 $self->change_macros(macros => ['warning_status', 'critical_status']);
100 }
101
102 my $oid_ccmHistoryRunningLastChanged = '.1.3.6.1.4.1.9.9.43.1.1.1.0';
103 my $oid_ccmHistoryRunningLastSaved = '.1.3.6.1.4.1.9.9.43.1.1.2.0';
104 my $oid_ccmHistoryStartupLastChanged = '.1.3.6.1.4.1.9.9.43.1.1.3.0';
105
106 sub manage_selection {
107 my ($self, %options) = @_;
108 $self->{snmp} = $options{snmp};
109
110 $self->{global} = {};
111
112 $self->{results} = $self->{snmp}->get_leef(oids => [ $oid_ccmHistoryRunningLastChanged, $oid_ccmHistoryRunningLastSaved,
113 $oid_ccmHistoryStartupLastChanged ], nothing_quit => 1);
114
115 $self->{global} = {
116 running_last_changed => $self->{results}->{$oid_ccmHistoryRunningLastChanged} / 100,
117 running_last_saved => $self->{results}->{$oid_ccmHistoryRunningLastSaved} / 100,
118 startup_last_changed => $self->{results}->{$oid_ccmHistoryStartupLastChanged} / 100,
119 }
120 }
121
122 1;
123
124 __END__
125
126 =head1 MODE
127
128 Check Cisco changed and saved configurations (CISCO-CONFIG-MAN-MIB).
129
130 =over 8
131
132 =item B<--warning-status>
133
134 Define the conditions to match for the status to be WARNING (default: '').
135 You can use the following variables: %{running_last_changed}, %{running_last_saved}, %{startup_last_changed}
136
137 =item B<--critical-status>
138
139 Define the conditions to match for the status to be CRITICAL (default: '%{running_last_changed} > %{running_last_saved}').
140 You can use the following variables: %{running_last_changed}, %{running_last_saved}, %{startup_last_changed}
141
142 =back
143
144 =cut
145