Highlighted
Respected Contributor.
Respected Contributor.
196 views

Control data_source when adding CIs using the REST API

How I can set the `data_source` property when inserting a node using the REST API?

For example: I first add a node, with property {'name':'testnode'}

In [3]: api =Api()

In [4]: api.insert([{'ucmdbId': 1, 'type': 'node', 'properties': { 'name': 'test_node' } }])

send: b'POST /rest-api/dataModel/ HTTP/1.1\r\nHost: localhost:8443\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\ncontent-type: application/json\r\nAuthorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\nContent-Length: 95\r\n\r\n'
send: b'{"cis": [{"ucmdbId": 1, "type": "node", "properties": {"name": "test_node"}}], "relations": []}'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Thu, 09 May 2019 06:08:37 GMT
header: X-FRAME-OPTIONS:
header: Content-Security-Policy: frame-ancestors 'self'
header: X-Content-Type-Options: nosniff
header: X-Xss-Protection: 1; mode=block
header: Strict-Transport-Security: max-age=31536000
header: IE-Language: en
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Credentials: true
header: Access-Control-Allow-Methods: POST, PUT, GET, HEAD, OPTIONS, PATCH, DELETE
header: Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers , Authorization, Cache-Control, Pragma, Expires
header: Access-Control-Max-Age: 17200
header: Set-Cookie: JSESSIONID=node01b9o1mzobprr850c0y6e72jwl124; HttpOnly; secure; path=/rest-api
header: Expires: Thu, 01 Jan 1970 00:00:00 GMT
header: Content-Type: application/json
header: Content-Length: 123
DEBUG:urllib3.connectionpool:https://localhost:8443 "POST /rest-api/dataModel/ HTTP/1.1" 200 123
Out[4]:
{'addedCis': ['4a4937d8f3e92392818aca6afdc98059'],
'removedCis': [],
'updatedCis': [],
'ignoredCis': []}

 

This adds a node with the id 4a4937d8f3e92392818aca6afdc98059. If I then query that node:

In [6]: api.get_ci('4a4937d8f3e92392818aca6afdc98059')
send: b'GET /rest-api/dataModel/ci/4a4937d8f3e92392818aca6afdc98059 HTTP/1.1\r\nHost: localhost:8443\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\ncontent-type: application/json\r\nAuthorization: BearerXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Thu, 09 May 2019 06:11:40 GMT
header: X-FRAME-OPTIONS:
header: Content-Security-Policy: frame-ancestors 'self'
header: X-Content-Type-Options: nosniff
header: X-Xss-Protection: 1; mode=block
header: Strict-Transport-Security: max-age=31536000
header: IE-Language: en
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Credentials: true
header: Access-Control-Allow-Methods: POST, PUT, GET, HEAD, OPTIONS, PATCH, DELETE
header: Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers , Authorization, Cache-Control, Pragma, Expires
header: Access-Control-Max-Age: 17200
header: Set-Cookie: JSESSIONID=node0rg44j9wua7pqyqgr7b3y6p2t125; HttpOnly; secure; path=/rest-api
header: Expires: Thu, 01 Jan 1970 00:00:00 GMT
header: Content-Type: application/json
header: Content-Length: 1531
DEBUG:urllib3.connectionpool:https://localhost:8443 "GET /rest-api/dataModel/ci/4a4937d8f3e92392818aca6afdc98059 HTTP/1.1" 200 1531
Out[6]:
{'ucmdbId': '4a4937d8f3e92392818aca6afdc98059',
'globalId': None,
'type': 'node',
'properties': {'lic_operational2advanced': 'false',
'root_candidatefordeletetime': '2019-05-29T06:08:37.323Z',
'data_operationisnew': 'false',
'lic_type_basic': 'false',
'root_class': 'node',
'display_label': 'test_node',
'data_operationstate': '0:Normal',
'data_allow_auto_discovery': 'true',
'root_actualdeletetime': '2019-06-18T06:08:37.323Z',
'data_teststate': '0:Normal',
'default_gateway_ip_address_type': 'IPv4',
'data_changecorrstate': '0:No Change',
'last_modified_time': '2019-05-09T06:08:37.323Z',
'create_time': '2019-05-09T06:08:37.323Z',
'data_changestate': '0:No Change',
'global_id': '4a4937d8f3e92392818aca6afdc98059',
'data_testisnew': 'false',
'root_lastaccesstime': '2019-05-09T06:08:37.323Z',
'lic_type_operational': 'false',
'root_iscandidatefordeletion': 'false',
'data_source': 'UCMDB: User:{UISysadmin###UCMDB},LoggedInUser:{admin###UCMDB}',
'data_changeisnew': 'false',
'data_testcorrstate': '0:Normal',
'track_changes': 'false',
'host_iscomplete': 'false',
'name': 'test_node',
'data_operationcorrstate': '0:Normal',
'is_save_persistency': 'false',
'data_adminstate': '0:Managed',
'lic_type_full': 'false',
'data_updated_by': 'UCMDB: User:{UISysadmin###UCMDB},LoggedInUser:{admin###UCMDB}',
'root_enableageing': 'false'},
'identifier': None}

 

This node now has

'data_source': 'UCMDB: User:{UISysadmin###UCMDB},LoggedInUser:{admin###UCMDB}',

which I would like to change to something else when adding the node.

What I tried is setting 'data_source' when inserting the node. This did not work.

 

api.insert([{'ucmdbId': 1, 'type': 'node', 'properties': { 'name': 'test_node2', 'data_source' : 'User Added' } }])
send: b'POST /rest-api/dataModel/ HTTP/1.1\r\nHost: localhost:8443\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\ncontent-type: application/json\r\nAuthorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXX\r\nContent-Length: 125\r\n\r\n'
send: b'{"cis": [{"ucmdbId": 1, "type": "node", "properties": {"name": "test_node2", "data_source": "User Added"}}], "relations": []}'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Thu, 09 May 2019 06:17:25 GMT
header: X-FRAME-OPTIONS:
header: Content-Security-Policy: frame-ancestors 'self'
header: X-Content-Type-Options: nosniff
header: X-Xss-Protection: 1; mode=block
header: Strict-Transport-Security: max-age=31536000
header: IE-Language: en
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Credentials: true
header: Access-Control-Allow-Methods: POST, PUT, GET, HEAD, OPTIONS, PATCH, DELETE
header: Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers , Authorization, Cache-Control, Pragma, Expires
header: Access-Control-Max-Age: 17200
header: Set-Cookie: JSESSIONID=node01mg60ytrzdasvtsqr3zy8sy8l126; HttpOnly; secure; path=/rest-api
header: Expires: Thu, 01 Jan 1970 00:00:00 GMT
header: Content-Type: application/json
header: Content-Length: 123
DEBUG:urllib3.connectionpool:https://localhost:8443 "POST /rest-api/dataModel/ HTTP/1.1" 200 123
Out[7]:
{'addedCis': ['434225832e3a344e816bb476da9ab519'],
'removedCis': [],
'updatedCis': [],
'ignoredCis': []}

In [8]: api.get_ci('434225832e3a344e816bb476da9ab519')
send: b'GET /rest-api/dataModel/ci/434225832e3a344e816bb476da9ab519 HTTP/1.1\r\nHost: localhost:8443\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\ncontent-type: application/json\r\nAuthorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Thu, 09 May 2019 06:17:38 GMT
header: X-FRAME-OPTIONS:
header: Content-Security-Policy: frame-ancestors 'self'
header: X-Content-Type-Options: nosniff
header: X-Xss-Protection: 1; mode=block
header: Strict-Transport-Security: max-age=31536000
header: IE-Language: en
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Credentials: true
header: Access-Control-Allow-Methods: POST, PUT, GET, HEAD, OPTIONS, PATCH, DELETE
header: Access-Control-Allow-Headers: Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers , Authorization, Cache-Control, Pragma, Expires
header: Access-Control-Max-Age: 17200
header: Set-Cookie: JSESSIONID=node08ga53m271vgl1td9o02anlt96127; HttpOnly; secure; path=/rest-api
header: Expires: Thu, 01 Jan 1970 00:00:00 GMT
header: Content-Type: application/json
header: Content-Length: 1533
DEBUG:urllib3.connectionpool:https://localhost:8443 "GET /rest-api/dataModel/ci/434225832e3a344e816bb476da9ab519 HTTP/1.1" 200 1533
Out[8]:
{'ucmdbId': '434225832e3a344e816bb476da9ab519',
'globalId': None,
'type': 'node',
'properties': {'lic_operational2advanced': 'false',
'root_candidatefordeletetime': '2019-05-29T06:17:25.347Z',
'data_operationisnew': 'false',
'lic_type_basic': 'false',
'root_class': 'node',
'display_label': 'test_node2',
'data_operationstate': '0:Normal',
'data_allow_auto_discovery': 'true',
'root_actualdeletetime': '2019-06-18T06:17:25.347Z',
'data_teststate': '0:Normal',
'default_gateway_ip_address_type': 'IPv4',
'data_changecorrstate': '0:No Change',
'last_modified_time': '2019-05-09T06:17:25.347Z',
'create_time': '2019-05-09T06:17:25.347Z',
'data_changestate': '0:No Change',
'global_id': '434225832e3a344e816bb476da9ab519',
'data_testisnew': 'false',
'root_lastaccesstime': '2019-05-09T06:17:25.347Z',
'lic_type_operational': 'false',
'root_iscandidatefordeletion': 'false',
'data_source': 'UCMDB: User:{UISysadmin###UCMDB},LoggedInUser:{admin###UCMDB}',
'data_changeisnew': 'false',
'data_testcorrstate': '0:Normal',
'track_changes': 'false',
'host_iscomplete': 'false',
'name': 'test_node2',
'data_operationcorrstate': '0:Normal',
'is_save_persistency': 'false',
'data_adminstate': '0:Managed',
'lic_type_full': 'false',
'data_updated_by': 'UCMDB: User:{UISysadmin###UCMDB},LoggedInUser:{admin###UCMDB}',
'root_enableageing': 'false'},
'identifier': None}

 

As you can see, the new node's ('ucmdbId': '434225832e3a344e816bb476da9ab519') data_source is 'data_source': 'UCMDB: User:{UISysadmin###UCMDB},LoggedInUser:{admin###UCMDB}'. Which is not what I defined in the insert. ('User Added')

0 Likes
3 Replies
Highlighted
Visitor.

Re: Control data_source when adding CIs using the REST API

AFAIK, there is no way to change it.

At the moment, CI added through UCMDB GUI is identical, from data-source POV, to CI added via APIs. There is also no way to destingwish between APIs.

Please submit this as an enhencement request on Idea Exchange.

I'll be happy to vote for the change.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Control data_source when adding CIs using the REST API

For integration points we can somehow control the dataSource with the username used for that integration and the CreatedBy attribute will contain that username.

Kind regards,
Bogdan Mureșan
EMEA CMS Technical Success
0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Re: Control data_source when adding CIs using the REST API

Yes that was exactly my observation as well. That's why I assumed that there is a way to do this using the REST-API.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.