Private GIT

Skip to content
Snippets Groups Projects
Commit 59795437 authored by Kevin Duret's avatar Kevin Duret
Browse files

Merge branch 'easy-broker' into 2.7.x

parents 50b85e1c bf6dd237
No related branches found
No related tags found
No related merge requests found
......@@ -410,14 +410,20 @@ class CentreonConfigCentreonBroker
/*
* Insert the Centreon Broker configuration
*/
$query = "INSERT INTO cfg_centreonbroker (config_name, config_filename, config_write_timestamp, config_write_thread_id, config_activate, ns_nagios_server, event_queue_max_size) VALUES (
$query = "INSERT INTO cfg_centreonbroker "
. "(config_name, config_filename, ns_nagios_server, config_activate, config_write_timestamp, config_write_thread_id, stats_activate, correlation_activate, retention_path, event_queue_max_size) "
. "VALUES (
'" . $this->db->escape($values['name']) . "',
'" . $this->db->escape($values['filename']) . "',
" . $this->db->escape($values['ns_nagios_server']) . ",
'" . $this->db->escape($values['activate']['activate']) . "',
'" . $this->db->escape($values['write_timestamp']['write_timestamp']) . "',
'" . $this->db->escape($values['write_thread_id']['write_thread_id']) . "',
'" . $this->db->escape($values['activate']['activate']) . "',
" . $this->db->escape($values['ns_nagios_server']) . ",
".$this->db->escape((int)$this->checkEventMaxQueueSizeValue($values['event_queue_max_size'])).")";
'" . $this->db->escape($values['stats_activate']['stats_activate']) . "',
'" . $this->db->escape($values['correlation_activate']['correlation_activate']) . "',
'" . $this->db->escape($values['retention_path']) . "',
".$this->db->escape((int)$this->checkEventMaxQueueSizeValue($values['event_queue_max_size']))
. ")";
if (PEAR::isError($this->db->query($query))) {
return false;
}
......@@ -451,10 +457,13 @@ class CentreonConfigCentreonBroker
$query = "UPDATE cfg_centreonbroker SET
config_name = '" . $this->db->escape($values['name']) . "',
config_filename = '" . $this->db->escape($values['filename']) . "',
ns_nagios_server = " . $this->db->escape($values['ns_nagios_server']) . ",
config_activate = '" . $this->db->escape($values['activate']['activate']) . "',
config_write_timestamp = '" . $this->db->escape($values['write_timestamp']['write_timestamp']) . "',
config_write_thread_id = '" . $this->db->escape($values['write_thread_id']['write_thread_id']) . "',
config_activate = '" . $this->db->escape($values['activate']['activate']) . "',
ns_nagios_server = " . $this->db->escape($values['ns_nagios_server']) . ",
stats_activate = '" . $this->db->escape($values['stats_activate']['stats_activate']) . "',
correlation_activate = '" . $this->db->escape($values['correlation_activate']['correlation_activate']) . "',
retention_path = '" . $this->db->escape($values['retention_path']) . "',
event_queue_max_size = ".(int)$this->db->escape($this->checkEventMaxQueueSizeValue($values['event_queue_max_size']))."
WHERE config_id = " . $id;
if (PEAR::isError($this->db->query($query))) {
......
......@@ -12,7 +12,10 @@ class Broker extends AbstractObjectXML {
config_write_timestamp,
config_write_thread_id,
ns_nagios_server,
stats_activate,
correlation_activate,
event_queue_max_size,
retention_path,
command_file
';
protected $attributes_select_parameters = '
......@@ -64,8 +67,14 @@ class Broker extends AbstractObjectXML {
foreach ($result as $row) {
$this->generate_filename = $row['config_filename'];
$object = array();
$flow_count = 0;
// Base parameters
$config_name = $row['config_name'];
$retention_path = $row['retention_path'];
$stats_activate = $row['stats_activate'];
$correlation_activate = $row['correlation_activate'];
# Base parameters
$object['instance'] = $this->engine['id'];
$object['instance_name'] = $this->engine['name'];
$object['module_directory'] = $this->engine['broker_modules_path'];
......@@ -74,14 +83,11 @@ class Broker extends AbstractObjectXML {
$object['event_queue_max_size'] = $row['event_queue_max_size'];
$object['command_file'] = $row['command_file'];
// Flow parameters
$this->stmt_broker_parameters->bindParam(':config_id', $row['config_id'], PDO::PARAM_INT);
$this->stmt_broker_parameters->execute();
$resultParameters = $this->stmt_broker_parameters->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$org = array();
$previousValue = '';
$count = 0;
# Flow parameters
foreach ($resultParameters as $key => $value) {
foreach ($value as $subvalue) {
if (in_array($subvalue['config_key'], $this->exclude_parameters) || trim($subvalue['config_value']) == '') {
......@@ -91,10 +97,50 @@ class Broker extends AbstractObjectXML {
} else {
$object[$subvalue['config_group_id']][$key][$subvalue['config_key']] = $subvalue['config_value'];
}
$flow_count++;
}
}
# Failover parameters
foreach ($object as &$subvalue) {
foreach ($subvalue as $config_type => &$flow) {
if ($config_type == 'output' && isset($flow['name']) && !isset($flow['failover']) && isset($flow['type']) && $flow['type'] != 'file') {
$flow['failover'] = $flow['name'] . '-' . $config_type . '-failover';
$object[$flow_count][$config_type] = array(
'type' => 'file',
'name' => $flow['name'] . '-' . $config_type . '-failover',
'path' => $retention_path . '/' . $config_name . '_' . $flow['name'] . '.retention',
'protocol' => 'bbdo',
'compression' => 'auto',
'max_size' => '104857600'
);
$flow_count++;
}
}
}
// Generate file
# Temporary parameters
$object[$flow_count]['temporary'] = array(
'type' => 'file',
'name' => $config_name . '-temporary',
'path' => $retention_path . '/' . $config_name . '.temporary',
'protocol' => 'bbdo',
'compression' => 'auto',
'max_size' => '104857600'
);
$flow_count++;
# Stats parameters
if ($stats_activate == '1') {
$object[$flow_count]['stats'] = array(
'type' => 'stats',
'name' => $config_name . '-stats',
'fifo' => $retention_path . '/' . $config_name . '.stats',
);
$flow_count++;
}
# Generate file
$this->generateFile($object, true, 'centreonBroker');
$this->writeFile($this->backend_instance->getPath());
}
......
......@@ -119,7 +119,9 @@
function getCentreonBrokerInformation($id) {
global $pearDB;
$query = "SELECT config_name, config_filename, config_write_timestamp, config_write_thread_id, config_activate, ns_nagios_server, event_queue_max_size
$query = "SELECT config_name, config_filename, ns_nagios_server, stats_activate, correlation_activate,
config_write_timestamp, config_write_thread_id, config_activate, event_queue_max_size, retention_path,
buffering_timeout, retry_interval
FROM cfg_centreonbroker
WHERE config_id = " . $id;
$res = $pearDB->query($query);
......@@ -138,11 +140,16 @@
"id" => $id,
"name" => $row['config_name'],
"filename" => $row['config_filename'],
"ns_nagios_server" => $row['ns_nagios_server'],
"activate" => $row['config_activate'],
"stats_activate" => $row['stats_activate'],
"correlation_activate" => $row['correlation_activate'],
"write_timestamp" => $row['config_write_timestamp'],
"write_thread_id" => $row['config_write_thread_id'],
"activate" => $row['config_activate'],
"ns_nagios_server" => $row['ns_nagios_server'],
"event_queue_max_size" => $row['event_queue_max_size']
"event_queue_max_size" => $row['event_queue_max_size'],
"retention_path" => $row['retention_path'],
"buffering_timeout" => $row['buffering_timeout'],
"retry_interval" => $row['retry_interval']
);
}
......
......@@ -18,22 +18,30 @@
</div>
<div id='tab1' class='tab'>
<table class="formTable table">
<tr class="ListHeader">
<td class="FormHeader" colspan="2">
<h3>| {$form.header.title}</h3>
<tr class="list_lvl_1">
<td class="ListColLvl1_name" colspan="2">
<h4>{$centreonbroker_main_options}</h4>
</td>
</tr>
<tr class="list_one"><td class="FormRowField">{$form.ns_nagios_server.label}</td><td class="FormRowValue">{$form.ns_nagios_server.html}</td></tr>
<tr class="list_two"><td class="FormRowField">{$form.name.label}</td><td class="FormRowValue">{$form.name.html}</td></tr>
<tr class="list_one"><td class="FormRowField">{$form.filename.label}</td><td class="FormRowValue">{$form.filename.html}</td></tr>
<tr class="list_two"><td class="FormRowField">{$form.retention_path.label}</td><td class="FormRowValue">{$form.retention_path.html}</td></tr>
<tr class="list_one"><td class="FormRowField">{$form.activate.label}</td><td class="FormRowValue">{$form.activate.html}</td></tr>
<tr class="list_lvl_1">
<td class="ListColLvl1_name" colspan="2">
<h4>{$centreonbroker_configuration}</h4>
<h4>{$centreonbroker_log_options}</h4>
</td>
</tr>
<tr class="list_one"><td class="FormRowField">{$form.name.label}</td><td class="FormRowValue">{$form.name.html}</td></tr>
<tr class="list_two"><td class="FormRowField">{$form.filename.label}</td><td class="FormRowValue">{$form.filename.html}</td></tr>
<tr class="list_one"><td class="FormRowField">{$form.write_timestamp.label}</td><td class="FormRowValue">{$form.write_timestamp.html}</td></tr>
<tr class="list_two"><td class="FormRowField">{$form.write_thread_id.label}</td><td class="FormRowValue">{$form.write_thread_id.html}</td></tr>
<tr class="list_one"><td class="FormRowField">{$form.activate.label}</td><td class="FormRowValue">{$form.activate.html}</td></tr>
<tr class="list_two"><td class="FormRowField">{$form.ns_nagios_server.label}</td><td class="FormRowValue">{$form.ns_nagios_server.html}</td></tr>
<tr class="list_lvl_1">
<td class="ListColLvl1_name" colspan="2">
<h4>{$centreonbroker_advanced_options}</h4>
</td>
</tr>
<tr class="list_one"><td class="FormRowField">{$form.stats_activate.label}</td><td class="FormRowValue">{$form.stats_activate.html}</td></tr>
<tr class="list_two"><td class="FormRowField">{$form.correlation_activate.label}</td><td class="FormRowValue">{$form.correlation_activate.html}</td></tr>
<tr class="list_one"><td class="FormRowField">{$form.event_queue_max_size.label}</td><td class="FormRowValue">{$form.event_queue_max_size.html}</td></tr>
<tr class="list_two"><td class="FormRowField">{$form.command_file.label}</td><td class="FormRowValue">{$form.command_file.html}</td></tr>
<tr class="list_lvl_2"><td class="ListColLvl2_name" colspan="2">{$form.required._note}</td></tr>
......@@ -43,10 +51,6 @@
<div id='tab{math equation="x + y" x=$smarty.foreach.tabForeach2.index y=2}' class='tab'>
<table class="formTable table" id="{$tab.id}">
<tbody id="{$tab.id}_0">
<tr class="ListHeader">
<td class="FormHeader" colspan="2">
<h3>| {$form.header.title}</h3>
</td>
</tr>
<tr class="list_lvl_1">
<td class="ListColLvl1_name" colspan="2">
......
......@@ -91,11 +91,15 @@ $tpl = initSmartyTpl($path, $tpl);
/*
* TAB 1 - General informations
*/
$tpl->assign('centreonbroker_configuration', _("Centreon Broker information"));
$tpl->assign('centreonbroker_main_options', _("Main options"));
$tpl->assign('centreonbroker_log_options', _("Log options"));
$tpl->assign('centreonbroker_advanced_options', _("Advanced options"));
$form->addElement('header', 'information', _("Centreon Broker configuration"));
$form->addElement('text', 'name', _("Name"), $attrsText);
$form->addElement('text', 'filename', _("Config file name"), $attrsText);
$form->addElement('select', 'ns_nagios_server', _("Requester"), $nagios_servers);
$form->addElement('text', 'retention_path', _("Retention path"), $attrsText);
$form->addElement('text', 'event_queue_max_size', _('Event queue max size'), $attrsText);
$command = $form->addElement('text', 'command_file', _('Command file'), $attrText);
......@@ -116,6 +120,16 @@ $status[] = HTML_QuickForm::createElement('radio', 'activate', null, _("Enabled"
$status[] = HTML_QuickForm::createElement('radio', 'activate', null, _("Disabled"), 0);
$form->addGroup($status, 'activate', _("Status"), '&nbsp;');
$stats_activate = array();
$stats_activate[] = HTML_QuickForm::createElement('radio', 'stats_activate', null, _("Yes"), 1);
$stats_activate[] = HTML_QuickForm::createElement('radio', 'stats_activate', null, _("No"), 0);
$form->addGroup($stats_activate, 'stats_activate', _("Statistics"), '&nbsp;');
$correlation_activate = array();
$correlation_activate[] = HTML_QuickForm::createElement('radio', 'correlation_activate', null, _("Yes"), 1);
$correlation_activate[] = HTML_QuickForm::createElement('radio', 'correlation_activate', null, _("No"), 0);
$form->addGroup($correlation_activate, 'correlation_activate', _("Correlation"), '&nbsp;');
$tags = $cbObj->getTags();
$tabs = array();
......@@ -134,8 +148,11 @@ foreach ($tags as $tagId => $tag) {
if (isset($_GET["o"]) && $_GET["o"] == 'a'){
$form->setDefaults(array(
"name" => '',
"retention_path" => '/var/lib/centreon-broker/',
"write_timestamp" => '1',
"write_thread_id" => '1',
"stats_activate" => '1',
"correlation_activate" => '0',
"activate" => '1'
));
$tpl->assign('config_id', 0);
......@@ -168,6 +185,7 @@ $form->registerRule('exist', 'callback', 'testExistence');
$form->addRule('name', _("Mandatory name"), 'required');
$form->addRule('name', _("Name is already in use"), 'exist');
$form->addRule('filename', _("Mandatory filename"), 'required');
$form->addRule('retention_path', _("Mandatory retention path"), 'required');
$form->addRule('event_queue_max_size', _('Value must be numeric'), 'numeric');
if ($o == "w") {
......
<?php
/*
* Copyright 2005-2013 Centreon
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation ; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses>.
*
* Linking this program statically or dynamically with other modules is making a
* combined work based on this program. Thus, the terms and conditions of the GNU
* General Public License cover the whole combination.
*
* As a special exception, the copyright holders of this program give Centreon
* permission to link this program with independent modules to produce an executable,
* regardless of the license terms of these independent modules, and to copy and
* distribute the resulting executable under terms of Centreon choice, provided that
* Centreon also meet, for each linked independent module, the terms and conditions
* of the license of that module. An independent module is a module which is not
* derived from this program. If you modify this program, you may extend this
* exception to your version of the program, but you are not obliged to do so. If you
* do not wish to do so, delete this exception statement from your version.
*
* For more information : contact@centreon.com
*
*
*/
# Make broker configuration easier
if (isset($pearDB)) {
# Add temporary and retention path to general tab
$query = "ALTER TABLE cfg_centreonbroker
ADD COLUMN retention_path varchar(255),
ADD COLUMN stats_activate enum('0','1') DEFAULT '1',
ADD COLUMN correlation_activate enum('0','1') DEFAULT '0'";
$pearDB->query($query);
# Fill retention path
$query1 = "SELECT config_id
FROM cfg_centreonbroker";
$res1 = $pearDB->query($query);
while ($row1 = $res1->fetchRow()) {
$retention_path = '/var/lib/centreon-broker/';
$query2 = "SELECT config_value
FROM cfg_centreonbroker_info
WHERE config_key = 'path'
ORDER BY config_group DESC";
$res2 = $pearDB->query($query2);
while ($row2 = $res2->fetchRow()) {
if (trim($row2['config_value']) != '') {
$retention_path = dirname(trim($row2['config_value']));
continue;
}
}
$query3 = "INSERT INTO cfg_centreonbroker (retention_path)
VALUES ('" . $pearDB->escape($retention_path). "')
WHERE config_id = " . $pearDB->escape($row1['config_id']);
$pearDB->query($query3);
}
# Delete old temporary configuration
$query = "DELETE FROM cfg_centreonbroker_info
WHERE config_group='temporary'";
$pearDB->query($query);
# Delete old failover output
$query = "DELETE FROM cfg_centreonbroker_info
WHERE (config_id,config_group,config_group_id) IN
(SELECT config_id,config_group,config_group_id FROM
(SELECT cbi2.config_id,cbi2.config_group,cbi2.config_group_id
FROM cfg_centreonbroker_info cbi1, cfg_centreonbroker_info cbi2, cfg_centreonbroker_info cbi3
WHERE cbi1.config_id = cbi2.config_id and cbi1.config_group = cbi2.config_group
AND cbi2.config_id = cbi3.config_id AND cbi2.config_group = cbi3.config_group AND cbi2.config_group_id = cbi3.config_group_id
AND cbi1.config_group='output'
AND cbi2.config_group='output'
AND cbi3.config_group='output'
AND cbi1.config_key='failover'
AND cbi2.config_key='name'
AND cbi1.config_value = cbi2.config_value
AND cbi3.config_key='type'
AND cbi3.config_value='file'
) as q
)";
$pearDB->query($query);
# Delete failover names which join to non existing failover
$query ="UPDATE cfg_centreonbroker_info
SET config_value=''
WHERE config_key = 'failover'
AND config_value NOT IN
(SELECT config_value FROM
(SELECT config_value
FROM cfg_centreonbroker_info
WHERE config_key = 'name'
) as q
)";
$pearDB->query($query);
# Enable correlation if it was configured
$query = "UPDATE cfg_centreonbroker
SET enable_correlation='1'
WHERE config_id IN
(SELECT distinct config_id
FROM cfg_centreonbroker_info
WHERE config_group='correlation'
)";
$pearDB->query($query);
# Delete correlation, stats and temporary configuration if it was configured
$query = "DELETE FROM cfg_centreonbroker_info
WHERE config_group='correlation'
OR config_group='stats'
OR config_group='temporary'
");
$pearDB->query($query);
# Delete correlation, stats and temporary tabs
$query = "DELETE FROM cb_tag
WHERE tagname='correlation'
OR tagname='stats'
OR tagname='temporary'";
$pearDB->query($query);
# Delete correlation, stats and temporary parameters
$query = "DELETE FROM cb_module
WHERE name='correlation'
OR name='stats'
OR name='temporary'";
$pearDB->query($query);
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment