Skip to content

Conversation

0xff8
Copy link

@0xff8 0xff8 commented Sep 15, 2025

Here is an initial proposal for a new --category option, that if present - will enable only desired metrics and exclude everything else.

As continuation of #1002

@0xff8
Copy link
Author

0xff8 commented Sep 15, 2025

Hi @g-bougard ,

do you want deeper integration (installers + configs + per module check) too ?

Copy link
Member

@g-bougard g-bougard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @0xff8,

I'm still perplex.

I see few problem with this option. It can break inventory if miss-used.

If I merge it, I'll modify few things to force required category. For example, bios and hardware categories are required for glpi and os is required if software category is enabled (see

$keep{hardware} = 1;
).

A problem is still this option could be very long as the default would be: accesslog,antivirus,battery,bios,controller,cpu,database,drive,environment,firewall,hardware,input,licenseinfo,local_group,local_user,lvm,memory,modem,monitor,network,os,port,printer,process,provider,psu,registry,remote_mgmt,rudder,slot,software,sound,storage,usb,user,video,virtualmachine

Maybe another way would be to use a categories option which would support some keywords with preselected category values: full, system, basic, extended or what ever people can think of.

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} ))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would prefer a elsif after the original case with a log telling category is "not enabled" in place of "disabled". This way, we can better understand why a module remains disabled while reading the log.

datadir => $self->{datadir},
inventory => $self->{inventory},
no_category => $self->{disabled},
category => $self->{enabled},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, no module uses category param in their isEnabled method.

@0xff8
Copy link
Author

0xff8 commented Sep 16, 2025

thank you very much for the review @g-bougard !

My initial goal was not to change the existing behavior. So, if no --category parameter is used the glpi-agent behaves as usual. I now see that some fields are required for partial updates, and as a simplest fix, I can declare the new --category option to be used only with the --full option - so partial updates won't be affected at all. Or I can extend current code (and make logic more difficult) and track dependencies in modules for partial updates.

A problem is still this option could be very long as the default would be: accesslog,antivirus,battery,bios,controller,cpu,database,drive,environment,firewall,hardware,input,licenseinfo,local_group,local_user,lvm,memory,modem,monitor,network,os,port,printer,process,provider,psu,registry,remote_mgmt,rudder,slot,software,sound,storage,usb,user,video,virtualmachine

By default, the plan is to request only the privacy-friendly data, i.e. bios,cpu,ram,battery, storage . I see this option as the very precise filter to get as minimum information as necessary. Also, I wanted this option to be compatible with --no-category option , because users know it and its format.

As an example, currently, the command we use looks like: glpi-agent --no-category process,environment,local_user,local_group,accesslog,network,software,video,battery,psu,monitor,user,firewall--server https://internal.server.local --full . it is quite long already :)

I am happy if you share your vision about --category option behavior - my understanding is - it will make partial updates unnecessary, since we already know that we request a very minimal set of the metrics.
Anyway, I am ready to adjust the implementation accordingly to get it merged 🚀

Co-authored-by: Guillaume Bougard <gbougard@teclib.com>
@0xff8
Copy link
Author

0xff8 commented Sep 18, 2025

I haven't finished yet, sorry, I found after merging your changes, not all reports are working properly. Please, let me spent a bit more time on this .

}
# 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")
Copy link
Member

Choose a reason for hiding this comment

The 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->{logger}->debug("Forcing os category as required by software one")
$self->{logger}->debug("Forcing os category as required by software one");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants