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

Commit

Permalink
fix(flush): use broker configuration to get rrdcached options for old…
Browse files Browse the repository at this point in the history
… centreonGraph class
  • Loading branch information
lpinsivy committed Oct 24, 2019
1 parent 19c0577 commit 7ff9653
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions www/class/centreonGraph.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class CentreonGraph
protected $vname;
protected $metrics;
protected $longer;
protected $rrdCachedOptions;
public $onecurve;
public $checkcurve;

Expand Down Expand Up @@ -206,6 +207,22 @@ public function __construct($user_id, $index = null, $debug = 0, $compress = nul
$DBRESULT->closeCursor();
unset($opt);

/* Get RRDCacheD options */
$result = $this->DB->query("SELECT config_key, config_value
FROM cfg_centreonbroker_info AS cbi
INNER JOIN cfg_centreonbroker AS cb ON (cb.config_id = cbi.config_id)
INNER JOIN nagios_server AS ns ON (ns.id = cb.ns_nagios_server)
WHERE ns.localhost = '1'
AND cbi.config_key IN ('rrd_cached_option', 'rrd_cached')"
);
while ($row = $result->fetch()) {
if ($row['config_key'] == 'rrd_cached_option') {
$this->rrdCachedOptions['rrd_cached_option'] = $row['config_value'];
} elseif ($row['config_key'] == 'rrd_cached') {
$this->rrdCachedOptions['rrd_cached'] = $row['config_value'];
}
}

if (isset($index)) {
$DBRESULT = $this->DB->query("SELECT `metric_id`
FROM `ods_view_details`
Expand Down Expand Up @@ -1780,8 +1797,8 @@ private function checkDBAvailability($metric_id)
*/
protected function flushRrdcached($metricsId)
{
if (!isset($this->generalOpt['rrdcached_enable'])
|| $this->generalOpt['rrdcached_enable'] == 0
if (!isset($this->rrdCachedOptions['rrd_cached_option'])
|| !preg_match('/(unix|tcp)/', $this->rrdCachedOptions['rrd_cached_option'])
) {
return true;
}
Expand All @@ -1791,20 +1808,14 @@ protected function flushRrdcached($metricsId)
*/
$errno = 0;
$errstr = '';
if (isset($this->generalOpt['rrdcached_port'])
&& trim($this->generalOpt['rrdcached_port']) != ''
) {
$sock = @fsockopen('127.0.0.1', trim($this->generalOpt['rrdcached_port']), $errno, $errstr);
if ($sock === false) {
return false;
}
} elseif (isset($this->generalOpt['rrdcached_unix_path'])
&& trim($this->generalOpt['rrdcached_unix_path']) != ''
) {
$sock = @fsockopen('unix://' . trim($this->generalOpt['rrdcached_unix_path']), $errno, $errstr);
if ($this->rrdCachedOptions['rrd_cached_option'] == 'tcp') {
$sock = fsockopen('127.0.0.1', trim($this->rrdCachedOptions['rrd_cached']), $errno, $errstr);
} elseif ($this->rrdCachedOptions['rrd_cached_option'] == 'unix') {
$sock = fsockopen('unix://' . trim($this->rrdCachedOptions['rrd_cached']), $errno, $errstr);
} else {
return false;
}

if (false === $sock) {
// @todo log the error
return false;
Expand Down

0 comments on commit 7ff9653

Please sign in to comment.