| 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 apps::video::zixi::restapi::mode::feederoutputusage; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
my $msg = 'active : ' . $self->{result_values}->{active} . ' [error: ' . ($self->{result_values}->{error} ne '' ? $self->{result_values}->{error} : '-') . ']'; |
| 33 |
|
| 34 |
return $msg; |
| 35 |
} |
| 36 |
|
| 37 |
sub custom_status_calc { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'}; |
| 41 |
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; |
| 42 |
$self->{result_values}->{error} = $options{new_datas}->{$self->{instance} . '_error'}; |
| 43 |
$self->{result_values}->{con_stat} = $options{new_datas}->{$self->{instance} . '_con_stat'}; |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
sub set_counters { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
$self->{maps_counters_type} = [ |
| 52 |
{ name => 'output_stream', type => 1, cb_prefix_output => 'prefix_output_output', message_multiple => 'All outputs are ok' }, |
| 53 |
]; |
| 54 |
|
| 55 |
$self->{maps_counters}->{output_stream} = [ |
| 56 |
{ label => 'status', threshold => 0, set => { |
| 57 |
key_values => [ { name => 'active' }, { name => 'name' }, { name => 'error' }, { name => 'con_stat' } ], |
| 58 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 59 |
closure_custom_output => $self->can('custom_status_output'), |
| 60 |
closure_custom_perfdata => sub { return 0; }, |
| 61 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 62 |
} |
| 63 |
}, |
| 64 |
{ label => 'current-bitrate', set => { |
| 65 |
key_values => [ { name => 'bitrate' }, { name => 'name' } ], |
| 66 |
output_change_bytes => 2, |
| 67 |
output_template => 'Current Bitrate : %s %s/s', |
| 68 |
perfdatas => [ |
| 69 |
{ label => 'current_bitrate', value => 'bitrate', template => '%.2f', |
| 70 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name' }, |
| 71 |
], |
| 72 |
} |
| 73 |
}, |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
sub new { |
| 78 |
my ($class, %options) = @_; |
| 79 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 80 |
bless $self, $class; |
| 81 |
|
| 82 |
$options{options}->add_options(arguments => |
| 83 |
{ |
| 84 |
"filter-name:s" => { name => 'filter_name' }, |
| 85 |
"warning-status:s" => { name => 'warning_status' }, |
| 86 |
"critical-status:s" => { name => 'critical_status' }, |
| 87 |
}); |
| 88 |
|
| 89 |
return $self; |
| 90 |
} |
| 91 |
|
| 92 |
sub check_options { |
| 93 |
my ($self, %options) = @_; |
| 94 |
$self->SUPER::check_options(%options); |
| 95 |
|
| 96 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 97 |
} |
| 98 |
|
| 99 |
sub prefix_output_output { |
| 100 |
my ($self, %options) = @_; |
| 101 |
|
| 102 |
return "Output '" . $options{instance_value}->{name} . "' "; |
| 103 |
} |
| 104 |
|
| 105 |
sub manage_selection { |
| 106 |
my ($self, %options) = @_; |
| 107 |
|
| 108 |
$self->{output_stream} = {}; |
| 109 |
my $result = $options{custom}->get(path => '/outs'); |
| 110 |
foreach my $entry (@{$result->{outs}}) { |
| 111 |
$entry->{name} = centreon::plugins::misc::trim($entry->{name}); |
| 112 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 113 |
$entry->{name} !~ /$self->{option_results}->{filter_name}/) { |
| 114 |
$self->{output}->output_add(long_msg => "skipping '" . $entry->{source} . "': no matching filter.", debug => 1); |
| 115 |
next; |
| 116 |
} |
| 117 |
|
| 118 |
$self->{output_stream}->{$entry->{name}} = { |
| 119 |
name => $entry->{name}, |
| 120 |
active => $entry->{active} == 0 ? 'false' : 'true', |
| 121 |
error => $entry->{error}, |
| 122 |
con_stat => $entry->{con_stat}, |
| 123 |
bitrate => $entry->{bitrate}, |
| 124 |
}; |
| 125 |
} |
| 126 |
|
| 127 |
if (scalar(keys %{$self->{output_stream}}) <= 0) { |
| 128 |
$self->{output}->add_option_msg(short_msg => "No output found."); |
| 129 |
$self->{output}->option_exit(); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
1; |
| 134 |
|
| 135 |
__END__ |
| 136 |
|
| 137 |
=head1 MODE |
| 138 |
|
| 139 |
Check feeder output usage. |
| 140 |
|
| 141 |
=over 8 |
| 142 |
|
| 143 |
=item B<--filter-source> |
| 144 |
|
| 145 |
Filter source (can be a regexp). |
| 146 |
|
| 147 |
=item B<--filter-counters> |
| 148 |
|
| 149 |
Only display some counters (regexp can be used). |
| 150 |
Example: --filter-counters='^status$' |
| 151 |
|
| 152 |
=item B<--warning-*> |
| 153 |
|
| 154 |
Warning threshold. |
| 155 |
Can be: 'current-birate'. |
| 156 |
|
| 157 |
=item B<--critical-*> |
| 158 |
|
| 159 |
Critical threshold. |
| 160 |
Can be: 'current-birate'. |
| 161 |
|
| 162 |
=item B<--warning-status> |
| 163 |
|
| 164 |
Define the conditions to match for the status to be WARNING (default: -) |
| 165 |
You can use the following variables: %{name}, %{active}, %{error}, %{con_stat}. |
| 166 |
|
| 167 |
=item B<--critical-status> |
| 168 |
|
| 169 |
Define the conditions to match for the status to be CRITICAL (default: -). |
| 170 |
You can use the following variables: %{name}, %{active}, %{error}, %{con_stat}. |
| 171 |
|
| 172 |
=back |
| 173 |
|
| 174 |
=cut |