2014-04-23 Vanessa Gil <vanessa.gil@artica.es>

* lib/PandoraFMS/Core.pm
	  util/pandora_manage.pl: Added functions
	to CLI.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9802 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
vgilc 2014-04-23 09:55:05 +00:00
parent e496bce528
commit 05b2283069
3 changed files with 232 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2014-04-23 Vanessa Gil <vanessa.gil@artica.es>
* lib/PandoraFMS/Core.pm
util/pandora_manage.pl: Added functions
to CLI.
2014-04-22 Sergio Martin <sergio.martin@artica.es>
* util/pandora_migrate_recon_scripts.pl

View File

@ -208,6 +208,11 @@ our @EXPORT = qw(
load_module_macros
@ServerTypes
$EventStormProtection
pandora_create_custom_graph
pandora_insert_graph_source
pandora_delete_graph_source
pandora_delete_custom_graph
pandora_edit_custom_graph
);
# Some global variables
@ -4324,7 +4329,125 @@ sub load_module_macros ($$) {
}
}
}
##########################################################################
# Create a custom graph
##########################################################################
sub pandora_create_custom_graph ($$$$$$$$$$) {
my ($name,$description,$user,$idGroup,$width,$height,$events,$stacked,$period,$dbh) = @_;
my ($columns, $values) = db_insert_get_values ({'name' => safe_input($name),
'id_user' => $user,
'description' => $description,
'period' => $period,
'width' => $width,
'height' => $height,
'private' => 0,
'id_group' => $idGroup,
'events' => $events,
'stacked' => $stacked
});
my $graph_id = db_insert ($dbh, 'id_graph', "INSERT INTO tgraph $columns", @{$values});
return $graph_id;
}
##########################################################################
# Insert graph source
##########################################################################
sub pandora_insert_graph_source ($$$$) {
my ($id_graph,$module,$weight,$dbh) = @_;
my ($columns, $values) = db_insert_get_values ({'id_graph' => $id_graph,
'id_agent_module' => $module,
'weight' => $weight
});
my $source_id = db_insert ($dbh, 'id_gs', "INSERT INTO tgraph_source $columns", @{$values});
return $source_id;
}
##########################################################################
# Delete graph source
##########################################################################
sub pandora_delete_graph_source ($$;$) {
my ($id_graph,$dbh,$id_module) = @_;
my $result;
if (defined ($id_module)) {
$result = db_do ($dbh, 'DELETE FROM tgraph_source
WHERE id_graph = ?
AND id_agent_module = ?', $id_graph, $id_module);
} else {
$result = db_do ($dbh, 'DELETE FROM tgraph_source WHERE id_graph = ?', $id_graph);
}
return $result;
}
##########################################################################
# Delete custom graph
##########################################################################
sub pandora_delete_custom_graph ($$) {
my ($id_graph,$dbh) = @_;
my $result = db_do ($dbh, 'DELETE FROM tgraph WHERE id_graph = ?', $id_graph);
return $result;
}
##########################################################################
# Edit a custom graph
##########################################################################
sub pandora_edit_custom_graph ($$$$$$$$$$$) {
my ($id_graph,$name,$description,$user,$idGroup,$width,$height,$events,$stacked,$period,$dbh) = @_;
my $graph = get_db_single_row ($dbh, 'SELECT * FROM tgraph
WHERE id_graph = ?', $id_graph);
if ($name eq '') {
$name = $graph->{'name'};
}
if ($description eq '') {
$description = $graph->{'description'};
}
if ($user eq '') {
$user = $graph->{'id_user'};
}
if ($period eq '') {
$period = $graph->{'period'};
}
if ($width eq '') {
$width = $graph->{'width'};
}
if ($height eq '') {
$height = $graph->{'height'};
}
if ($idGroup eq '') {
$idGroup = $graph->{'id_group'};
}
if ($events eq '') {
$events = $graph->{'events'};
}
if ($stacked eq '') {
$stacked = $graph->{'stacked'};
}
my $res = db_do ($dbh, 'UPDATE tgraph SET name = ?, id_user = ?, description = ?, period = ?, width = ?,
height = ?, private = 0, id_group = ?, events = ?, stacked = ?
WHERE id_graph = ?',$name, $user, $description,$period, $width, $height, $idGroup, $events, $stacked, $id_graph);
return $res;
}
# End of function declaration
# End of defined Code

View File

@ -3638,6 +3638,26 @@ sub pandora_manage_main ($$$) {
elsif ($param eq '--set_event_storm_protection') {
param_check($ltotal, 1);
cli_set_event_storm_protection();
}
elsif ($param eq '--create_custom_graph') {
param_check($ltotal, 11);
cli_create_custom_graph();
}
elsif ($param eq '--delete_custom_graph') {
param_check($ltotal, 1);
cli_delete_custom_graph();
}
elsif ($param eq '--edit_custom_graph') {
param_check($ltotal, 10);
cli_edit_custom_graph();
}
elsif ($param eq '--add_modules_to_graph') {
param_check($ltotal, 3);
cli_add_modules_to_graph();
}
elsif ($param eq '--delete_modules_to_graph') {
param_check($ltotal, 3);
cli_delete_modules_to_graph();
}
else {
print_log "[ERROR] Invalid option '$param'.\n\n";
@ -3651,3 +3671,86 @@ sub pandora_manage_main ($$$) {
exit;
}
##############################################################################
# Create a custom graph.
# Related option: --create_custom_graph
##############################################################################
sub cli_create_custom_graph() {
my ($name,$description,$user,$idGroup,$width,$height,$events,$stacked,$period,$modules,$separator) = @ARGV[2..12];
$separator = ($separator ne '') ? $separator : ';';
my @module_array = split($separator, $modules);
$description = ($description ne '') ? safe_input($description) : '';
$width = ($width ne '') ? $width : 550;
$height = ($height ne '') ? $height : 210;
$period = ($period ne '') ? $period : 86400;
$events = ($events ne '') ? $events : 0;
$stacked = ($stacked ne '') ? $stacked : 0;
$idGroup = ($idGroup ne '') ? $idGroup : 0;
my $id_graph = pandora_create_custom_graph($name,$description,$user,$idGroup,$width,$height,$events,$stacked,$period,$dbh);
if ($id_graph != 0) { #~ insert source
if ($modules ne '') {
foreach my $module (@module_array) {
pandora_insert_graph_source($id_graph,$module,1,$dbh);
}
}
}
}
##############################################################################
# Delete a custom graph.
# Related option: --delete_custom_graph
##############################################################################
sub cli_delete_custom_graph () {
my ($id_graph) = @ARGV[2];
my $result = pandora_delete_graph_source($id_graph, $dbh);
pandora_delete_custom_graph($id_graph, $dbh);
}
##############################################################################
# Edit a custom graph.
# Related option: --edit_custom_graph
##############################################################################
sub cli_edit_custom_graph() {
my ($id_graph,$name,$description,$user,$idGroup,$width,$height,$events,$stacked,$period) = @ARGV[2..12];
pandora_edit_custom_graph($id_graph,$name,$description,$user,$idGroup,$width,$height,$events,$stacked,$period,$dbh);
}
sub cli_add_modules_to_graph () {
my ($id_graph,$modules,$separator) = @ARGV[2..4];
$separator = ($separator ne '') ? $separator : ';';
my @module_array = split($separator, $modules);
foreach my $module (@module_array) {
pandora_insert_graph_source($id_graph,$module,1,$dbh);
}
}
sub cli_delete_modules_to_graph () {
my ($id_graph,$modules,$separator) = @ARGV[2..4];
$separator = ($separator ne '') ? $separator : ';';
my @module_array = split($separator, $modules);
foreach my $module (@module_array) {
pandora_delete_graph_source($id_graph, $dbh, $module);
}
}