enh(citrix) Get licenses by name/PLD

This commit is contained in:
UrBnW 2020-07-28 10:12:16 +02:00
parent 3531760012
commit 71f21194f7
1 changed files with 31 additions and 19 deletions

View File

@ -29,7 +29,7 @@ use Win32::OLE;
sub custom_license_output { sub custom_license_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Licenses Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$self->{result_values}->{total}, $self->{result_values}->{total},
$self->{result_values}->{used}, $self->{result_values}->{used},
$self->{result_values}->{prct_used}, $self->{result_values}->{prct_used},
@ -39,35 +39,41 @@ sub custom_license_output {
return $msg; return $msg;
} }
sub prefix_license_output {
my ($self, %options) = @_;
return "License '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'license', type => 1, cb_prefix_output => 'prefix_license_output', message_multiple => 'All licenses are ok', skipped_code => { -10 => 1 } },
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{license} = [
{ label => 'usage', nlabel => 'licenses.usage.count', set => { { label => 'usage', nlabel => 'licenses.usage.count', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_license_output'), closure_custom_output => $self->can('custom_license_output'),
perfdatas => [ perfdatas => [
{ value => 'used', template => '%d', min => 0, max => 'total' }, { value => 'used', template => '%d', min => 0, max => 'total', label_extra_instance => 1, instance_use => 'display' },
], ],
} }
}, },
{ label => 'usage-free', display_ok => 0, nlabel => 'licenses.free.count', set => { { label => 'usage-free', display_ok => 0, nlabel => 'licenses.free.count', set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_license_output'), closure_custom_output => $self->can('custom_license_output'),
perfdatas => [ perfdatas => [
{ value => 'free', template => '%d', min => 0, max => 'total' }, { value => 'free', template => '%d', min => 0, max => 'total', label_extra_instance => 1, instance_use => 'display' },
], ],
} }
}, },
{ label => 'usage-prct', display_ok => 0, nlabel => 'licenses.usage.percentage', set => { { label => 'usage-prct', display_ok => 0, nlabel => 'licenses.usage.percentage', set => {
key_values => [ { name => 'prct_used' } ], key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
output_template => 'Licenses Used : %.2f %%', closure_custom_output => $self->can('custom_license_output'),
perfdatas => [ perfdatas => [
{ value => 'prct_used', template => '%.2f', min => 0, max => 100, unit => '%' }, { value => 'prct_used', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
], ],
} }
}, },
@ -80,6 +86,7 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'filter:s' => { name => 'filter' }
}); });
return $self; return $self;
@ -94,22 +101,23 @@ sub manage_selection {
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{global} = { total => 0, used => 0 }; my $query = "Select PLD,InUseCount,Count from Citrix_GT_License_Pool";
my $query = "Select InUseCount,Count from Citrix_GT_License_Pool";
my $resultset = $wmi->ExecQuery($query); my $resultset = $wmi->ExecQuery($query);
foreach my $obj (in $resultset) { foreach my $obj (in $resultset) {
$self->{global}->{used} += $obj->{InUseCount}; if (!defined($self->{option_results}->{filter}) || ($obj->{PLD} =~ /$self->{option_results}->{filter}/i)) {
$self->{global}->{total} += $obj->{Count}; $self->{license}->{$obj->{PLD}}->{display} = $obj->{PLD};
$self->{license}->{$obj->{PLD}}->{used} = $obj->{InUseCount};
$self->{license}->{$obj->{PLD}}->{total} = $obj->{Count};
$self->{license}->{$obj->{PLD}}->{prct_used} = $obj->{InUseCount} * 100 / $obj->{Count};
$self->{license}->{$obj->{PLD}}->{prct_free} = 100 - $self->{license}->{$obj->{PLD}}->{prct_used};
$self->{license}->{$obj->{PLD}}->{free} = $obj->{Count} - $obj->{InUseCount};
}
} }
if ($self->{global}->{total} == 0) { if (!scalar keys %{$self->{license}}) {
$self->{output}->add_option_msg(short_msg => 'Cant get licenses count'); $self->{output}->add_option_msg(short_msg => 'Cant get licenses count');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{global}->{prct_used} = $self->{global}->{used} * 100 / $self->{global}->{total};
$self->{global}->{prct_free} = 100 - $self->{global}->{prct_used};
$self->{global}->{free} = $self->{global}->{total} - $self->{global}->{used};
} }
1; 1;
@ -122,6 +130,10 @@ Check Citrix licenses.
=over 8 =over 8
=item B<--filter>
Filter license name.
=item B<--warning-*> B<--critical-*> =item B<--warning-*> B<--critical-*>
Thresholds. Thresholds.