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

Commit

Permalink
* [WEB-642] Add configuration and function for communicate with Centr…
Browse files Browse the repository at this point in the history
…eon Broker by socket
  • Loading branch information
leoncx committed Aug 4, 2015
1 parent e088282 commit b11c0c8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
33 changes: 33 additions & 0 deletions www/include/common/common-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -1778,5 +1778,38 @@ function str2db($string) {
return $string;
}

/**
* Execute a command to the Centreon Broker socket
*
* @param string $command The command to execute
* @param string $socket The socket file or tcp information
* @return bool
*/
function sendCommandBySocket($command, $socket)
{
ob_start();
$stream = stream_socket_client($socket, $errno, $errstr, 10);
ob_end_clean();
if (false === $stream) {
throw new \Exception("Error to connect to the socket.");
}
fwrite($stream, $command . "\n");
$rStream = array($stream);
$nbStream = stream_select($rStream, $wStream = null, $eStream = null, 5);
if (false === $nbStream || 0 === $nbStream) {
fclose($stream);
throw new \Exception("Error to read the socket.");
}
$ret = explode(' ', fgets($stream), 3);
fclose($stream);
if ($ret[1] !== '0x1' && $ret[1] !== '0x0') {
throw new \Exception("Error when execute command : " . $ret[2]);
}
$running = true;
if ($ret[1] === '0x0') {
$running = false;
}
return $running;
}

?>
1 change: 1 addition & 0 deletions www/include/options/oreon/generalOpt/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function updateNagiosConfigData($gopt_id = null) {
updateOption($pearDB, "monitoring_engine", isset($ret["monitoring_engine"]) && $ret["monitoring_engine"] != NULL ? $ret["monitoring_engine"] : "NULL");
updateOption($pearDB, "mailer_path_bin", isset($ret["mailer_path_bin"]) && $ret["mailer_path_bin"] != NULL ? $pearDB->escape($ret["mailer_path_bin"]) : "NULL");
updateOption($pearDB, "broker_correlator_script", isset($ret["broker_correlator_script"]) && $ret["broker_correlator_script"] != NULL ? $pearDB->escape($ret["broker_correlator_script"]) : "NULL");
updateOption($pearDB, "broker_socket_path", isset($ret["broker_socket_path"]) && $ret["broker_socket_path"] != NULL ? $pearDB->escape($ret["broker_socket_path"]) : "NULL");
updateOption($pearDB, "interval_length", isset($ret["interval_length"]) && $ret["interval_length"] != NULL ? $pearDB->escape($ret["interval_length"]) : "NULL");
$brokerOpt = "ndo";

Expand Down
1 change: 1 addition & 0 deletions www/include/options/oreon/generalOpt/nagios/form.ihtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<tr class="list_lvl_1"><td class="ListColLvl1_name" colspan="2">&nbsp;<img src='./img/icones/16x16/mailer.gif'>&nbsp;&nbsp;{$genOpt_Correlation_script}</td></tr>
<tr class="list_one"><td class="FormRowField"><img class="helpTooltip" name="tip_start_script_for_correlator_engine">&nbsp;{$form.broker_correlator_script.label}</td><td class="FormRowValue">{$form.broker_correlator_script.html}</td></tr>
<tr class="list_two"><td class="FormRowField"><img class="helpTooltip" name="tip_broker_socket_path">&nbsp;{$form.broker_socket_path.label}</td><td class="FormRowValue">{$form.broker_socket_path.html}</td></tr>

<tr class="list_lvl_1"><td class="ListColLvl1_name" colspan="2">&nbsp;<img src='./img/icones/16x16/mailer.gif'>&nbsp;&nbsp;{$genOpt_mailer_path}</td></tr>
<tr class="list_one"><td class="FormRowField"><img class="helpTooltip" name="tip_directory+mailer_binary">&nbsp;{$form.mailer_path_bin.label}</td><td class="FormRowValue">{$form.mailer_path_bin.html}</td></tr>
Expand Down
4 changes: 4 additions & 0 deletions www/include/options/oreon/generalOpt/nagios/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
* Correlation engine
*/
$form->addElement('text', 'broker_correlator_script', _("Start script for broker daemon"), $attrsText);
/*
* Socket for communicate with Centreon Broker
*/
$form->addElement('text', 'broker_socket_path', _("Centroen Broker socket path"), $attrsText);

/*
* Tactical Overview form
Expand Down
1 change: 1 addition & 0 deletions www/include/options/oreon/generalOpt/nagios/help.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

$help['tip_start_script_for_correlator_engine'] = dgettext('help', 'Init script for broker daemon.');
$help['tip_broker_socket_path'] = dgettext('help', "Centreon Broker socket path for send external command.");

/**
* Mailer path
Expand Down
5 changes: 5 additions & 0 deletions www/install/sql/centreon/Update-DB-2.6.1_to_2.6.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add default socket path for Centreon Broker
INSERT INTO `options` (`key`, `value`) VALUES ('broker_socket_path', '@CENTREONBROKER_VARLIB@/command');

-- Change version of Centreon
UPDATE `informations` SET `value` = '2.6.2' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '2.6.1' LIMIT 1;

0 comments on commit b11c0c8

Please sign in to comment.