Skip to content

Commit ec406b3

Browse files
(plugin) os::linux::local - add mode systemd-journal (centreon#4609)
1 parent d9e106a commit ec406b3

12 files changed

Lines changed: 283 additions & 59 deletions

File tree

src/os/linux/local/mode/cpu.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ sub set_counters {
107107
output_template => 'CPU(s) average usage is %.2f %%',
108108
output_use => 'prct_used', threshold_use => 'prct_used',
109109
perfdatas => [
110-
{ label => 'total_cpu_avg', value => 'prct_used', template => '%.2f',
110+
{ value => 'prct_used', template => '%.2f',
111111
min => 0, max => 100, unit => '%' }
112112
]
113113
}
@@ -124,7 +124,7 @@ sub set_counters {
124124
output_template => 'usage : %.2f %%',
125125
output_use => 'prct_used', threshold_use => 'prct_used',
126126
perfdatas => [
127-
{ label => 'cpu', value => 'prct_used', template => '%.2f',
127+
{ value => 'prct_used', template => '%.2f',
128128
min => 0, max => 100, unit => '%', label_extra_instance => 1 }
129129
]
130130
}
@@ -140,7 +140,7 @@ sub prefix_cpu_core_output {
140140

141141
sub new {
142142
my ($class, %options) = @_;
143-
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
143+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
144144
bless $self, $class;
145145

146146
$options{options}->add_options(arguments => {

src/os/linux/local/mode/cpudetailed.pm

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ my $maps = [
4141

4242
sub new {
4343
my ($class, %options) = @_;
44-
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
44+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
4545
bless $self, $class;
4646

4747
$options{options}->add_options(arguments => {
@@ -50,7 +50,7 @@ sub new {
5050
foreach (@{$maps}) {
5151
$options{options}->add_options(arguments => {
5252
'warning-' . $_->{counter} . ':s' => { name => 'warning_' . $_->{counter} },
53-
'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} },
53+
'critical-' . $_->{counter} . ':s' => { name => 'critical_' . $_->{counter} }
5454
});
5555
}
5656

@@ -108,13 +108,15 @@ sub run {
108108
$new_datas->{$cpu_number} = { total => 0 };
109109
$old_datas->{$cpu_number} = { total => 0 };
110110
}
111+
111112
$new_datas->{$cpu_number}->{$_->{counter}} = $values[$_->{position}];
112113
$save_datas->{'cpu' . $cpu_number . '_' . $_->{counter}} = $values[$_->{position}];
113114
my $tmp_value = $self->{statefile_cache}->get(name => 'cpu' . $cpu_number . '_' . $_->{counter});
114115
if (!defined($tmp_value)) {
115116
$buffer_creation = 1;
116117
next;
117118
}
119+
118120
if ($new_datas->{$cpu_number}->{$_->{counter}} < $tmp_value) {
119121
$buffer_creation = 1;
120122
next;
@@ -129,24 +131,30 @@ sub run {
129131

130132
$self->{statefile_cache}->write(data => $save_datas);
131133
if ($buffer_creation == 1) {
132-
$self->{output}->output_add(severity => 'OK',
133-
short_msg => "Buffer creation...");
134+
$self->{output}->output_add(
135+
severity => 'OK',
136+
short_msg => "Buffer creation..."
137+
);
134138
if ($exit == 0) {
135139
$self->{output}->display();
136140
$self->{output}->exit();
137141
}
138142
}
139143

140-
$self->{output}->output_add(severity => 'OK',
141-
short_msg => "CPUs usages are ok.");
144+
$self->{output}->output_add(
145+
severity => 'OK',
146+
short_msg => "CPUs usages are ok."
147+
);
142148

143149
foreach my $cpu_number (sort keys(%$new_datas)) {
144150
# In buffer creation. New cpu
145151
next if (scalar(keys %{$old_datas->{$cpu_number}}) <= 1);
146152

147153
if ($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total} == 0) {
148-
$self->{output}->output_add(severity => 'OK',
149-
short_msg => "Counter not moved. Have to wait.");
154+
$self->{output}->output_add(
155+
severity => 'OK',
156+
short_msg => "Counter not moved. Have to wait."
157+
);
150158
$self->{output}->display();
151159
$self->{output}->exit();
152160
}
@@ -175,25 +183,36 @@ sub run {
175183
my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter});
176184
my $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $_->{counter});
177185

178-
$self->{output}->perfdata_add(label => 'cpu' . $cpu_number . '_' . $_->{counter}, unit => '%',
179-
value => sprintf("%.2f", $value),
180-
warning => $warning,
181-
critical => $critical,
182-
min => 0, max => 100);
186+
$self->{output}->perfdata_add(
187+
nlabel => 'core.cpu.utilization.percentage',
188+
unit => '%',
189+
instances => [$cpu_number, $_->{counter}],
190+
value => sprintf("%.2f", $value),
191+
warning => $warning,
192+
critical => $critical,
193+
min => 0, max => 100
194+
);
183195
}
196+
184197
$self->{output}->output_add(long_msg => $str_output);
185198
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
186-
$self->{output}->output_add(severity => $exit,
187-
short_msg => $str_output);
199+
$self->{output}->output_add(
200+
severity => $exit,
201+
short_msg => $str_output
202+
);
188203
}
189204
}
190205

191206
# We can display a total (some buffer creation and counters have moved)
192207
if ($total_cpu_num != 0) {
193208
foreach my $counter (sort keys %{$total_datas}) {
194-
$self->{output}->perfdata_add(label => 'total_cpu_' . $counter . '_avg', unit => '%',
195-
value => sprintf("%.2f", $total_datas->{$counter} / $total_cpu_num),
196-
min => 0, max => 100);
209+
$self->{output}->perfdata_add(
210+
nlabel => 'cpu.utilization.percentage',
211+
instances => $counter,
212+
unit => '%',
213+
value => sprintf("%.2f", $total_datas->{$counter} / $total_cpu_num),
214+
min => 0, max => 100
215+
);
197216
}
198217
}
199218

src/os/linux/local/mode/filesdate.pm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use centreon::plugins::misc;
2828

2929
sub new {
3030
my ($class, %options) = @_;
31-
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
3232
bless $self, $class;
3333

3434
$options{options}->add_options(arguments => {
@@ -115,8 +115,11 @@ sub run {
115115
short_msg => sprintf('%s: %s seconds (time: %s)', $name, $diff_time, scalar(localtime($time)))
116116
);
117117
}
118+
118119
$self->{output}->perfdata_add(
119-
label => $name, unit => 's',
120+
nlabel => 'file.mtime.last.seconds',
121+
instances => $name,
122+
unit => 's',
120123
value => $diff_time,
121124
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
122125
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')

src/os/linux/local/mode/filessize.pm

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use centreon::plugins::misc;
2828

2929
sub new {
3030
my ($class, %options) = @_;
31-
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
3232
bless $self, $class;
3333

3434
$options{options}->add_options(arguments => {
@@ -123,7 +123,9 @@ sub run {
123123
);
124124
}
125125
$self->{output}->perfdata_add(
126-
label => $name, unit => 'B',
126+
nlabel => 'file.size.bytes',
127+
instances => $name,
128+
unit => 'B',
127129
value => $size,
128130
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_one'),
129131
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_one'),
@@ -145,7 +147,8 @@ sub run {
145147
);
146148
}
147149
$self->{output}->perfdata_add(
148-
label => 'total', unit => 'B',
150+
nlabel => 'files.size.bytes',
151+
unit => 'B',
149152
value => $total_size,
150153
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_total'),
151154
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_total'),

src/os/linux/local/mode/inodes.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sub set_counters {
3939
];
4040

4141
$self->{maps_counters}->{inodes} = [
42-
{ label => 'usage', set => {
42+
{ label => 'usage', nlabel => 'storage.inodes.usage.percentage', set => {
4343
key_values => [ { name => 'used' }, { name => 'display' } ],
4444
output_template => 'used: %s %%',
4545
perfdatas => [
@@ -53,7 +53,7 @@ sub set_counters {
5353

5454
sub new {
5555
my ($class, %options) = @_;
56-
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
56+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
5757
bless $self, $class;
5858

5959
$options{options}->add_options(arguments => {

src/os/linux/local/mode/packeterrors.pm

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,46 +75,46 @@ sub set_counters {
7575
closure_custom_threshold_check => \&catalog_status_threshold_ng
7676
}
7777
},
78-
{ label => 'in-discard', set => {
78+
{ label => 'in-discard', nlabel => 'interface.packets.in.discard.percentage', set => {
7979
key_values => [ { name => 'discard_in', diff => 1 }, { name => 'total_in', diff => 1 }, { name => 'display' } ],
8080
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'discard', label_ref => 'in' },
8181
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Discard In : %s',
8282
threshold_use => 'result_prct',
8383
perfdatas => [
84-
{ label => 'packets_discard_in', value => 'result_prct', template => '%.2f', min => 0, max => 100,
84+
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
8585
unit => '%', label_extra_instance => 1, instance_use => 'display' }
8686
]
8787
}
8888
},
89-
{ label => 'out-discard', set => {
89+
{ label => 'out-discard', nlabel => 'interface.packets.out.discard.percentage', set => {
9090
key_values => [ { name => 'discard_out', diff => 1 }, { name => 'total_out', diff => 1 }, { name => 'display' } ],
9191
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'discard', label_ref => 'out' },
9292
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Discard Out : %s',
9393
threshold_use => 'result_prct',
9494
perfdatas => [
95-
{ label => 'packets_discard_out', value => 'result_prct', template => '%.2f', min => 0, max => 100,
95+
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
9696
unit => '%', label_extra_instance => 1, instance_use => 'display' }
9797
]
9898
}
9999
},
100-
{ label => 'in-error', set => {
100+
{ label => 'in-error', nlabel => 'interface.packets.in.error.percentage', set => {
101101
key_values => [ { name => 'error_in', diff => 1 }, { name => 'total_in', diff => 1 }, { name => 'display' } ],
102102
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'error', label_ref => 'in' },
103103
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Error In : %s',
104104
threshold_use => 'result_prct',
105105
perfdatas => [
106-
{ label => 'packets_error_in', value => 'result_prct', template => '%.2f', min => 0, max => 100,
106+
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
107107
unit => '%', label_extra_instance => 1, instance_use => 'display' }
108108
]
109109
}
110110
},
111-
{ label => 'out-error', set => {
111+
{ label => 'out-error', nlabel => 'interface.packets.out.error.percentage', set => {
112112
key_values => [ { name => 'error_out', diff => 1 }, { name => 'total_out', diff => 1 }, { name => 'display' } ],
113113
closure_custom_calc => $self->can('custom_packet_calc'), closure_custom_calc_extra_options => { type => 'error', label_ref => 'out' },
114114
closure_custom_output => $self->can('custom_packet_output'), output_error_template => 'Error In : %s',
115115
threshold_use => 'result_prct',
116116
perfdatas => [
117-
{ label => 'packets_error_out', value => 'result_prct', template => '%.2f', min => 0, max => 100,
117+
{ value => 'result_prct', template => '%.2f', min => 0, max => 100,
118118
unit => '%', label_extra_instance => 1, instance_use => 'display' }
119119
]
120120
}
@@ -124,7 +124,7 @@ sub set_counters {
124124

125125
sub new {
126126
my ($class, %options) = @_;
127-
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
127+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
128128
bless $self, $class;
129129

130130
$options{options}->add_options(arguments => {
@@ -235,6 +235,21 @@ Command used: /sbin/ip -s addr 2>&1
235235
236236
=over 8
237237
238+
=item B<--unknown-status>
239+
240+
Define the conditions to match for the status to be UNKNOWN.
241+
You can use the following variables: %{status}, %{display}
242+
243+
=item B<--warning-status>
244+
245+
Define the conditions to match for the status to be WARNING.
246+
You can use the following variables: %{status}, %{display}
247+
248+
=item B<--critical-status>
249+
250+
Define the conditions to match for the status to be CRITICAL (default: '%{status} ne "RU"').
251+
You can use the following variables: %%{status}, %{display}
252+
238253
=item B<--warning-*>
239254
240255
Warning threshold in percent of total packets. Can be:

src/os/linux/local/mode/quota.pm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ use warnings;
2828
sub custom_usage_perfdata {
2929
my ($self, %options) = @_;
3030

31-
my ($extra_label, $unit) = ('', '');
31+
my $unit = '';
3232
$unit = 'B' if ($self->{result_values}->{label_ref} eq 'data');
33-
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
34-
$extra_label .= '_' . $self->{result_values}->{display};
35-
}
33+
3634
$self->{output}->perfdata_add(
37-
label => $self->{result_values}->{label_ref} . '_used' . $extra_label, unit => $unit,
35+
nlabel => $self->{nlabel},
36+
unit => $unit,
37+
instances => $self->{result_values}->{display},
3838
value => $self->{result_values}->{used},
3939
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{warn_label}, total => $self->{result_values}->{total}, cast_int => 1),
4040
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{crit_label}, total => $self->{result_values}->{total}, cast_int => 1),
@@ -72,7 +72,7 @@ sub custom_usage_output {
7272
}
7373

7474
return sprintf(
75-
"%s Used: %s%s%s",
75+
"%s used: %s%s%s",
7676
ucfirst($self->{result_values}->{label_ref}),
7777
$value,
7878
$limit_soft, $limit_hard
@@ -120,15 +120,15 @@ sub set_counters {
120120
];
121121

122122
$self->{maps_counters}->{quota} = [
123-
{ label => 'data-usage', set => {
123+
{ label => 'data-usage', nlabel => 'quota.data.usage.bytes', set => {
124124
key_values => [ { name => 'display' }, { name => 'data_used' }, { name => 'data_soft' }, { name => 'data_hard' } ],
125125
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'data' },
126126
closure_custom_output => $self->can('custom_usage_output'),
127127
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
128128
closure_custom_threshold_check => $self->can('custom_usage_threshold')
129129
}
130130
},
131-
{ label => 'inode-usage', set => {
131+
{ label => 'inode-usage', nlabel => 'quota.files.usage.count', set => {
132132
key_values => [ { name => 'display' }, { name => 'inode_used' }, { name => 'inode_soft' }, { name => 'inode_hard' } ],
133133
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'inode' },
134134
closure_custom_output => $self->can('custom_usage_output'),
@@ -141,7 +141,7 @@ sub set_counters {
141141

142142
sub new {
143143
my ($class, %options) = @_;
144-
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
144+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
145145
bless $self, $class;
146146

147147
$options{options}->add_options(arguments => {

src/os/linux/local/mode/storage.pm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use warnings;
2828
sub custom_usage_perfdata {
2929
my ($self, %options) = @_;
3030

31-
my $label = 'used';
31+
my $label = $self->{nlabel};
3232
my $value_perf = $self->{result_values}->{used};
3333
if (defined($self->{instance_mode}->{option_results}->{free})) {
34-
$label = 'free';
34+
$label = 'storage.space.free.bytes';
3535
$value_perf = $self->{result_values}->{free};
3636
}
3737

@@ -42,8 +42,9 @@ sub custom_usage_perfdata {
4242
}
4343

4444
$self->{output}->perfdata_add(
45-
label => $label, unit => 'B',
46-
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
45+
nlabel => $label,
46+
unit => 'B',
47+
instances => $self->{result_values}->{display},
4748
value => $value_perf,
4849
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options),
4950
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options),
@@ -110,7 +111,7 @@ sub set_counters {
110111
];
111112

112113
$self->{maps_counters}->{disks} = [
113-
{ label => 'usage', set => {
114+
{ label => 'usage', nlabel => 'storage.space.usage.bytes', set => {
114115
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'free' }, { name => 'total' } ],
115116
closure_custom_calc => $self->can('custom_usage_calc'),
116117
closure_custom_output => $self->can('custom_usage_output'),
@@ -123,7 +124,7 @@ sub set_counters {
123124

124125
sub new {
125126
my ($class, %options) = @_;
126-
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
127+
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
127128
bless $self, $class;
128129

129130
$options{options}->add_options(arguments => {

0 commit comments

Comments
 (0)