I have create a custom skill for my Azure Cognitive Service. After creating the datasouce, index, indexer and running the indexer I can see that my function is being called and it is outputting the correct information, but when I search the index the field that is connected to the custom skill is empty.
This is my indexer definition:
{
"name": "idxdocs",
"description": null,
"dataSourceName": "dsdocs",
"skillsetName": "skillset-procuradores",
"targetIndexName": "customer-documents",
"disabled": null,
"schedule": null,
"parameters": {
"batchSize": null,
"maxFailedItems": -1,
"maxFailedItemsPerBatch": null,
"base64EncodeKeys": null,
"configuration": {
"indexedFileNameExtensions": ".pdf,.docx,.doc",
"dataToExtract": "contentAndMetadata",
"failOnUnprocessableDocument": false,
"failOnUnsupportedContentType": false,
"indexStorageMetadataOnlyForOversizedDocuments": true,
"allowSkillsetToReadFileData": true
}
},
"fieldMappings": [],
"outputFieldMappings": [
{
"sourceFieldName": "/document/content/procuradores",
"targetFieldName": "procuradores"
}
],
"cache": null,
"encryptionKey": null
}
This is my index:
{
"name": "customer-documents",
"fields": [
{
"name": "key",
"type": "Edm.String",
"facetable": true,
"filterable": true,
"key": true,
"retrievable": true,
"searchable": false,
"sortable": true,
"analyzer": null,
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "content",
"type": "Edm.String",
"facetable": false,
"filterable": false,
"key": false,
"retrievable": true,
"searchable": true,
"sortable": false,
"analyzer": "es.lucene",
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
},
{
"name": "procuradores",
"type": "Edm.String",
"facetable": false,
"filterable": true,
"key": false,
"retrievable": true,
"searchable": false,
"sortable": false,
"analyzer": null,
"indexAnalyzer": null,
"searchAnalyzer": null,
"synonymMaps": [],
"fields": []
}
],
"suggesters": [],
"scoringProfiles": [],
"defaultScoringProfile": null,
"corsOptions": null,
"analyzers": [],
"charFilters": [],
"tokenFilters": [],
"tokenizers": [],
"similarity": {
"#odata.type": "#Microsoft.Azure.Search.BM25Similarity",
"k1": null,
"b": null
},
"encryptionKey": null,
"#odata.etag": "\"0x8D98BC85E9F6996\""
}
My skill set definition:
{
"name": "skillset-procuradores",
"description": "",
"skills": [
{
"#odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
"name": "procuradores",
"description": "",
"context": "/document",
"uri": "my url ommited for secure reasons",
"httpMethod": "POST",
"timeout": "PT3M50S",
"batchSize": 1,
"degreeOfParallelism": null,
"inputs": [
{
"name": "text",
"source": "/document/content"
}
],
"outputs": [
{
"name": "procuradores",
"targetName": "procuradores"
}
],
"httpHeaders": {}
}
],
"cognitiveServices": null,
"knowledgeStore": null,
"encryptionKey": null
}
And finally my function output:
{
"values": [
{
"recordId": "1",
"data": {
"procuradores": "people's names"
}
}
]
}
What am I missing?
Rafael, can you give debug sessions a try? I suspect there is something happening in your custom skill that means the data is not coming back. By using this, you can test the actual input and output.
https://learn.microsoft.com/en-us/azure/search/cognitive-search-debug-session
This is just a hunch, but in the indexer definition, try changing your output field mapping sourceFieldName from "/document/content/procuradores" to "/document/procuradores". The context that you are giving in the skill is just "/document" so it should append the output onto that.
I am trying to flatten the "policy_metrics" array in the following JSON
{
"ticket": {
"url": "https://company.zendesk.com/api/v2/tickets/12107.json",
"id": 12107,
"description": "test",
"priority": "high",
"status": "open",
"slas": {
"policy_metrics": [
{
"breach_at": "2020-09-18T09:27:53Z",
"stage": "active",
"metric": "pausable_update_time",
"days": 2
},
{
"breach_at": null,
"stage": "achieved",
"metric": "first_reply_time"
},
{
"breach_at": "2020-09-16T09:18:56Z",
"stage": "achieved",
"metric": "next_reply_time",
"hours": -4
}
]
},
"allow_channelback": false,
"allow_attachments": true
}
}
When I use
$.ticket.slas.policy_metrics[*]
I get the following which is what I want.
breach_at
stage
metric
days
hours
What I am not able to figure out is how to get the ticket attributes and the policy_metrics attributes. For example:
url
id
description
priority
status
breach_at
stage
metric
days
hours
If its not possible with JSONPath, example with Javascript will also work.
Thanks for your help.
So I was able to make with Javascript
const flatten = require('flat').flatten;
const obj = {
"ticket": {
"url": "https://company.zendesk.com/api/v2/tickets/12107.json",
"id": 12107,
"description": "test",
"priority": "high",
"status": "open",
"slas": {
"policy_metrics": [
{
"breach_at": "2020-09-18T09:27:53Z",
"stage": "active",
"metric": "pausable_update_time",
"days": 2
},
{
"breach_at": null,
"stage": "achieved",
"metric": "first_reply_time"
},
{
"breach_at": "2020-09-16T09:18:56Z",
"stage": "achieved",
"metric": "next_reply_time",
"hours": -4
}
]
},
"allow_channelback": false,
"allow_attachments": true
}
}
console.log(flatten(obj));
The end result
{
'ticket.url': 'https://company.zendesk.com/api/v2/tickets/12107.json',
'ticket.id': 12107,
'ticket.description': 'test',
'ticket.priority': 'high',
'ticket.status': 'open',
'ticket.slas.policy_metrics.0.breach_at': '2020-09-18T09:27:53Z',
'ticket.slas.policy_metrics.0.stage': 'active',
'ticket.slas.policy_metrics.0.metric': 'pausable_update_time',
'ticket.slas.policy_metrics.0.days': 2,
'ticket.slas.policy_metrics.1.breach_at': null,
'ticket.slas.policy_metrics.1.stage': 'achieved',
'ticket.slas.policy_metrics.1.metric': 'first_reply_time',
'ticket.slas.policy_metrics.2.breach_at': '2020-09-16T09:18:56Z',
'ticket.slas.policy_metrics.2.stage': 'achieved',
'ticket.slas.policy_metrics.2.metric': 'next_reply_time',
'ticket.slas.policy_metrics.2.hours': -4,
'ticket.allow_channelback': false,
'ticket.allow_attachments': true
}
I have the following JSON and I need to get id values for instances which do not have type = Jenkins
{
"data": [
{
"id": "35002399-6fd7-40b7-b0d0-8be64e4ec09c",
"name": "94Jenkins",
"url": "http://127.0.0.1:8084",
"authProvider": false,
"siteId": "cce1b6e2-4b5d-4455-ac96-6b5d4c0d901d",
"status": {
"status": "ONLINE"
},
"instanceStateReady": true,
"instanceState": {
"#type": "InstanceStateDto",
"version": "2.60.3"
},
"adminUser": "admin1",
"hasDRConfig": false,
"managed": true,
"type": "JENKINS",
"siteName": "City",
"lastRefreshTime": "2018-04-24T09:43:01.694Z"
},
{
"id": "5cd3caf6-bac1-4f07-8793-5f124b90eaf5",
"name": "RJO",
"url": "http://test.com",
"authProvider": false,
"status": {
"status": "UNAUTHORIZED"
},
"instanceStateReady": true,
"instanceState": {
"#type": "numberOfArtifacts",
"version": "5.5.2-m002",
"licenses": {
"RJO : artrjo-m": {
"type": "ENTERPRISE",
"validThrough": "Jun 12, 2021",
"licensedTo": "Test",
"licenseHash": "asdadsdb612bda1aae745bd2a3",
"expired": false
},
"RJO : artrjo-s1": {
"type": "ENTERPRISE",
"validThrough": "Jun 12, 2021",
"licensedTo": "JFrog",
"licenseHash": "asaswca236350205a3798c0fa3",
"expired": false
}
}
},
"adminUser": "jfmc",
"hasDRConfig": false,
"managed": false,
"warnings": [
"Site is missing",
"Failed to connect to the service. Please verify that the service information provided is correct."
],
"type": "ARTIFACTORY"
},
{
"id": "0727a49a-6c95-433e-9fc5-7e5c760cc76f",
"name": "NinetyTwo",
"url": "http:127.0.0.1:8081",
"authProvider": true,
"siteId": "cce1b6e2-4b5d-4455-ac96-6b5d4c0d901d",
"status": {
"status": "ONLINE"
},
"instanceStateReady": true,
"instanceState": {
"#type": "numberOfArtifacts",
"version": "5.9.0",
"licenses": {
"NinetyTwo": {
"type": "ENTERPRISE",
"validThrough": "Dec 30, 2018",
"licensedTo": "Test",
"licenseHash": "qweqwed95f712dbabee98184da52443",
"expired": false
}
}
},
"adminUser": "admin",
"hasDRConfig": false,
"managed": true,
"type": "ARTIFACTORY",
"serviceId": "jfrt#01c7g4c7hq0dpd0qa71r8c09sj",
"siteName": "Test",
"lastRefreshTime": "2018-04-24T09:43:01.698Z"
}
]
}
And I use $..[?(#.type!='JENKINS')].id path to receive id-s which relate to the instances with type NOT JENKINS, however JSON Extractor returns me the Jenkins's id too. The question is how can I receive ids for non-jenkins instances only?
Replace your JSON path expression with the below and it should work:
$.data.[*][?(#.type != "JENKINS")].id
I want to extract some data and store it as JMeter variables of a previous sampler response. In my response, there are many, so called, attributes which have a formulaName, a definitionId and a id. I want to find a specific attribute via the formulaName ("formulaName": "F1"; defined is user defined variables) and get it's definitionId and id and store them in a variable like attributeF1DefinitionId and attributeF1Id.
On the bottom of the question a complete JSON response can be found, which was not shortened to better describe my problem.
{
"resultType": "OK",
"messages": null,
"results": {
"data": {
"actionData": {
"actionId": "00000000-0000-0000-0000-000000000000",
"modelId": "00000000-0000-0000-0000-000000000000",
"isNew": false,
"isReadOnly": false,
"includeDisplayObjectsInTabVisibility": true,
"preselectedTabId": "00000000-0000-0000-0000-000000000000",
"elementId": "AM100000001",
"localizedName": "AM100000001Action",
"headerLayout": {
"fitToAvailableWidth": true,
"fillingColumnIndex0Based": 0,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": null
"tabs": [
{
"id": "00000000-0000-0000-0000-000000000000",
"formulaName": "TD1",
"name": "Description",
"nameAdditionalInfos": null,
"dynamicLayout": {
"fitToAvailableWidth": false,
"fillingColumnIndex0Based": null,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "10000000-0000-0000-0000-000000000001",
"name": "Attribute Number 1",
"formulaName": "F1",
"definitionId": "10000000-0000-0000-0000-000000000001",
"isHidden": false
},
{
"id": "20000000-0000-0000-0000-000000000002",
"name": "Attribute Number 2",
"formulaName": "F2",
"definitionId": "20000000-0000-0000-0000-000000000002",
"isHidden": false
},
......
Any approaches are appreciated, where I can automate this extraction in the next step. What I actually want to do, is to extract almost all definitionIds and ids of all attributes (found by their formulaName) and generate use defined variables for them. The formula names are held in a "User defined variables" - Set and I found a way to iterate through it with groovy.
My approach was with a JSR223 - groovy post processor inside the request sampler which loads the data and has the response seen above.
But im stuck, with the filtering for my specific formulaName.
import groovy.json.*;
import org.apache.jmeter.threads.JMeterVariables;
def response = prev.getResponseDataAsString();
def json = new JsonSlurper().parseText(response)
def allAttributes = json.results.data.actionData.tabs.dynamicLayout.attributes;
Complete JSON response:
{
"resultType": "OK",
"messages": null,
"results": {
"data": {
"actionData": {
"actionId": "627292b8-5854-4413-bd3c-7bc4a683f58d",
"modelId": "da5433d1-74f9-43e4-8a98-92c8eb9dcead",
"isReadOnly": false,
"preselectedTabId": "14ff3d76-532d-47a6-bb85-5e48b0e7cab9",
"elementId": "AM200000001",
"localizedName": "AM200000001Action",
"tabs": [
{
"id": "14ff3d76-532d-47a6-bb85-5e48b0e7cab9",
"formulaName": "TD2",
"name": "Description",
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_14ff3d76-532d-47a6-bb85-5e48b0e7cab9",
"nameAdditionalInfos": null,
"dynamicLayout": {
"fitToAvailableWidth": false,
"fillingColumnIndex0Based": null,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b",
"name": "F1 attribute name",
"formulaName": "F1",
"definitionId": "1dc065a6-f071-4547-835b-603aff165754",
"isHidden": false,
"isReadOnly": false,
"isMandatory": true,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "F1 attribute name",
"colonPosition": 6,
"referedClientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Value",
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "a2a4fb71-9662-44e3-9279-b4692f9ca8f1",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"options": [
{
"id": "402e48f4-a313-4869-9355-91b120a93849",
"text": "Planned",
"cascadingParentItemIds": []
},
{
"id": "f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0",
"text": "Implemented",
"cascadingParentItemIds": []
}
],
"cascadingParentAttributeId": null,
"allowsNoValue": true,
"cascadingParentInitialValue": null,
"value": "402e48f4-a313-4869-9355-91b120a93849",
"attributeType": "ActionAttributeListSingleEntity",
"isDirty": false,
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeSingleSelectListDefault",
"parameters": null
}
},
"dependencies": []
},
{
"id": "c75171ee-bd2f-4396-828e-0f909ae538ed",
"name": "F2 attribute name",
"formulaName": "F2",
"definitionId": "886e8d59-deb5-4725-8080-9033feacb6d3",
"isHidden": false,
"isReadOnly": false,
"isMandatory": true,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "F2 attribute name",
"colonPosition": 6,
"referedClientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Value",
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "734d1c1e-0b35-46f3-9580-7f0a31a8201b",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"options": [
{
"id": "3231d235-36e3-497a-b244-f1ccd3e4a585",
"text": "None",
"cascadingParentItemIds": [
"402e48f4-a313-4869-9355-91b120a93849",
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "1b2e9695-0945-4724-85cb-70b4d55bcaf3",
"text": "Weak",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "b89239d8-2bad-48ad-b3b9-f1426b0b5b8c",
"text": "Noticeable",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "8bc090f5-17c1-4040-9a16-2d4a9b609c94",
"text": "Strong",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "4cdee469-9524-4dde-8e24-a878ea8d2138",
"text": "Very strong",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
}
],
"cascadingParentAttributeId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b",
"allowsNoValue": true,
"cascadingParentInitialValue": [
"402e48f4-a313-4869-9355-91b120a93849"
],
"value": "3231d235-36e3-497a-b244-f1ccd3e4a585",
"attributeType": "ActionAttributeListSingleEntity",
"isDirty": false,
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeSingleSelectListDefault",
"parameters": null
}
},
"dependencies": [
{
"requiresFullUpdate": false,
"sourceAttributeId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b",
"targetAttributeId": "c75171ee-bd2f-4396-828e-0f909ae538ed"
}
]
},
{
"id": "16f18829-e905-498a-8c28-2d29fc2e7b8b",
"name": "F3 attribute name",
"formulaName": "F3",
"definitionId": "9aef853b-f4c3-440d-9c32-6d9a13835033",
"isHidden": false,
"isReadOnly": false,
"isMandatory": true,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "F3 attribute name",
"colonPosition": 6,
"referedClientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Value",
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "096f02b4-2570-47b2-a346-c27c5102ceda",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"rows": 4,
"maxLength": 30000,
"searchInfo": null,
"value": "Textattribute value was changed! ",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": []
}
],
"displayObjects": []
}
},
{
"id": "e72e24ab-0ebd-4dd8-bf7b-4586dbc50da4",
"formulaName": "TD1",
"name": "Remarks",
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_e72e24ab-0ebd-4dd8-bf7b-4586dbc50da4",
"nameAdditionalInfos": null,
"dynamicLayout": {
"fitToAvailableWidth": false,
"fillingColumnIndex0Based": null,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987",
"name": "Remark attribute 1",
"formulaName": "R1",
"definitionId": "9709e796-3be7-49e5-a638-ed9de027b680",
"isHidden": false,
"isReadOnly": true,
"isMandatory": false,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "Remark attribute 1",
"colonPosition": 6,
"referedClientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Value",
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "d31bb13b-1f12-4f43-8ec4-d91fc405b3ae",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"rows": 4,
"maxLength": 30000,
"searchInfo": null,
"value": "",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": []
},
{
"id": "379d5451-e5af-42f8-b8b8-52b7f0953261",
"name": "Remark attribute 2",
"formulaName": "R2",
"definitionId": "ba03b62d-bcc1-40c7-9df1-e976151821a2",
"isHidden": false,
"isReadOnly": true,
"isMandatory": false,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "Remark attribute 1",
"colonPosition": 6,
"referedClientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Value",
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "129e84fe-0d76-4f8b-b5aa-e80e452998bd",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"rows": 4,
"maxLength": 30000,
"searchInfo": null,
"value": "",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": []
}
],
"displayObjects": []
}
}
],
"footerLayout": {
"fitToAvailableWidth": true,
"fillingColumnIndex0Based": 2,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "AuditComment",
"name": null,
"formulaName": "AuditComment",
"definitionId": "AuditComment",
"isHidden": false,
"isReadOnly": false,
"isMandatory": false,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": false
},
"text": "Audit-Trail Comment",
"colonPosition": 7,
"referedClientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateValue",
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateLabel",
"layout": {
"positionHorizontal": 3,
"positionVertical": 2
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateMandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 2
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": null,
"value": {
"width": null,
"rows": 1,
"maxLength": null,
"searchInfo": null,
"value": "",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateValue",
"layout": {
"positionHorizontal": 1,
"positionVertical": 2
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": null
}
],
"displayObjects": null
}
},
"linkedActions": null,
"documentations": null,
"approvals": null
}
}
}
I believe you can do it much easier using JSON Extractor, for example you can get id attribute where "formulaName" is "F1" using the following simple JSON Path query:
$..[?(#.formulaName == 'F1')].id
Similarly for definitionId, just change the above JSON Path query to match it:
$..[?(#.formulaName == 'F1')].definitionId
References:
JsonPath Operators
Advanced Usage of the JSON Path Extractor in JMeter
Groovy approach:
import groovy.json.JsonSlurper
def response = prev.getResponseDataAsString()
def json = new JsonSlurper().parseText(response)
def allAttributes = json.results.data.actionData.headerLayout.tabs[0].dynamicLayout.attributes
allAttributes.each { attribute ->
attribute.each { k, v -> log.info("${k}:${v}") }
}
With getJsonResponseString() returning a string with the json response data as specified in the question ("complete json response"), the below groovy code:
import groovy.json.*;
def data = getJsonResponseString()
def json = new JsonSlurper().parseText(data)
def attribute = json.results.data.actionData.tabs.dynamicLayout.attributes.first().find { attribute ->
attribute.formulaName == "F1"
}
if (!attribute) {
println "No attribute with formulaName F1 found!"
} else {
println "Results for 'F1': "
println " definitionId: ${attribute.definitionId}"
println " id: ${attribute.id}"
}
prints:
Results for 'F1':
definitionId: 1dc065a6-f071-4547-835b-603aff165754
id: ca25c1bc-5528-4730-8cc5-3a3c2ca4428b
the json object in the above code should be equivalent to the json object in your sample code.
I am trying to start a bunch of EC2 instances, then install something on them based on the IP given by AWS. With only one EC2, I can add the host and proceed without any issue,but when I chain them using with_dict, I can't achieve it anymore...
The following runs as I want, but I can't understand how to deal with the registered variable ec2_infos I got from the provisioning...
- name: Create Test EC2 instances
ec2:
group: default
image: ami-40d28157
instance_type: '{{item.value.type}}'
instance_tags:
Name: "{{ tag+'-'+item.value.name }}"
key_name: privatekey
region: us-west-1
vpc_subnet_id: subnet-REDACTD
wait: yes
with_dict: '{{ec2_stack}}'
register: ec2_infos
With a dictionary like
ec2_stack:
serv1:
type: t2.micro
name: server1
serv2:
type: t2.small
name: server2
ec2_infos is structures like:
"ec2_infos": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"instance_ids": [
"i-0fewq09812ddq6"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-0987654"
}
},
"dns_name": "",
"ebs_optimized": false,
"groups": {
"sg-qdwdww": "default"
},
"hypervisor": "xen",
"id": "i-083665656521dwq6",
"image_id": "ami-40d28157",
"launch_time": "2016-11-24T20:38:53.000Z",
"placement": "us-west-1d",
"private_ip": "x.x.x.x",
"public_dns_name": "",
"public_ip": null,
"ramdisk": null,
"region": "us-east-1",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"tags": {
"Name": "server1",
"Team": "blah"
},
"tenancy": "default","tenancy": "default",
"virtualization_type": "hvm"
}
],
"invocation": {
"module_args": {
"assign_public_ip": false,
"exact_count": null,
"group": [
"default"
],
"group_id": null,
"id": null,
"image": "ami-40d28157",
"instance_ids": null,
"instance_initiated_shutdown_behavior": null,
"instance_profile_name": null,
"instance_tags": {
"Name": "server1",
"Team": "blah"
},
"instance_type": "t2.micro",
"kernel": null,
"volumes": null,
"vpc_subnet_id": "subnet-abcdfed",
"wait": true,
"wait_timeout": "300",
"zone": null
},
"module_name": "ec2"
},
"item": {
"key": "serv1",
"value": {
"name": "server1",
"type": "t2.micro"
}
},
"tagged_instances": []
},
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"instance_ids": [
"i-0971278624334fd"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/sda1": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-9999999"
}
},
"dns_name": "",
"ebs_optimized": false,
"groups": {
"sg-redactd": "default"
},
"launch_time": "2016-11-24T20:39:21.000Z",
"private_ip": "y.y.y.y",
"public_dns_name": "",
"public_ip": null,
"ramdisk": null,
"state": "running",
"state_code": 16,
"tags": {
"Name": "serv2",
"Team": "blah"
},
"tenancy": "default",
"virtualization_type": "hvm"
}
],
"invocation": {
"module_args": {
"assign_public_ip": false,
"wait_timeout": "300",
"zone": null
},
"module_name": "ec2"
},
"item": {
"key": "server2",
"value": {
"name": "serv2",
"type": "t2.small"
}
},
"tagged_instances": []
}
]
}
I tried with_items and with_subelements in different ways, but I can't manage to get every IPs of the new EC2. I don't even need to sort them just extract them from the instances part and feed them to add_host so I can proceed.
Anybody knows a clean way to do so, or would be kind enough to explain to me how to deal with a registered variable after a loop properly ?
Answer from the comments:
ec2_infos.results | map(attribute='instances') | sum(start=[]) | map(attribute='private_ip') | list