Private GIT

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

#3832 improve broker config generation

parent 05e4cc6a
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,6 @@ class Broker extends AbstractObjectXML { ...@@ -42,7 +42,6 @@ class Broker extends AbstractObjectXML {
protected $stmt_broker = null; protected $stmt_broker = null;
protected $stmt_broker_parameters = null; protected $stmt_broker_parameters = null;
protected $stmt_engine_parameters = null; protected $stmt_engine_parameters = null;
protected $max_config_group_id = null;
private function generate($poller_id) { private function generate($poller_id) {
if (is_null($this->stmt_broker)) { if (is_null($this->stmt_broker)) {
...@@ -55,10 +54,6 @@ class Broker extends AbstractObjectXML { ...@@ -55,10 +54,6 @@ class Broker extends AbstractObjectXML {
$this->stmt_broker->bindParam(':poller_id', $poller_id, PDO::PARAM_INT); $this->stmt_broker->bindParam(':poller_id', $poller_id, PDO::PARAM_INT);
$this->stmt_broker->execute(); $this->stmt_broker->execute();
if (is_null($this->max_config_group_id)) {
$this->getMaxConfigGroupId();
}
$this->getEngineParameters($poller_id); $this->getEngineParameters($poller_id);
if (is_null($this->stmt_broker_parameters)) { if (is_null($this->stmt_broker_parameters)) {
...@@ -75,6 +70,7 @@ class Broker extends AbstractObjectXML { ...@@ -75,6 +70,7 @@ class Broker extends AbstractObjectXML {
$this->generate_filename = $row['config_filename']; $this->generate_filename = $row['config_filename'];
$object = array(); $object = array();
$output_options = array(); $output_options = array();
$flow_count = 0;
$config_name = $row['config_name']; $config_name = $row['config_name'];
$retention_path = $row['retention_path']; $retention_path = $row['retention_path'];
...@@ -102,46 +98,40 @@ class Broker extends AbstractObjectXML { ...@@ -102,46 +98,40 @@ class Broker extends AbstractObjectXML {
$this->stmt_broker_parameters->execute(); $this->stmt_broker_parameters->execute();
$resultParameters = $this->stmt_broker_parameters->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC); $resultParameters = $this->stmt_broker_parameters->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
$failover_config_group_id = $this->max_config_group_id + 1;
foreach ($resultParameters as $key => $value) {
$subobjects = array();
$failover = false;
$output_name = null;
$outputs = array();
# Flow parameters # Flow parameters
foreach ($resultParameters as $key => $value) {
foreach ($value as $subvalue) { foreach ($value as $subvalue) {
if (in_array($subvalue['config_key'], $this->exclude_parameters) || trim($subvalue['config_value']) == '') { if (in_array($subvalue['config_key'], $this->exclude_parameters) || trim($subvalue['config_value']) == '') {
continue; continue;
} else if ($subvalue['config_key'] == 'category') { } else if ($subvalue['config_key'] == 'category') {
$subobjects[$subvalue['config_group_id']][$key]['filters'][][$subvalue['config_key']] = $subvalue['config_value']; $object[$subvalue['config_group_id']][$key]['filters'][][$subvalue['config_key']] = $subvalue['config_value'];
} else { } else {
$subobjects[$subvalue['config_group_id']][$key][$subvalue['config_key']] = $subvalue['config_value']; $object[$subvalue['config_group_id']][$key][$subvalue['config_key']] = $subvalue['config_value'];
}
$flow_count++;
} }
} }
# Failover parameters # Failover parameters
foreach ($subobjects as $config_group_id => $subvalue) { foreach ($object as &$subvalue) {
if (isset($subvalue['output']['type']) && $subvalue['output']['type'] != 'file' && !isset($subvalue['output']['failover']) && isset($subvalue['output']['name'])) { foreach ($subvalue as $config_type => &$flow) {
$output_name = $subobjects[$config_group_id]['output']['name']; if ($config_type == 'output' && isset($flow['name']) && !isset($flow['failover']) && isset($flow['type']) && $flow['type'] != 'file') {
$subobjects[$config_group_id]['output']['failover'] = $output_name . '-failover'; $flow['failover'] = $flow['name'] . '-' . $config_type . '-failover';
$subobjects[$failover_config_group_id]['output']= array( $object[$flow_count][$config_type] = array(
'type' => 'file', 'type' => 'file',
'name' => $output_name . '-failover', 'name' => $flow['name'] . '-' . $config_type . '-failover',
'path' => $retention_path . '/' . $config_name . '_' . $output_name . '.retention', 'path' => $retention_path . '/' . $config_name . '_' . $flow['name'] . '.retention',
'protocol' => 'bbdo', 'protocol' => 'bbdo',
'compression' => 'auto', 'compression' => 'auto',
'max_size' => '104857600' 'max_size' => '104857600'
); );
$failover_config_group_id++; $flow_count++;
} }
} }
$object = array_merge($object, $subobjects);
} }
# Temporary parameters # Temporary parameters
$object[1]['temporary'] = array( $object[$flow_count]['temporary'] = array(
'type' => 'file', 'type' => 'file',
'name' => $config_name . '-temporary', 'name' => $config_name . '-temporary',
'path' => $retention_path . '/' . $config_name . '.temporary', 'path' => $retention_path . '/' . $config_name . '.temporary',
...@@ -149,14 +139,16 @@ class Broker extends AbstractObjectXML { ...@@ -149,14 +139,16 @@ class Broker extends AbstractObjectXML {
'compression' => 'auto', 'compression' => 'auto',
'max_size' => '104857600' 'max_size' => '104857600'
); );
$flow_count++;
# Stats parameters # Stats parameters
if ($stats_activate == '1') { if ($stats_activate == '1') {
$object[1]['stats'] = array( $object[$flow_count]['stats'] = array(
'type' => 'stats', 'type' => 'stats',
'name' => $config_name . '-stats', 'name' => $config_name . '-stats',
'fifo' => $retention_path . '/' . $config_name . '.temporary', 'fifo' => $retention_path . '/' . $config_name . '.stats',
); );
$flow_count++;
} }
# Generate file # Generate file
...@@ -186,20 +178,6 @@ class Broker extends AbstractObjectXML { ...@@ -186,20 +178,6 @@ class Broker extends AbstractObjectXML {
} }
} }
private function getMaxConfigGroupId() {
$stmt = $this->backend_instance->db->prepare("SELECT
MAX(config_group_id) as max_config_group_id
FROM cfg_centreonbroker_info
");
$stmt->execute();
try {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$this->max_config_group_id = $row['max_config_group_id'];
} catch (Exception $e) {
throw new Exception('Exception received : ' . $e->getMessage() . "\n");
}
}
public function generateFromPoller($poller) { public function generateFromPoller($poller) {
$this->generate($poller['id']); $this->generate($poller['id']);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment