Debian Codegraph @

src/os/hpux/snmp/mode/load.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 os::hpux::snmp::mode::load;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments =>
34 {
35 "warning:s" => { name => 'warning', default => '' },
36 "critical:s" => { name => 'critical', default => '' },
37 });
38
39 return $self;
40 }
41
42 sub check_options {
43 my ($self, %options) = @_;
44 $self->SUPER::init(%options);
45
46 ($self->{warn1}, $self->{warn5}, $self->{warn15}) = split /,/, $self->{option_results}->{warning};
47 ($self->{crit1}, $self->{crit5}, $self->{crit15}) = split /,/, $self->{option_results}->{critical};
48
49 if (($self->{perfdata}->threshold_validate(label => 'warn1', value => $self->{warn1})) == 0) {
50 $self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1} . "'.");
51 $self->{output}->option_exit();
52 }
53 if (($self->{perfdata}->threshold_validate(label => 'warn5', value => $self->{warn5})) == 0) {
54 $self->{output}->add_option_msg(short_msg => "Wrong warning (5min) threshold '" . $self->{warn5} . "'.");
55 $self->{output}->option_exit();
56 }
57 if (($self->{perfdata}->threshold_validate(label => 'warn15', value => $self->{warn15})) == 0) {
58 $self->{output}->add_option_msg(short_msg => "Wrong warning (15min) threshold '" . $self->{warn15} . "'.");
59 $self->{output}->option_exit();
60 }
61 if (($self->{perfdata}->threshold_validate(label => 'crit1', value => $self->{crit1})) == 0) {
62 $self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1} . "'.");
63 $self->{output}->option_exit();
64 }
65 if (($self->{perfdata}->threshold_validate(label => 'crit5', value => $self->{crit5})) == 0) {
66 $self->{output}->add_option_msg(short_msg => "Wrong critical (5min) threshold '" . $self->{crit5} . "'.");
67 $self->{output}->option_exit();
68 }
69 if (($self->{perfdata}->threshold_validate(label => 'crit15', value => $self->{crit15})) == 0) {
70 $self->{output}->add_option_msg(short_msg => "Wrong critical (15min) threshold '" . $self->{crit15} . "'.");
71 $self->{output}->option_exit();
72 }
73 }
74
75 sub run {
76 my ($self, %options) = @_;
77
78 my $oid_computerSystemAvgJobs1 = '.1.3.6.1.4.1.11.2.3.1.1.3.0';
79 my $oid_computerSystemAvgJobs5 = '.1.3.6.1.4.1.11.2.3.1.1.4.0';
80 my $oid_computerSystemAvgJobs15 = '.1.3.6.1.4.1.11.2.3.1.1.5.0';
81
82 my $result = $options{snmp}->get_leef(oids => [$oid_computerSystemAvgJobs1, $oid_computerSystemAvgJobs5, $oid_computerSystemAvgJobs15], nothing_quit => 1);
83
84 my $cpu_load1 = $result->{$oid_computerSystemAvgJobs1} / 100;
85 my $cpu_load5 = $result->{$oid_computerSystemAvgJobs5} / 100;
86 my $cpu_load15 = $result->{$oid_computerSystemAvgJobs15} / 100;
87
88 $self->{output}->perfdata_add(label => 'load1',
89 value => $cpu_load1,
90 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
91 critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
92 min => 0);
93 $self->{output}->perfdata_add(label => 'load5',
94 value => $cpu_load5,
95 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
96 critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
97 min => 0);
98 $self->{output}->perfdata_add(label => 'load15',
99 value => $cpu_load15,
100 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
101 critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
102 min => 0);
103
104 my $exit1 = $self->{perfdata}->threshold_check(value => $cpu_load1,
105 threshold => [ { label => 'crit1', exit_litteral => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
106 my $exit2 = $self->{perfdata}->threshold_check(value => $cpu_load5,
107 threshold => [ { label => 'crit5', exit_litteral => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
108 my $exit3 = $self->{perfdata}->threshold_check(value => $cpu_load15,
109 threshold => [ { label => 'crit15', exit_litteral => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
110 my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
111 $self->{output}->output_add(severity => $exit,
112 short_msg => sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15));
113
114 $self->{output}->display();
115 $self->{output}->exit();
116 }
117
118 1;
119
120 __END__
121
122 =head1 MODE
123
124 Check system load-average.
125
126 =over 8
127
128 =item B<--warning>
129
130 Warning threshold (1min,5min,15min).
131
132 =item B<--critical>
133
134 Critical threshold (1min,5min,15min).
135
136 =back
137
138 =cut