2011-12-29 Sergio Martin <sergio.martin@artica.es>
* lib/PandoraFMS/Core.pm util/pandora_manage.pl: Added two new options to CLI: Create group and add agent to policy git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5308 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
47290d7601
commit
4728404858
|
@ -1,3 +1,9 @@
|
|||
2011-12-29 Sergio Martin <sergio.martin@artica.es>
|
||||
|
||||
* lib/PandoraFMS/Core.pm
|
||||
util/pandora_manage.pl: Added two new options to CLI:
|
||||
Create group and add agent to policy
|
||||
|
||||
2011-12-26 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* lib/PandoraFMS/Core.pm: Discard inc data when a second value
|
||||
|
|
|
@ -42,6 +42,8 @@ Exported Functions:
|
|||
|
||||
=item * C<pandora_create_agent>
|
||||
|
||||
=item * C<pandora_create_group>
|
||||
|
||||
=item * C<pandora_create_incident>
|
||||
|
||||
=item * C<pandora_create_module>
|
||||
|
@ -130,6 +132,7 @@ our @EXPORT = qw(
|
|||
pandora_add_agent_address
|
||||
pandora_audit
|
||||
pandora_create_agent
|
||||
pandora_create_group
|
||||
pandora_create_incident
|
||||
pandora_create_module
|
||||
pandora_create_module_from_hash
|
||||
|
@ -1367,6 +1370,18 @@ sub pandora_update_module_from_hash ($$$$$) {
|
|||
return $module_id;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
## Create a group
|
||||
##########################################################################
|
||||
sub pandora_create_group ($$$$$$$$) {
|
||||
my ($name, $icon, $parent, $propagate, $disabled, $custom_id, $id_skin, $dbh) = @_;
|
||||
|
||||
my $group_id = db_insert ($dbh, 'id_grupo', 'INSERT INTO tgrupo (nombre, icon, parent, propagate, disabled, custom_id, id_skin) VALUES (?, ?, ?, ?, ?, ?, ?)', safe_input($name), $icon,
|
||||
$parent, $propagate, $disabled, $custom_id, $id_skin);
|
||||
|
||||
return $group_id;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
=head2 C<< pandora_create_agent (I<$pa_config>, I<$server_name>, I<$agent_name>, I<$address>, I<$group_id>, I<$parent_id>, I<$os_id>, I<$description>, I<$interval>, I<$dbh>, [I<$timezone_offset>], [I<$longitude>], [I<$latitude>], [I<$altitude>], [I<$position_description>]) >>
|
||||
|
||||
|
|
|
@ -432,6 +432,8 @@ sub help_screen{
|
|||
help_screen_line('--delete_not_policy_modules', '', 'Delete all modules without policy from configuration file');
|
||||
help_screen_line('--apply_policy', '<policy_name>', 'Force apply a policy');
|
||||
help_screen_line('--disable_policy_alerts', '<policy_name>', 'Disable all the alerts of a policy');
|
||||
help_screen_line('--create_group', '<group_name> [<parent_group_name>]', 'Create an agent group');
|
||||
help_screen_line('--add_agent_to_policy', '<agent_name> <policy_name>', 'Add an agent to a policy');
|
||||
print "\n";
|
||||
exit;
|
||||
}
|
||||
|
@ -1347,6 +1349,60 @@ sub cli_disable_policy_alerts() {
|
|||
my $array_pointer_ag = enterprise_hook('pandora_disable_policy_alerts',[$dbh, $policy_id]);
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Add an agent to a policy
|
||||
# Related option: --add_agent_to_policy
|
||||
##############################################################################
|
||||
|
||||
sub cli_policy_add_agent() {
|
||||
my ($agent_name, $policy_name) = @ARGV[2..3];
|
||||
|
||||
my $agent_id = get_agent_id($dbh,$agent_name);
|
||||
exist_check($agent_id,'agent',$agent_name);
|
||||
|
||||
my $policy_id = enterprise_hook('get_policy_id',[$dbh, safe_input($policy_name)]);
|
||||
exist_check($policy_id,'policy',$policy_name);
|
||||
|
||||
# Add the agent to policy
|
||||
my $policy_agent_id = enterprise_hook('pandora_policy_add_agent',[$policy_id, $agent_id, $dbh]);
|
||||
|
||||
if($policy_agent_id == -1) {
|
||||
print "[ERROR] A problem has been ocurred adding agent '$agent_name' to policy '$policy_name'\n\n";
|
||||
}
|
||||
else {
|
||||
print "[INFO] Added agent '$agent_name' to policy '$policy_name'. Is necessary apply the policy to changes take effect.\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Create group
|
||||
# Related option: --create_group
|
||||
##############################################################################
|
||||
|
||||
sub cli_create_group() {
|
||||
my ($group_name,$parent_group_name) = @ARGV[2..3];
|
||||
|
||||
my $group_id = get_group_id($dbh,$group_name);
|
||||
|
||||
non_exist_check($group_id, 'group name', $group_name);
|
||||
|
||||
my $parent_group_id = 0;
|
||||
|
||||
if(defined($parent_group_name)) {
|
||||
$parent_group_id = get_group_id($dbh,$parent_group_name);
|
||||
exist_check($parent_group_id, 'group name', $parent_group_name);
|
||||
}
|
||||
|
||||
$group_id = pandora_create_group ($group_name, '', $parent_group_id, 0, 0, '', 0, $dbh);
|
||||
|
||||
if($group_id == -1) {
|
||||
print "[ERROR] A problem has been ocurred creating group '$group_name'\n\n";
|
||||
}
|
||||
else {
|
||||
print "[INFO] Created group '$group_name'\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Disable alert system globally
|
||||
# Related option: --disable_alerts
|
||||
|
@ -1551,6 +1607,14 @@ sub pandora_manage_main ($$$) {
|
|||
param_check($ltotal, 1);
|
||||
cli_disable_policy_alerts();
|
||||
}
|
||||
elsif ($param eq '--create_group') {
|
||||
param_check($ltotal, 2, 1);
|
||||
cli_create_group();
|
||||
}
|
||||
elsif ($param eq '--add_agent_to_policy') {
|
||||
param_check($ltotal, 2, 0);
|
||||
cli_policy_add_agent();
|
||||
}
|
||||
else {
|
||||
print "[ERROR] Invalid option '$param'.\n\n";
|
||||
$param = '';
|
||||
|
|
Loading…
Reference in New Issue