Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions core/jsoncollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ public function Prepare()
} else {
$aDataGet = [];
}
$iSynchroTimeout = (int)Utils::GetConfigurationValue('itop_synchro_timeout', 600); // timeout in seconds, for a synchro to run
$aCurlOptions = Utils::GetCurlOptions($iSynchroTimeout);

$aCurlOptions = static::GetCurlOptions();
Comment thread
jbostoen marked this conversation as resolved.
Outdated


//logs
Utils::Log(LOG_DEBUG, 'Source aDataGet: '.json_encode($aDataGet));
$this->sFileJson = Utils::DoPostRequest($this->sURL, $aDataGet, '', $aResponseHeaders, $aCurlOptions);
$this->sFileJson = Utils::DoPostRequest($this->sURL, $aDataGet, static::GetOptionalHeaders(), $aResponseHeaders, $aCurlOptions);
Comment thread
jbostoen marked this conversation as resolved.
Outdated
Utils::Log(LOG_DEBUG, 'Source sFileJson: '.$this->sFileJson);
Utils::Log(LOG_INFO, 'Synchro URL (target): '.Utils::GetConfigurationValue('itop_url', array()));
} else {
Expand Down Expand Up @@ -258,6 +259,51 @@ public function Fetch()

return false;
}

/**
* Returns optional HTTP headers which can be sent to the specified URL.
Comment thread
Molkobain marked this conversation as resolved.
Outdated
* For example, a subclass can be override this method to send an Authorization: header.
Comment thread
jbostoen marked this conversation as resolved.
Outdated
*/
public function GetOptionalHeaders() : string
{

return '';

Comment thread
Molkobain marked this conversation as resolved.
Outdated
}

/**
* Returns cURL options to use.
Comment thread
Molkobain marked this conversation as resolved.
Outdated
* For example, a subclass can be override this method to add the CURLOPT_USERPWD and a value.
*/
public function GetCurlOptions() : array
{

$iSynchroTimeout = (int)Utils::GetConfigurationValue('itop_synchro_timeout', 600); // timeout in seconds, for a synchro to run
Comment thread
Molkobain marked this conversation as resolved.
Outdated
$aParamsSourceJson = $this->aCollectorConfig;

// Step 1:
// Use cURL options from "config" XML.
$aConfigCurlOptions = Utils::GetCurlOptions($iSynchroTimeout);

// Step 2:
// If available: Add or update options defined in the "collector" XML.
// Apply the same mechanism to convert constants. The flexibility in place is to allow adding and overriding values, so do not pass on synchro timeout.
$aCollectorCurlOptions = array();

if(isset($aParamsSourceJson['curl_options'])) {
$aCollectorCurlOptions = $aParamsSourceJson['curl_options'];
}
if(isset($aParamsSourceJson['CURL_OPTIONS'])) {
$aCollectorCurlOptions = $aParamsSourceJson['CURL_OPTIONS'];
}
Comment thread
Molkobain marked this conversation as resolved.

if(count($aCollectorCurlOptions) > 0) {
$aCollectorCurlOptions = utils::GetCurlOptions($aCollectorCurlOptions, -1);
Comment thread
jbostoen marked this conversation as resolved.
Outdated
}

return array_replace($aConfigCurlOptions, $aCollectorCurlOptions);

}
Comment thread
Molkobain marked this conversation as resolved.
Outdated

/**
* @param array $aData
Expand Down