From 71c4016d6323e5d30ad778bdfc5ebeb24bda4c5e Mon Sep 17 00:00:00 2001 From: Calvo Date: Tue, 10 Oct 2023 17:58:29 +0200 Subject: [PATCH] Case insensitive option for get module id --- pandora_console/pandoradb_data.sql | 1 + pandora_server/lib/PandoraFMS/DB.pm | 13 ++++++++++--- pandora_server/lib/PandoraFMS/DataServer.pm | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 22db03654e..29a54e12c5 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -247,6 +247,7 @@ INSERT INTO `tmodule_group` VALUES (7,'Database'), (8,'Enviromental'), (9,'Users'); +(10,'Security'); UNLOCK TABLES; diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index 22ee1611fa..c0ee332f64 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -814,14 +814,21 @@ sub get_plugin_id ($$) { ########################################################################## ## Return module group ID given the module group name. ########################################################################## -sub get_module_group_id ($$) { - my ($dbh, $module_group_name) = @_; +sub get_module_group_id ($$;$) { + my ($dbh, $module_group_name, $case_insensitve) = @_; + $case_insensitve = 0 unless defined($case_insensitve); + if (!defined($module_group_name) || $module_group_name eq '') { return 0; } - my $rc = get_db_value ($dbh, "SELECT id_mg FROM tmodule_group WHERE name = ?", safe_input($module_group_name)); + my $rc; + if($case_insensitve == 0) { + $rc = get_db_value ($dbh, "SELECT id_mg FROM tmodule_group WHERE name = ?", safe_input($module_group_name)); + } else { + $rc = get_db_value ($dbh, "SELECT id_mg FROM tmodule_group WHERE LOWER(name) = ?", lc(safe_input($module_group_name))); + } return defined ($rc) ? $rc : -1; } diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index b3c32522c6..80e8bb4bd3 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -812,7 +812,7 @@ sub process_module_data ($$$$$$$$$$) { # The group name has to be translated to a group ID if (defined $module_conf->{'module_group'}) { - my $id_group_module = get_module_group_id ($dbh, $module_conf->{'module_group'}); + my $id_group_module = get_module_group_id ($dbh, $module_conf->{'module_group'}, 1); if ( $id_group_module >= 0) { $module_conf->{'id_module_group'} = $id_group_module; }