Skip to content

Commit

Permalink
Change IP Discovery Application synchro to use the primary_key as rec…
Browse files Browse the repository at this point in the history
…onciliation (#5)

* Change IP Discovery Application synchro to use the primary_key as reconciliation

* Do not update uuid
  • Loading branch information
Hipska authored Oct 30, 2023
1 parent db34111 commit 6111a02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions json/TeemIpDiscoveryIPApplicationCollector.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"database_table_name": "",
"scope_restriction": "",
"full_load_periodicity": "0",
"reconciliation_policy": "use_attributes",
"reconciliation_policy": "use_primary_key",
"action_on_zero": "error",
"action_on_one": "update",
"action_on_multiple": "error",
Expand Down Expand Up @@ -227,7 +227,7 @@
{
"attcode": "uuid",
"update": "0",
"reconcile": "1",
"reconcile": "0",
"update_policy": "master_locked",
"finalclass": "SynchroAttribute"
}
Expand Down
4 changes: 4 additions & 0 deletions src/TeemIpDiscoveryCollectionPlan.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ protected function GetDiscoveryParameters($sApplicationUUID): array
Utils::Log(LOG_INFO, "An IP Discovery Application with UUID ".$sApplicationUUID." has been found in iTop.");
$aData = reset($aResult['objects']);
$aIPDiscoveryAttributes = $aData['fields'];
$aIPDiscoveryAttributes['id'] = (int) $aData['key'];

foreach ($aIPDiscoveryAttributes['ipv4subnets_list'] as $aIPv4Subnet) {
$sIndex = $aIPv4Subnet['ip'];
Expand Down Expand Up @@ -386,6 +387,9 @@ public function SetApplicationParam($sParam, $sValue): void
public function GetApplicationParam($sParam)
{
switch ($sParam) {
case 'id':
return $this->aDiscoveryApplication['params']['id'];

case 'uuid':
return $this->aDiscoveryApplication['UUID'];

Expand Down
17 changes: 8 additions & 9 deletions src/TeemIpDiscoveryIPApplicationCollector.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TeemIpDiscoveryIPApplicationCollector extends Collector
const MAX_IP_APPS = 1;

protected $iIndex;
protected $oCollectionPlan;
protected TeemIpDiscoveryCollectionPlan $oCollectionPlan;

/**
* @inheritdoc
Expand Down Expand Up @@ -87,18 +87,17 @@ public function Synchronize($iMaxChunkSize = 0): bool

/**
* @inheritdoc
* @return array{ primary_key: int, last_discovery_date: string, duration:int }|false
*/
public function fetch()
public function Fetch()
{
if ($this->iIndex < static::MAX_IP_APPS) {
$aDatas = array();
$aDatas['primary_key'] = $this->oCollectionPlan->GetApplicationParam('uuid');
$aDatas['uuid'] = $this->oCollectionPlan->GetApplicationParam('uuid');
$aDatas['last_discovery_date'] = $this->oCollectionPlan->GetApplicationParam('last_discovery_date');
$aDatas['duration'] = $this->oCollectionPlan->GetApplicationParam('duration');
$this->iIndex++;

return $aDatas;
return [
'primary_key' => $this->oCollectionPlan->GetApplicationParam('id'),
'last_discovery_date' => $this->oCollectionPlan->GetApplicationParam('last_discovery_date'),
'duration' => $this->oCollectionPlan->GetApplicationParam('duration')
];
}

return false;
Expand Down

0 comments on commit 6111a02

Please sign in to comment.