Menu

#1609 reconciliation_attcode is unknown attribute when creating synchro data source via API

Unassigned
not-a-bug
nobody
User Interface
High
2.4.1
defect
2018-10-09
2018-06-20
sonicblind
No

Hi,

I am trying to create a new synchro data source via API.
It works fine for data sources as long as they do not contain external keys.

I followed the advices from this site:
https://www.itophub.io/wiki/page?id=extensions%3Aitop-data-collector-base, especially the part where MyCollector.json is defined.

So when I submit the JSON below, with the attcode "brand_id" which is of class SynchroAttExtKey, I need to provide also attribute "reconciliation_attcode". But the API returns following error:

INTERNAL_ERROR - https://localhost/webservices/rest.php?version=1.3 : Error: attribute_list: reconciliation_attcode: Unknown attribute

Please continue to read below the JSON code...

{
    "operation": "core/create",
    "comment": "",
    "class": "SynchroDataSource",
    "output_fields": "*",
    "fields":
    {
        "action_on_multiple": "error",
        "action_on_one": "update",
        "action_on_zero": "create",
        "attribute_list": [
                            {
                                "attcode": "name",
                                "finalclass": "SynchroAttribute",
                                "reconcile": "0",
                                "update": "1",
                                "update_policy": "master_locked"
                            },  
                            {
                                "attcode": "brand_id",
                                "reconciliation_attcode": "",
                                "finalclass": "SynchroAttExtKey",
                                "reconcile": "0",
                                "update": "1",
                                "update_policy": "master_locked"
                            },
                            {
                                "attcode": "syncstatus",
                                "finalclass": "SynchroAttribute",
                                "reconcile": "0",
                                "update": "1",
                                "update_policy": "master_locked"
                            }
                        ],
        "database_table_name": "synchro_data_series",
        "delete_policy": "update",
        "delete_policy_retention": "0",
        "delete_policy_update": "syncstatus:Sync Lost",
        "description": "",
        "full_load_periodicity": "115200",
        "name": "15 - Series",
        "notify_contact_id": "2",
        "reconciliation_policy": "use_primary_key",
        "scope_class": "Series",
        "scope_restriction": "",
        "status": "production",
        "url_application": "",
        "url_icon": "",
        "user_delete_policy": "nobody",
        "user_id": "8"
    }
}

When I POST the same JSON via API, but without the one line:
"reconciliation_attcode": "",

...the API actually creates the data source, but incorrectly!
It creates the data source with following definition of the brand_id attribute:

{  'attcode': 'brand_id',
         'finalclass': 'SynchroAttribute',
         'friendlyname': 'brand_id',
         'reconcile': False,
         'update': True,
         'update_policy': 'master_locked'     },

So as you can see the finalclass for some reason is suddenly SynchroAttribute although I submitted it as SynchroAttExtKey.

When I want to view this data source in web GUI I get following error:

Error: Unknown attribute reconciliation_attcode from class SynchroAttribute.

Any help would be appreciated.

Thanks,
Martin

Discussion

  • sonicblind

    sonicblind - 2018-08-17

    Is there anybody able to help with this issue?

     
  • Passportu

    Passportu - 2018-08-23

    better to create a new Synchronization Data Sources via GUI, with all syncronization attributes, and using tool "php dump_tasks.php --task_name="sccmSoftware" > sccmSoftwareCollector.json" will generate right json.

     
    • sonicblind

      sonicblind - 2018-08-23

      I have checked the script dump_tasks.php, but:

      It does not run on my system becase it requires

      require_once(APPROOT.'core/parameters.class.inc.php');
      require_once(APPROOT.'core/utils.class.inc.php');
      require_once(APPROOT.'core/restclient.class.inc.php');
      

      And basically the parameters.class.inc.php is located under APPROOT.'setup/, or APPROOT.'webservices/setup/. So if this is the correct file, I could only change the path in the dump_tasks.

      But the other two files, utils and restclient are not present on my system at all.

      That is really weird. Did you actually try to run the dump_tasks on your installation and if yes, where are the files located, or supposed to be located?

      And second point. As far as I understood this dump_tasks only generates the JSON definition of synchro data sources. But my problem is with the import, the JSON is not accepted at all, or interpreted incorrectly, when creaing the synchor data source from provided JSON.

      I would bet that the JSON which is produced by dump_tasks looks the same as when I generate it with the help of API. But my problem is still there with the import.

       
  • sonicblind

    sonicblind - 2018-09-03

    The itop-data-collector-base extension is in my opinion an overhead for just a simple task of export/importing of a data source.

    So at the end I figured it out myself with a bit of reverse engineering of how iTop works.

    With my new script, talking to iTop via API, I am now able to:

    • automatically export an existing data source with all attributes and parameters into JSON file.
    • automatically create new data source based on provided JSON file.
    • automatically update existing data source based on provided JSON file.

    Works like a charms, I am really happy about it as it saves me a lot of time wasted when migrating data source definitions between systems manually.

    The basic idea is, when you create a new data source, never include attributes definition with core/create. Provide only the basic 'datasource' parameters/fields for core/create. Data source attributes will be created automatically based on your data model. Next send an API request with operation core/update for all attributes, this time with your respective JSON definition for attributes.

    These two steps ensures that the new data source is created with correct attributes with correct parameters, including reconcilioation attributes, linked sets delimiters etc.

     
  • Pierre Goiffon

    Pierre Goiffon - 2018-10-09
    • status: new --> not-a-bug
     
  • Pierre Goiffon

    Pierre Goiffon - 2018-10-09

    Many thanks for the feedback !
    As you seems to have find a nice solution I'm closing this ticket :)

     

Log in to post a comment.

MongoDB Logo MongoDB