Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
feat(broker): add form to configure generic stream connector (#6024)
Browse files Browse the repository at this point in the history
* feat(form broker) add custom output

* fix(broker): Fix js with multiple element on Centreon Broker Form

* Add jshook for fields

* feat(broker) add filter in custom output

* fix(broker) replace space in output/input name

* feat(broker) add custom output test

* feat(broker) add doc
  • Loading branch information
loiclau authored and Ridene committed Mar 20, 2018
1 parent c1a83a6 commit 4ee816d
Show file tree
Hide file tree
Showing 12 changed files with 891 additions and 21 deletions.
4 changes: 4 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ default:
paths: [ %paths.base%/features/Broker.feature ]
contexts: [ BrokerContext ]

broker_configuration:
paths: [ %paths.base%/features/BrokerConfiguration.feature ]
contexts: [ BrokerConfigurationContext ]

ldap:
paths: [ %paths.base%/features/Ldap.feature ]
contexts: [ LdapContext ]
Expand Down
22 changes: 22 additions & 0 deletions doc/en/administration_guide/02l.rst
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,28 @@ Instance timeout
'unresponding' and all of its hosts and services marked as 'unknown'.
Default is 300 seconds.

===========
LUA Outputs
===========

LUA *Outputs* send metrics information into a script by a key-value system. The LUA script should be
on your server.

Path
The path of the lua script in your server.
Filter category
The categories of events accepted by this Output. If empty, no restriction on events accepted.
If filled, only events of the given type will be processed. Output that accept data from
Centreon Engines’ Broker module should be set to accept only ‘Neb’ events.

*metric lua
Type
Type of the value of the metric.
Name/Key
Name of the value of the metric.
Value
Value of the metric.
====================
Dumper Reader/Writer
====================
Expand Down
595 changes: 595 additions & 0 deletions doc/fr/administration_guide/02l.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/fr/administration_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Guide d'administration
02i
02j
02k
02l
backup
partitioning/index
10 changes: 10 additions & 0 deletions features/BrokerConfiguration.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Centreon broker Configuration
As a Centreon user
I want to configure broker

Background:
Given I am logged in a Centreon server

Scenario: add custom output
When I add a custom output
Then the output is saved
65 changes: 65 additions & 0 deletions features/bootstrap/BrokerConfigurationContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

use Centreon\Test\Behat\CentreonContext;
use Centreon\Test\Behat\Configuration\BrokerConfigurationListingPage;
use Centreon\Test\Behat\Configuration\BrokerConfigurationPage;

class BrokerConfigurationContext extends CentreonContext
{

private $currentPage;

private $initialProperties = array(
'name' => 'brokerConfigName',
'filename' => 'brokerFilename',
'cache_directory' => '/var/lib/centreon-broker/'
);

private $luaProperties = array(
'name' => 'lua_script',
'path' => '/tmp/lua.lua',
'metricType' => 'Number',
'metricName' => 'integer',
'metricValue' => 42
);


/**
* @When I add a custom output
*/
public function iAddACustomOutput()
{
$this->currentPage = new BrokerConfigurationListingPage($this);
$this->assertFind('css', 'table.ToolbarTable.table a.btc.bt_success')->click();
$page = $this->currentPage = new BrokerConfigurationPage($this);
$this->currentPage->setProperties($this->initialProperties);
$this->assertFind('css', '#c4')->click();
$this->selectInList('#block_output', 'Lua - Lua script');
$this->assertFind('css', 'a#add_output.btc.bt_success')->click();
$this->currentPage;

$this->spin(
function ($context) use ($page) {
return $context->getSession()->getPage()->has('css', 'tbody#output_1 tr.list_one td input.v_required');
}
);

$this->assertFind('css', 'tbody#output_1 tr.list_one td input.v_required')->setValue($this->luaProperties['name']);
$this->assertFind('css', 'tbody#output_1 tr.list_two td input.v_required')->setValue($this->luaProperties['path']);
$this->selectInList('tbody#output_1 tr:nth-child(1) td.FormRowValue:nth-child(2) select', $this->luaProperties['metricType']);
$this->assertFind('css', 'tbody#output_1 tr.list_one:nth-child(2) td:nth-child(2).FormRowValue input')->setValue($this->luaProperties['metricName']);
$this->assertFind('css', 'tbody#output_1 tr:nth-child(1) td.FormRowValue input.v_number')->setValue($this->luaProperties['metricValue']);

$this->currentPage->save();
}

/**
* @Then the output is saved
*/
public function theOutputIsSaved()
{
$this->currentPage = new BrokerConfigurationListingPage($this);
$this->currentPage->getEntry($this->initialProperties['name']);
}

}
32 changes: 26 additions & 6 deletions www/class/centreonConfigCentreonBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ public function quickFormById($blockId, $page, $formId = 1, $config_id = 0)
$this->attrText,
array(
'id' => $tag . '[' . $formId . '][name]',
'class' => 'v_required'
'class' => 'v_required',
'onBlur' => "this.value = this.value.replace(/ /g, '_')"
)
)
);
Expand Down Expand Up @@ -442,11 +443,28 @@ public function quickFormById($blockId, $page, $formId = 1, $config_id = 0)
if ($isMultiple && $parentGroup != "") {
if ($elementType != 'select') {
$elementAttr = array_merge($elementAttr, array(
'parentGroup' => $parentGroup,
'displayNameGroup' => $displayNameGroup
));
'parentGroup' => $parentGroup,
'displayNameGroup' => $displayNameGroup
));
if ($field['hook_name'] != '') {
$elementAttr = array_merge($elementAttr, array(
'onchange' => $field['hook_name'] . '.onChange(' . $field['hook_arguments'] . ')(this)',
'data-ontab-fn' => $field['hook_name'],
'data-ontab-arg' => $field['hook_arguments']
));
}
} else {
$elementAttrSelect = array('parentGroup' => $parentGroup , 'displayNameGroup' => $displayNameGroup);
$elementAttrSelect = array(
'parentGroup' => $parentGroup ,
'displayNameGroup' => $displayNameGroup
);
if ($field['hook_name'] != '') {
$elementAttrSelect = array_merge($elementAttrSelect, array(
'onchange' => $field['hook_name'] . '.onChange(' . $field['hook_arguments'] . ')(this)',
'data-ontab-fn' => $field['hook_name'],
'data-ontab-arg' => $field['hook_arguments']
));
}
}
}

Expand Down Expand Up @@ -525,7 +543,7 @@ public function getBlockInfos($typeId)
*/
$fields = array();
$query = "SELECT f.cb_field_id, f.fieldname, f.displayname, f.fieldtype, f.description, f.external,
tfr.is_required, tfr.order_display, f.cb_fieldgroup_id
tfr.is_required, tfr.order_display, tfr.jshook_name, tfr.jshook_arguments, f.cb_fieldgroup_id
FROM cb_field f, cb_type_field_relation tfr
WHERE f.cb_field_id = tfr.cb_field_id AND (tfr.cb_type_id = %d
OR tfr.cb_type_id IN (SELECT t.cb_type_id
Expand All @@ -549,6 +567,8 @@ public function getBlockInfos($typeId)
$field['required'] = $row['is_required'];
$field['order'] = $row['order_display'];
$field['group'] = $row['cb_fieldgroup_id'];
$field['hook_name'] = $row['jshook_name'];
$field['hook_arguments'] = $row['jshook_arguments'];
if (!is_null($row['external']) && $row['external'] != '') {
$field['value'] = $row['external'];
} else {
Expand Down
75 changes: 71 additions & 4 deletions www/include/common/javascript/centreon/brokerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function clonifyTableFields(attributeName,displayName){
table1.append(clone_template).append(jQuery('<tr>').attr('id',obj +"_noforms_template" ));
var img = jQuery('<img>').attr('src','./img/icons/circle-cross.png').addClass('ico-14').css('vertical-align','middle');
var remove = jQuery('<span>').css({'cursor': 'pointer', 'position': 'absolute', 'top': '56px', 'right': '-17px'}).attr('id', obj+'_remove_current').append(img);
table2.append(jQuery('<tr>').addClass('elem-toCollapse').append(jQuery('<td>').css({'text-align': 'right', 'height': '1px'}).attr('rowspan','5').attr('colspan','2').append(remove)));
table2.append(jQuery('<tr>').append(jQuery('<td>').css({'text-align': 'right', 'height': '1px'}).attr('rowspan','5').attr('colspan','2').append(remove)));

if(GroupArray.hasOwnProperty(obj)){
var firstPosition = false;
Expand Down Expand Up @@ -83,9 +83,12 @@ function clonifyTableFields(attributeName,displayName){
});
}

function addCollapse() {
var tbody = jQuery(".collapse-wrapper");

function addCollapse(id_name) {
if(id_name === undefined){
var tbody = jQuery(".collapse-wrapper");
} else {
var tbody = jQuery("#" + id_name + ".collapse-wrapper");
}
tbody.find(".list_one").addClass("elem-toCollapse");
tbody.find(".list_two").addClass("elem-toCollapse");
}
Expand Down Expand Up @@ -138,3 +141,67 @@ jQuery(function () {
}
});
});

/* Hooks for some fields */
var luaArguments = {
/* Hook on load tab */
onLoad: function (element, argument) {
argument = window.JSON.parse(argument);
return function () {
var type = jQuery(element).val();
var entry = element.name.match('(input|output)(\\[\\d\\])\\[(\\w*)\\]');
var block = entry[3].split('_');
var name = argument.target.replace("%d", block[block.length - 1]);
var target = entry[1] + entry[2] + '[' + name + ']';
luaArguments.changeInput(type, target)
}
},
/* Hook on change the target */
onChange: function (argument) {
return function (self) {
var entry = self.name.match('(input|output)(\\[\\d\\])\\[(\\w*)\\]');
var block = entry[3].split('_');
var name = argument.target.replace("%d", block[block.length - 1]);
var target = entry[1] + entry[2] + '[' + name + ']';
var type = jQuery(self).val();
luaArguments.changeInput(type,target)
}
},
/* Internal function for apply the input change */
changeInput: function (type, name) {
/* Get all attributes */
var attrs = {};
name = '[name="' + name + '"]:input';
jQuery.each(jQuery(name)[0].attributes, function (idx, attr) {
attrs[attr.name] = attr.value;
});
delete(attrs.type);
delete(attrs.size);
delete(attrs.class);
var $elParent = jQuery(name).parent();
var value = jQuery(name).val();
jQuery(name).remove();
/* Find the good input for the type by default text => string */
if (type === 'number') {
var newEl = jQuery('<input />')
.attr(attrs)
.attr('size', 10)
.attr('type', 'text')
.addClass('v_number')
.val(value);
} else if (type === 'password') {
var newEl = jQuery('<input />')
.attr(attrs)
.attr('size', 120)
.attr('type', 'password')
.val(value);
} else {
var newEl = jQuery('<input />')
.attr(attrs)
.attr('size', 120)
.attr('type', 'text')
.val(value);
}
$elParent.append(newEl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function addInfo(type) {
checkTypeValidity('block_' + type);
jQuery("#"+id_name).centreonValidate();
clonifyTableFields('parentGroup','displaynamegroup');
addCollapse();
addCollapse(id_name);
openNewElem(id_name);
}
}
Expand Down Expand Up @@ -207,10 +207,15 @@ function loadedConfiguration() {
function changeTab(tab) {
jQuery('#Form').centreonValidate('validate');
purgeHideInput(tab);
initCollapsebyTab(tab);
if(tab == "tab4"){
clonifyTableFields('parentGroup','displaynamegroup');
}
jQuery(function() {
jQuery.each(jQuery('[data-ontab-fn]'), function () {
window[jQuery(this).attr('data-ontab-fn')].onLoad(this, jQuery(this).attr('data-ontab-arg'))();
});
});
initCollapsebyTab(tab);
}

function purgeHideInput(tab) {
Expand Down
2 changes: 2 additions & 0 deletions www/install/createTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ CREATE TABLE `cb_type_field_relation` (
`cb_fieldset_id` INT,
`is_required` int(11) NOT NULL DEFAULT '0',
`order_display` int(11) NOT NULL DEFAULT '0',
`jshook_name` VARCHAR(255) DEFAULT NULL,
`jshook_arguments` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`cb_type_id`,`cb_field_id`),
KEY `fk_cb_type_field_relation_1` (`cb_type_id`),
KEY `fk_cb_type_field_relation_2` (`cb_field_id`),
Expand Down
Loading

0 comments on commit 4ee816d

Please sign in to comment.