add device mode versa

This commit is contained in:
garnier-quentin 2020-06-04 13:37:07 +02:00
parent c1f4328b25
commit 10686700fe
2 changed files with 151 additions and 106 deletions

View File

@ -254,11 +254,11 @@ sub cache_versa_entities {
sub get_organizations {
my ($self, %options) = @_;
my $datas = $self->bouchon(file => '/home/qgarnier/clients/plugins/todo/versa/Versa-Centreon/organizations.json');
#my $datas = $self->bouchon(file => '/home/qgarnier/clients/plugins/todo/versa/Versa-Centreon/organizations.json');
$self->cache_versa_entities();
return $self->{cache_organizations} if (!defined($options{disable_cache}) || $options{disable_cache} == 0);
#my $datas = $self->request_api(endpoint => '/api/config/nms/provider/organizations/organization');
my $datas = $self->request_api(endpoint => '/api/config/nms/provider/organizations/organization');
my $results = { entries => {}, names => { } };
@ -275,11 +275,11 @@ sub get_organizations {
sub get_appliances {
my ($self, %options) = @_;
my $datas = $self->bouchon(file => '/home/qgarnier/clients/plugins/todo/versa/Versa-Centreon/appliances.json');
#my $datas = $self->bouchon(file => '/home/qgarnier/clients/plugins/todo/versa/Versa-Centreon/appliances.json');
$self->cache_versa_entities();
return $self->{cache_appliances} if (!defined($options{disable_cache}) || $options{disable_cache} == 0);
#my $datas = $self->request_api(endpoint => '/api/config/nms/provider/appliances/appliance');
my $datas = $self->request_api(endpoint => '/api/config/nms/provider/appliances/appliance');
my $results = { entries => {}, names => { }, types => { } };
@ -298,7 +298,7 @@ sub get_appliances {
sub execute {
my ($self, %options) = @_;
return $self->bouchon(file => '/home/qgarnier/clients/plugins/todo/versa/Versa-Centreon/appliance_status.json');
#return $self->bouchon(file => '/home/qgarnier/clients/plugins/todo/versa/Versa-Centreon/plop.json');
$self->cache_versa_entities();
my $results = $self->request_api(

View File

@ -25,18 +25,45 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use Digest::MD5 qw(md5_hex);
use centreon::plugins::misc;
sub custom_status_output {
my ($self, %options) = @_;
return 'status: ' . $self->{result_values}->{status};
return sprintf(
'status services: %s [ping: %s] [sync: %s] [path: %s] [controller: %s]',
$self->{result_values}->{services_status},
$self->{result_values}->{ping_status},
$self->{result_values}->{sync_status},
$self->{result_values}->{path_status},
$self->{result_values}->{controller_status}
);
}
sub custom_link_status_output {
sub custom_memory_output {
my ($self, %options) = @_;
return 'status: ' . $self->{result_values}->{link_status};
return sprintf(
'memory total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)',
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}),
$self->{result_values}->{prct_used},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}),
$self->{result_values}->{prct_free}
);
}
sub custom_disk_output {
my ($self, %options) = @_;
return sprintf(
'disk total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)',
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}),
$self->{result_values}->{prct_used},
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}),
$self->{result_values}->{prct_free}
);
}
sub set_counters {
@ -47,9 +74,9 @@ sub set_counters {
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok',
group => [
{ name => 'device_status', type => 0, skipped_code => { -10 => 1 } },
{ name => 'device_connections', type => 0, cb_prefix_output => 'prefix_connection_output', skipped_code => { -10 => 1 } },
{ name => 'device_traffic', type => 0, cb_prefix_output => 'prefix_traffic_output', skipped_code => { -10 => 1, -11 => 1 } },
{ name => 'device_links', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'device_memory', type => 0, skipped_code => { -10 => 1 } },
{ name => 'device_disk', type => 0, skipped_code => { -10 => 1 } },
{ name => 'device_alarms', type => 0, cb_prefix_output => 'prefix_alarm_output', skipped_code => { -10 => 1 } }
]
}
];
@ -59,7 +86,7 @@ sub set_counters {
key_values => [ { name => 'total'} ],
output_template => 'total: %s',
perfdatas => [
{ template => '%s', min => 0, max => 'total' }
{ template => '%s', min => 0 }
]
}
}
@ -67,8 +94,11 @@ sub set_counters {
$self->{maps_counters}->{device_status} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
key_values => [
{ name => 'ping_status' }, { name => 'sync_status' },
{ name => 'services_status' }, { name => 'path_status' },
{ name => 'controller_status' }, { name => 'display' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
@ -76,86 +106,79 @@ sub set_counters {
}
];
$self->{maps_counters}->{device_connections} = [
{ label => 'connections-success', nlabel => 'device.connections.success.count', set => {
key_values => [ { name => 'assoc' }, { name => 'display' } ],
output_template => 'success: %s',
$self->{maps_counters}->{device_memory} = [
{ label => 'memory-usage', nlabel => 'memory.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_memory_output'),
perfdatas => [
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'connections-auth', nlabel => 'device.connections.auth.count', display_ok => 0, set => {
key_values => [ { name => 'auth' }, { name => 'display' } ],
output_template => 'auth: %s',
{ label => 'memory-usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_memory_output'),
perfdatas => [
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'connections-assoc', nlabel => 'device.connections.assoc.count', display_ok => 0, set => {
key_values => [ { name => 'assoc' }, { name => 'display' } ],
output_template => 'assoc: %s',
{ label => 'memory-usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
key_values => [ { name => 'prct_used' }, { name => 'display' } ],
output_template => 'memory used: %.2f %%',
perfdatas => [
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'connections-dhcp', nlabel => 'device.connections.dhcp.count', display_ok => 0, set => {
key_values => [ { name => 'dhcp' }, { name => 'display' } ],
output_template => 'dhcp: %s',
perfdatas => [
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'connections-dns', nlabel => 'device.connections.dns.count', display_ok => 0, set => {
key_values => [ { name => 'dns' }, { name => 'display' } ],
output_template => 'dns: %s',
perfdatas => [
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
{ template => '%.2f', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
$self->{maps_counters}->{device_traffic} = [
{ label => 'traffic-in', nlabel => 'device.traffic.in.bitspersecond', set => {
key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ],
output_template => 'in: %s %s/s',
output_change_bytes => 2,
$self->{maps_counters}->{device_disk} = [
{ label => 'disk-usage', nlabel => 'disk.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_disk_output'),
perfdatas => [
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'traffic-out', nlabel => 'device.traffic.out.bitspersecond', set => {
key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ],
output_template => 'out: %s %s/s',
output_change_bytes => 2,
{ label => 'disk-usage-free', display_ok => 0, nlabel => 'disk.free.bytes', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_disk_output'),
perfdatas => [
{ template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'disk-usage-prct', display_ok => 0, nlabel => 'disk.usage.percentage', set => {
key_values => [ { name => 'prct_used' }, { name => 'display' } ],
output_template => 'disk used: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
$self->{maps_counters}->{device_links} = [
{ label => 'link-status', threshold => 0, set => {
key_values => [ { name => 'link_status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_link_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
$self->{maps_counters}->{device_alarms} = [];
foreach (('critical', 'major', 'minor', 'warning', 'indeterminate')) {
push @{$self->{maps_counters}->{device_alarms}}, {
label => 'alarms-' . $_, nlabel => 'alarms.' . $_ . '.count',
set => {
key_values => [ { name => $_ }, { name => 'display' } ],
output_template => $_ . ': %s',
perfdatas => [
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
};
}
}
sub device_long_output {
my ($self, %options) = @_;
return "checking device '" . $options{instance_value}->{display} . "'";
return "checking device '" . $options{instance_value}->{display} . "' [type: " . $options{instance_value}->{type} . ']';
}
sub prefix_device_output {
@ -170,22 +193,10 @@ sub prefix_global_output {
return 'Devices ';
}
sub prefix_connection_output {
sub prefix_alarm_output {
my ($self, %options) = @_;
return 'connection ';
}
sub prefix_traffic_output {
my ($self, %options) = @_;
return 'traffic ';
}
sub prefix_link_output {
my ($self, %options) = @_;
return "link '" . $options{instance_value}->{display} . "' ";
return 'alarms ';
}
sub new {
@ -199,10 +210,7 @@ sub new {
'filter-device-org-name:s' => { name => 'filter_device_org_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /alerting/i' },
'unknown-link-status:s' => { name => 'unknown_link_status', default => '' },
'warning-link-status:s' => { name => 'warning_link_status', default => '' },
'critical-link-status:s' => { name => 'critical_link_status', default => '%{link_status} =~ /failed/i' }
'critical-status:s' => { name => 'critical_status', default => '%{ping_status} ne "reachable" or %{services_status} ne "good"' }
});
return $self;
@ -213,8 +221,7 @@ sub check_options {
$self->SUPER::check_options(%options);
$self->change_macros(macros => [
'unknown_status', 'warning_status', 'critical_status',
'unknown_link_status', 'warning_link_status', 'critical_link_status'
'unknown_status', 'warning_status', 'critical_status'
]);
}
@ -263,9 +270,62 @@ sub manage_selection {
# "diskSize": "80G",
# "freeDisk": "33G",
#}
# need alarms also
my $appliance_status = $options{custom}->execute(endpoint => '/vnms/dashboard/applianceStatus/' . $device->{uuid});
$self->{devices}->{ $device->{name} } = {
display => $device->{name},
type => $device->{type},
device_status => {
display => $device->{name},
ping_status => lc($appliance_status->{'versanms.ApplianceStatus'}->{'ping-status'}),
sync_status => lc($appliance_status->{'versanms.ApplianceStatus'}->{'sync-status'}),
services_status => lc($appliance_status->{'versanms.ApplianceStatus'}->{'services-status'}),
path_status => lc($appliance_status->{'versanms.ApplianceStatus'}->{'path-status'}),
controller_status => lc($appliance_status->{'versanms.ApplianceStatus'}->{'controller-status'})
},
device_alarms => {
display => $device->{name}
}
};
my $total = centreon::plugins::misc::convert_bytes(
value => $appliance_status->{'versanms.ApplianceStatus'}->{Hardware}->{memory},
pattern => '([0-9\.]+)(.*)$'
);
my $free = centreon::plugins::misc::convert_bytes(
value => $appliance_status->{'versanms.ApplianceStatus'}->{Hardware}->{freeMemory},
pattern => '([0-9\.]+)(.*)$'
);
$self->{devices}->{ $device->{name} }->{device_memory} = {
display => $device->{name},
total => $total,
free => $free,
used => $total - $free,
prct_used => 100 - ($free * 100 / $total),
prct_free => ($free * 100 / $total)
};
$total = centreon::plugins::misc::convert_bytes(
value => $appliance_status->{'versanms.ApplianceStatus'}->{Hardware}->{diskSize},
pattern => '([0-9\.]+)(.*)$'
);
$free = centreon::plugins::misc::convert_bytes(
value => $appliance_status->{'versanms.ApplianceStatus'}->{Hardware}->{freeDisk},
pattern => '([0-9\.]+)(.*)$'
);
$self->{devices}->{ $device->{name} }->{device_disk} = {
display => $device->{name},
total => $total,
free => $free,
used => $total - $free,
prct_used => 100 - ($free * 100 / $total),
prct_free => ($free * 100 / $total)
};
foreach (@{$appliance_status->{'versanms.ApplianceStatus'}->{alarmSummary}->{rows}}) {
$self->{devices}->{ $device->{name} }->{device_alarms}->{ lc($_->{firstColumnValue}) } = $_->{columnValues}->[0];
}
$self->{global}->{total}++;
}
@ -299,37 +359,22 @@ Filter device by organization name (Can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{display}
Can used special variables like: %{ping_status}, %{services_status}, %{sync_status}, %{controller_status}, %{path_status}, %{display}
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
Can used special variables like: %{ping_status}, %{service_sstatus}, %{sync_status}, %{controller_status}, %{path_status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /alerting/i').
Can used special variables like: %{status}, %{display}
=item B<--unknown-link-status>
Set unknown threshold for status.
Can used special variables like: %{link_status}, %{display}
=item B<--warning-link-status>
Set warning threshold for status.
Can used special variables like: %{link_status}, %{display}
=item B<--critical-link-status>
Set critical threshold for status (Default: '%{link_status} =~ /failed/i').
Can used special variables like: %{link_status}, %{display}
Set critical threshold for status (Default: '%{ping_status} ne "reachable" or %{services_status} ne "good"').
Can used special variables like: %{ping_status}, %{services_status}, %{sync_status}, %{controller_status}, %{path_status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total-online', 'total-offline', 'total-alerting',
Can be: 'total',
'traffic-in', 'traffic-out', 'connections-success', 'connections-auth',
'connections-assoc', 'connections-dhcp', 'connections-dns'.