Debian Codegraph @

src/hardware/devices/masterclock/ntp100gps/snmp/mode/gpsstatus.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 hardware::devices::masterclock::ntp100gps::snmp::mode::gpsstatus;
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_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("GPS receiver health : '%s', Satellites seen : '%s', Latitude : '%s', Longitude : '%s'",
33 $self->{result_values}->{health},
34 $self->{result_values}->{satellites},
35 $self->{result_values}->{latitude},
36 $self->{result_values}->{longitude});
37
38 return $msg;
39 }
40
41 sub custom_status_calc {
42 my ($self, %options) = @_;
43
44 $self->{result_values}->{health} = $options{new_datas}->{$self->{instance} . '_health'};
45 $self->{result_values}->{satellites} = $options{new_datas}->{$self->{instance} . '_satellites'};
46 $self->{result_values}->{latitude} = $options{new_datas}->{$self->{instance} . '_latitude'};
47 $self->{result_values}->{longitude} = $options{new_datas}->{$self->{instance} . '_longitude'};
48
49 return 0;
50 }
51
52 sub set_counters {
53 my ($self, %options) = @_;
54
55 $self->{maps_counters_type} = [
56 { name => 'global', type => 0 },
57 ];
58
59 $self->{maps_counters}->{global} = [
60 { label => 'status', set => {
61 key_values => [ { name => 'health' }, { name => 'satellites' }, { name => 'latitude' }, { name => 'longitude' } ],
62 closure_custom_calc => $self->can('custom_status_calc'),
63 closure_custom_output => $self->can('custom_status_output'),
64 closure_custom_perfdata => sub { return 0; },
65 closure_custom_threshold_check => \&catalog_status_threshold,
66 }
67 },
68 ];
69 }
70
71 sub new {
72 my ($class, %options) = @_;
73 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
74 bless $self, $class;
75
76 $options{options}->add_options(arguments =>
77 {
78 "warning-status:s" => { name => 'warning_status', default => '%{satellites} =~ /No satellites in view/' },
79 "critical-status:s" => { name => 'critical_status', default => '' },
80 });
81
82 return $self;
83 }
84
85 sub check_options {
86 my ($self, %options) = @_;
87 $self->SUPER::check_options(%options);
88
89 $self->change_macros(macros => ['warning_status', 'critical_status']);
90 }
91
92 sub manage_selection {
93 my ($self, %options) = @_;
94
95 my $oid_gps_health = ".1.3.6.1.4.1.45561.1.1.1.26.0";
96 my $oid_gps_latitude = ".1.3.6.1.4.1.45561.1.1.1.27.0";
97 my $oid_gps_longitude = ".1.3.6.1.4.1.45561.1.1.1.28.0";
98 my $oid_gps_satellites = ".1.3.6.1.4.1.45561.1.1.1.29.0";
99
100 my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_gps_health, $oid_gps_latitude, $oid_gps_longitude, $oid_gps_satellites ]);
101
102 $self->{global} = {
103 health => $snmp_result->{$oid_gps_health},
104 latitude => $snmp_result->{$oid_gps_latitude},
105 longitude => $snmp_result->{$oid_gps_longitude},
106 satellites => $snmp_result->{$oid_gps_satellites},
107 };
108 }
109
110 1;
111
112 __END__
113
114 =head1 MODE
115
116 Check GPS status
117
118 =over 8
119
120 =item B<--warning-status>
121
122 Define the conditions to match for the status to be WARNING (default: '%{satellites} =~ /No satellites in view/')
123 You can use the following variables: %{health}, %{satellites}, %{latitude}, %{longitude}
124
125 =item B<--critical-status>
126
127 Define the conditions to match for the status to be CRITICAL (default: '')
128 You can use the following variables: %{health}, %{satellites}, %{latitude}, %{longitude}
129
130 =back
131
132 =cut