Fixed ha Perl Warning that maybe gave problems with parse the output

This commit is contained in:
mdtrooper 2015-01-15 16:36:22 +01:00
parent 774afe902c
commit b9f0bf17f5

View File

@ -2997,7 +2997,7 @@ sub cli_get_agent_modules() {
exist_check($id_agent,'agent',$agent_name); exist_check($id_agent,'agent',$agent_name);
my $modules = pandora_get_agent_modules ($dbh, $id_agent); my $modules = pandora_get_agent_modules ($dbh, $id_agent);
if(scalar(@{$modules}) == 0) { if(scalar(@{$modules}) == 0) {
print_log "[INFO] The agent '$agent_name' have not modules\n\n"; print_log "[INFO] The agent '$agent_name' have not modules\n\n";
} }
@ -3008,49 +3008,56 @@ sub cli_get_agent_modules() {
} }
} }
############################################################################## ########################################################################
# Show all the modules of a policy # Show all the modules of a policy
# Related option: --get_policy_modules # Related option: --get_policy_modules
############################################################################## ########################################################################
sub cli_get_policy_modules() { sub cli_get_policy_modules() {
my $policy_name = @ARGV[2]; my $policy_name = @ARGV[2];
my $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]); my $policy_id = enterprise_hook('get_policy_id',
exist_check($policy_id,'policy',$policy_name); [$dbh, safe_input($policy_name)]);
exist_check($policy_id, 'policy', $policy_name);
my $policy_modules = enterprise_hook('get_policy_modules',[$dbh, $policy_id]); my $policy_modules = enterprise_hook(
exist_check(scalar(@{$policy_modules})-1,'modules in policy',$policy_name); 'get_policy_modules', [$dbh, $policy_id]);
if (defined($policy_modules)) {
exist_check(scalar(@{$policy_modules}) - 1, 'modules in policy',
$policy_name);
}
print "id_policy_module, module_name\n"; print "id_policy_module, module_name\n";
foreach my $module (@{$policy_modules}) { foreach my $module (@{$policy_modules}) {
print $module->{'id'}.",".safe_output($module->{'name'})."\n"; print $module->{'id'} . "," . safe_output($module->{'name'}) . "\n";
} }
} }
############################################################################## ########################################################################
# Show all the policies (without parameters) or the policies of given agent # Show all the policies (without parameters) or the policies of given
# agent.
# Related option: --get_policies # Related option: --get_policies
############################################################################## ########################################################################
sub cli_get_policies() { sub cli_get_policies() {
my $agent_name = @ARGV[2]; my $agent_name = @ARGV[2];
my $policies; my $policies;
if(defined($agent_name)) { if (defined($agent_name)) {
my $id_agent = get_agent_id($dbh,$agent_name); my $id_agent = get_agent_id($dbh,$agent_name);
exist_check($id_agent,'agent',$agent_name); exist_check($id_agent,'agent',$agent_name);
$policies = enterprise_hook('get_agent_policies',[$dbh,$id_agent]); $policies = enterprise_hook('get_agent_policies', [$dbh,$id_agent]);
if(scalar(@{$policies}) == 0) { if (scalar(@{$policies}) == 0) {
print_log "[INFO] No policies found on agent '$agent_name'\n\n"; print_log "[INFO] No policies found on agent '$agent_name'\n\n";
exit; exit;
} }
} }
else { else {
$policies = enterprise_hook('get_policies',[$dbh]); $policies = enterprise_hook('get_policies', [$dbh]);
if(scalar(@{$policies}) == 0) { if (scalar(@{$policies}) == 0) {
print_log "[INFO] No policies found\n\n"; print_log "[INFO] No policies found\n\n";
exit; exit;
} }