From d4814c6cc5608a2cc5f9d7cd10f6e389767200dc Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Tue, 28 Jul 2020 10:12:16 +0200 Subject: [PATCH 1/2] enh(citrix) Get licenses by name/PLD --- apps/citrix/local/mode/license.pm | 50 +++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/apps/citrix/local/mode/license.pm b/apps/citrix/local/mode/license.pm index 3db8f64d8..9dbdeadc6 100644 --- a/apps/citrix/local/mode/license.pm +++ b/apps/citrix/local/mode/license.pm @@ -29,7 +29,7 @@ use Win32::OLE; sub custom_license_output { 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}->{used}, $self->{result_values}->{prct_used}, @@ -39,35 +39,41 @@ sub custom_license_output { return $msg; } +sub prefix_license_output { + my ($self, %options) = @_; + + return "License '" . $options{instance_value}->{display} . "' "; +} + sub set_counters { my ($self, %options) = @_; $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 => { - 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'), 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 => { - 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'), 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 => { - key_values => [ { name => 'prct_used' } ], - output_template => 'Licenses Used : %.2f %%', + key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_output => $self->can('custom_license_output'), 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; $options{options}->add_options(arguments => { + 'filter:s' => { name => 'filter' } }); return $self; @@ -94,22 +101,23 @@ sub manage_selection { $self->{output}->option_exit(); } - $self->{global} = { total => 0, used => 0 }; - my $query = "Select InUseCount,Count from Citrix_GT_License_Pool"; + my $query = "Select PLD,InUseCount,Count from Citrix_GT_License_Pool"; my $resultset = $wmi->ExecQuery($query); foreach my $obj (in $resultset) { - $self->{global}->{used} += $obj->{InUseCount}; - $self->{global}->{total} += $obj->{Count}; + if (!defined($self->{option_results}->{filter}) || ($obj->{PLD} =~ /$self->{option_results}->{filter}/i)) { + $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}->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; @@ -122,6 +130,10 @@ Check Citrix licenses. =over 8 +=item B<--filter> + +Filter license name. + =item B<--warning-*> B<--critical-*> Thresholds. From efadbaf027bc57e1fa6dea79e483d654eccd59f2 Mon Sep 17 00:00:00 2001 From: UrBnW <40244829+UrBnW@users.noreply.github.com> Date: Tue, 28 Jul 2020 10:50:42 +0200 Subject: [PATCH 2/2] enh(citrix) Get licenses by name/PLD --- apps/citrix/local/mode/license.pm | 49 ++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/apps/citrix/local/mode/license.pm b/apps/citrix/local/mode/license.pm index 9dbdeadc6..ce9c58dcb 100644 --- a/apps/citrix/local/mode/license.pm +++ b/apps/citrix/local/mode/license.pm @@ -49,11 +49,43 @@ sub set_counters { my ($self, %options) = @_; $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} = [ + { label => 'total-count', nlabel => 'licenses.count', set => { + key_values => [ { name => 'count' } ], + perfdatas => [ + { value => 'count', template => '%d' }, + ], + } + }, + { label => 'total-usage', nlabel => 'licenses.usage.count', set => { + key_values => [ { name => 'used' }, { name => 'total' } ], + perfdatas => [ + { value => 'used', template => '%d', min => 0, max => 'total' }, + ], + } + }, + { label => 'total-usage-free', display_ok => 0, nlabel => 'licenses.free.count', set => { + key_values => [ { name => 'free' }, { name => 'total' } ], + perfdatas => [ + { value => 'free', template => '%d', min => 0, max => 'total' }, + ], + } + }, + { label => 'total-usage-prct', display_ok => 0, nlabel => 'licenses.usage.percentage', set => { + key_values => [ { name => 'prct_used' } ], + perfdatas => [ + { value => 'prct_used', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; + $self->{maps_counters}->{license} = [ - { label => 'usage', nlabel => 'licenses.usage.count', set => { + { label => 'usage', nlabel => 'license.usage.count', set => { key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_license_output'), perfdatas => [ @@ -61,7 +93,7 @@ sub set_counters { ], } }, - { label => 'usage-free', display_ok => 0, nlabel => 'licenses.free.count', set => { + { label => 'usage-free', display_ok => 0, nlabel => 'license.free.count', set => { key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_license_output'), perfdatas => [ @@ -69,7 +101,7 @@ sub set_counters { ], } }, - { label => 'usage-prct', display_ok => 0, nlabel => 'licenses.usage.percentage', set => { + { label => 'usage-prct', display_ok => 0, nlabel => 'license.usage.percentage', set => { key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], closure_custom_output => $self->can('custom_license_output'), perfdatas => [ @@ -101,10 +133,14 @@ sub manage_selection { $self->{output}->option_exit(); } + $self->{global} = { count => 0, total => 0, used => 0 }; my $query = "Select PLD,InUseCount,Count from Citrix_GT_License_Pool"; my $resultset = $wmi->ExecQuery($query); foreach my $obj (in $resultset) { if (!defined($self->{option_results}->{filter}) || ($obj->{PLD} =~ /$self->{option_results}->{filter}/i)) { + $self->{global}->{count}++; + $self->{global}->{used} += $obj->{InUseCount}; + $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}; @@ -118,6 +154,10 @@ sub manage_selection { $self->{output}->add_option_msg(short_msg => 'Cant get licenses count'); $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; @@ -137,7 +177,8 @@ Filter license name. =item B<--warning-*> B<--critical-*> Thresholds. -Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). +Can be: 'usage', 'usage-free, 'usage-prct' (%), +'total-usage', 'total-count', 'total-usage-free, 'total-usage-prct' (%). =back