-
Notifications
You must be signed in to change notification settings - Fork 91
Add --category option #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Add --category option #1012
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -35,11 +35,12 @@ sub isEnabled { | |||||
# Add a GLPI client to each param with a category and a use property | ||||||
# and if related category is not disabled | ||||||
my %disabled = map { $_ => 1 } @{$self->{config}->{'no-category'}}; | ||||||
my %enabled = map { $_ => 1 } @{$self->{config}->{'category'}}; | ||||||
my @params; | ||||||
my $cant_load_glpi_client = 0; | ||||||
foreach my $param (@{$tasks->{inventory}->{params}}) { | ||||||
my @validated; | ||||||
if (!$param->{category} || $disabled{$param->{category}}) { | ||||||
if (!$param->{category} || $disabled{$param->{category}} || (%enabled && ! exists $enabled{ $param->{category} })) { | ||||||
} elsif ($param->{params_id}) { | ||||||
# Here we must handle the case of remotely triggered events | ||||||
my @categories = map { trimWhitespace($_) } split(/,+/, $param->{category}); | ||||||
|
@@ -154,6 +155,23 @@ sub run { | |||||
$self->{disabled} = { | ||||||
map { $_ => 1 } @{$self->{config}->{'no-category'}} | ||||||
}; | ||||||
$self->{enabled} = { | ||||||
map { $_ => 1 } @{$self->{config}->{'category'}} | ||||||
}; | ||||||
|
||||||
if (keys(%{$self->{enabled}})) { | ||||||
# Be sure at least bios and hardware category are enabled via category option | ||||||
foreach my $category (qw(bios hardware)) { | ||||||
$self->{logger}->debug("$category not enabled, forcing as it is required") | ||||||
unless $self->{enabled}->{$category}; | ||||||
$self->{enabled}->{$category} = 1; | ||||||
} | ||||||
# Software category requires os to be enabled too | ||||||
if ($self->{enabled}->{software} && !$self->{enabled}->{os}) { | ||||||
$self->{logger}->debug("Forcing os category as required by software one") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My apologies, one char is missing at the end here:
Suggested change
|
||||||
$self->{enabled}->{os} = 1; | ||||||
} | ||||||
} | ||||||
|
||||||
# Support inventory event | ||||||
if ($event && !$self->setupEvent()) { | ||||||
|
@@ -207,7 +225,7 @@ sub setupEvent { | |||||
|
||||||
# Support partial event with category defined only if partial | ||||||
if ($event->partial && $event->category) { | ||||||
my %keep = map { lc($_) => 1 } grep { ! $self->{disabled}->{$_} } split(/,+/, $event->category); | ||||||
my %keep = map { lc($_) => 1 } grep { ! $self->{disabled}->{$_} && (!%{ $self->{enabled} } || $self->{enabled}->{$_}) } split(/,+/, $event->category); | ||||||
unless (keys(%keep)) { | ||||||
$self->{logger}->info("Nothing to inventory on partial inventory event"); | ||||||
return 0; | ||||||
|
@@ -413,7 +431,7 @@ sub _initModulesList { | |||||
if (defined(*{$module."::category"})) { | ||||||
no strict 'refs'; ## no critic (ProhibitNoStrict) | ||||||
my $category = &{$module."::category"}(); | ||||||
if ($category && $self->{disabled}->{$category}) { | ||||||
if ($category && ($self->{disabled}->{$category} || ( %{ $self->{enabled} } && !exists $self->{enabled}->{$category} ))) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I would prefer a |
||||||
$logger->debug2("module $module disabled: '$category' category disabled"); | ||||||
$self->{modules}->{$module}->{enabled} = 0; | ||||||
next; | ||||||
|
@@ -532,6 +550,7 @@ sub _runModule { | |||||
datadir => $self->{datadir}, | ||||||
inventory => $self->{inventory}, | ||||||
no_category => $self->{disabled}, | ||||||
category => $self->{enabled}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed, no module uses |
||||||
logger => $self->{logger}, | ||||||
registry => $self->{registry}, | ||||||
params => $self->{params}, | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.