asterisk: update plugin, add warning and critical threshold in remote plugin
This commit is contained in:
parent
5d89a8ac90
commit
60cca1809d
|
@ -53,9 +53,9 @@ sub new {
|
||||||
{
|
{
|
||||||
"hostname:s" => { name => 'hostname' },
|
"hostname:s" => { name => 'hostname' },
|
||||||
"port:s" => { name => 'port', default => 5038 },
|
"port:s" => { name => 'port', default => 5038 },
|
||||||
"username:s" => { name => 'username' },
|
"username:s" => { name => 'username' },
|
||||||
"password:s" => { name => 'password' },
|
"password:s" => { name => 'password' },
|
||||||
"remote:s" => { name => 'remote', default => 'ssh' },
|
"remote:s" => { name => 'remote', default => 'ssh' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
"ssh-option:s@" => { name => 'ssh_option' },
|
||||||
"ssh-path:s" => { name => 'ssh_path' },
|
"ssh-path:s" => { name => 'ssh_path' },
|
||||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||||
|
@ -64,6 +64,8 @@ sub new {
|
||||||
"command-path:s" => { name => 'command_path', default => '/home/centreon/bin' },
|
"command-path:s" => { name => 'command_path', default => '/home/centreon/bin' },
|
||||||
"protocol:s" => { name => 'protocol', },
|
"protocol:s" => { name => 'protocol', },
|
||||||
"filter-name:s" => { name => 'filter_name', },
|
"filter-name:s" => { name => 'filter_name', },
|
||||||
|
"warning:s" => { name => 'warning', },
|
||||||
|
"critical:s" => { name => 'critical', },
|
||||||
});
|
});
|
||||||
$self->{result} = {};
|
$self->{result} = {};
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -90,6 +92,15 @@ sub check_options {
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
|
@ -124,40 +135,73 @@ sub manage_selection {
|
||||||
|
|
||||||
# Compute data
|
# Compute data
|
||||||
foreach my $line (@result) {
|
foreach my $line (@result) {
|
||||||
next if ($line !~ /^(\w*)\/\w* .* (OK|Unreachable) \((.*) (.*)\)/);
|
if ($line =~ /^(\w*)\/\w* .* (OK) \((.*) (.*)\)/)
|
||||||
my ($trunkname, $trunkstatus, $trunkvalue, $trunkunit) = ($1, $2, $3, $4);
|
{
|
||||||
|
my ($trunkname, $trunkstatus, $trunkvalue, $trunkunit) = ($1, $2, $3, $4);
|
||||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
|
||||||
$trunkname !~ /$self->{option_results}->{filter_name}/) {
|
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||||
$self->{output}->output_add(long_msg => "Skipping trunk '" . $trunkname . "': no matching filter name");
|
$trunkname !~ /$self->{option_results}->{filter_name}/)
|
||||||
next;
|
{
|
||||||
|
$self->{output}->output_add(long_msg => "Skipping trunk '" . $trunkname . "': no matching filter name");
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{result}->{$trunkname} = {name => $trunkname, status => 'OK',
|
||||||
|
realstatus => $trunkstatus,
|
||||||
|
value => $trunkvalue,
|
||||||
|
unit => $trunkunit};
|
||||||
}
|
}
|
||||||
|
elsif ($line =~ /^(\w*)\/\w* .* (Unreachable)/)
|
||||||
$self->{result}->{$trunkname} = {name => $trunkname, status => $trunkstatus, value => $trunkvalue, unit => $trunkunit};
|
{
|
||||||
|
my ($trunkname, $trunkstatus) = ($1, $2);
|
||||||
|
$self->{result}->{$trunkname} = {name => $trunkname, status => 'CRITICAL', realstatus => $trunkstatus};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
# Send formated data to Centreon
|
|
||||||
my $msg;
|
my $msg;
|
||||||
|
my $old_status = 'ok';
|
||||||
|
|
||||||
|
# Send formated data to Centreon
|
||||||
$self->{output}->output_add(severity => 'OK',
|
$self->{output}->output_add(severity => 'OK',
|
||||||
short_msg => 'Everything is OK');
|
short_msg => 'Everything is OK');
|
||||||
|
|
||||||
$self->manage_selection();
|
$self->manage_selection();
|
||||||
|
|
||||||
foreach my $name (sort(keys %{$self->{result}})) {
|
foreach my $name (sort(keys %{$self->{result}})) {
|
||||||
$msg = sprintf("Trunk: %s %s", $self->{result}->{$name}->{name}, $self->{result}->{$name}->{status});
|
if (defined($self->{result}->{$name}->{value}) && defined($self->{result}->{$name}->{unit}))
|
||||||
$self->{output}->perfdata_add(label => $self->{result}->{$name}->{name},
|
{
|
||||||
value => $self->{result}->{$name}->{value}.$self->{result}->{$name}->{unit},
|
$self->{result}->{$name}->{status} = $self->{perfdata}->threshold_check(value => $self->{result}->{$name}->{value},
|
||||||
# keep this lines for future upgrade of this plugin
|
threshold => [{ label => 'critical', exit_litteral => 'critical' },
|
||||||
#warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
|
{ label => 'warning', exit_litteral => 'warning' }]);
|
||||||
#critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
|
$self->{output}->perfdata_add(label => $self->{result}->{$name}->{name},
|
||||||
min => 0);
|
value => $self->{result}->{$name}->{value}.$self->{result}->{$name}->{unit},
|
||||||
if (!$self->{output}->is_status(value => $self->{result}->{$name}->{status}, compare => 'ok', litteral => 1)) {
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||||
|
min => 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$self->{output}->is_status(value => $self->{result}->{$name}->{status}, compare => 'ok', litteral => 1))
|
||||||
|
{
|
||||||
|
$msg = sprintf("Trunk: %s", $self->{result}->{$name}->{name});
|
||||||
$self->{output}->output_add(severity => $self->{result}->{$name}->{status},
|
$self->{output}->output_add(severity => $self->{result}->{$name}->{status},
|
||||||
short_msg => $msg);
|
short_msg => $msg);
|
||||||
|
if ($self->{result}->{$name}->{realstatus} eq 'Unreachable')
|
||||||
|
{
|
||||||
|
$self->{output}->output_add(long_msg => sprintf("%s : %s", $self->{result}->{$name}->{name}, $self->{result}->{$name}->{realstatus}));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$self->{output}->output_add(long_msg => sprintf("%s : %s", $self->{result}->{$name}->{name}, $self->{result}->{$name}->{value}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +219,14 @@ Show peers for different protocols.
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
|
=item B<--warning>
|
||||||
|
|
||||||
|
Threshold warning.
|
||||||
|
|
||||||
|
=item B<--critical>
|
||||||
|
|
||||||
|
Threshold critical.
|
||||||
|
|
||||||
=item B<--remote>
|
=item B<--remote>
|
||||||
|
|
||||||
Execute command remotely; can be 'ami' or 'ssh' (default: ssh).
|
Execute command remotely; can be 'ami' or 'ssh' (default: ssh).
|
||||||
|
|
|
@ -93,7 +93,7 @@ sub run {
|
||||||
}
|
}
|
||||||
|
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $value,
|
my $exit_code = $self->{perfdata}->threshold_check(value => $value,
|
||||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
$self->{output}->perfdata_add(label => 'Calls',
|
$self->{output}->perfdata_add(label => 'Calls',
|
||||||
value => $value,
|
value => $value,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
|
|
|
@ -87,6 +87,10 @@ sub check_options {
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critontrunk} . "'.");
|
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critontrunk} . "'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
if (!defined($self->{option_results}->{trunkusernamelist})) {
|
||||||
|
$self->{output}->add_option_msg(short_msg => "trunkusernamelist must be defined.");
|
||||||
|
$self->{output}->option_exit();
|
||||||
|
}
|
||||||
|
|
||||||
$self->{statefile_value}->check_options(%options);
|
$self->{statefile_value}->check_options(%options);
|
||||||
}
|
}
|
||||||
|
@ -129,9 +133,6 @@ sub run {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#$result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1);
|
|
||||||
#my $astConfigCallsActive = $result->{$oid_astConfigCallsActive};
|
|
||||||
|
|
||||||
# compute status based on total number of active calls
|
# compute status based on total number of active calls
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $astConfigCallsActive,
|
my $exit_code = $self->{perfdata}->threshold_check(value => $astConfigCallsActive,
|
||||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
|
|
Loading…
Reference in New Issue