Related
I have 2 JSON as below. I want to compare JSON1 with JSON2 based on the subnet value, if the subnet in JSON1 & localsubnet in JSON2 matches, then i would like to copy the line(useVpn) under the particular localsubnet from JSON2 and put it under the subnet in JSON1. Please find the expected result.
JSON1:
[
{
"ansible_loop_var": "item",
"cache_control": "no-cache, no-store, max-age=0, must-revalidate",
"changed": false,
"connection": "close",
"content": "[{}]",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Mon, 18 Oct 2021 13:26:25 GMT",
"elapsed": 1,
"expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"client_cert": null,
"client_key": null,
"creates": null,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"remote_src": false,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": false,
"validate_certs": false
}
},
"item": "555",
"json": [
{
"applianceIp": "11.11.11.12",
"dhcpBootOptionsEnabled": false,
"dhcpHandling": "Run a DHCP server",
"dhcpLeaseTime": "1 day",
"fixedIpAssignments": {},
"id": 1,
"name": "Default",
"networkId": "888",
"reservedIpRanges": [],
"subnet": "11.11.11.11/28"
}
],
"msg": "OK (unknown bytes)",
"pragma": "no-cache",
"redirected": false,
"server": "nginx/1.21.3",
"status": 200,
"strict_transport_security": "max-age=15552000; includeSubDomains",
"transfer_encoding": "chunked"
},
{
"ansible_loop_var": "item",
"cache_control": "no-cache, no-store, max-age=0, must-revalidate",
"changed": false,
"connection": "close",
"content": "[{}]",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Mon, 18 Oct 2021 13:26:27 GMT",
"elapsed": 0,
"expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"client_cert": null,
"client_key": null,
"creates": null,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"remote_src": false,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": false
}
},
"item": "555",
"json": [
{
"applianceIp": "10.10.10.11",
"dhcpBootOptionsEnabled": false,
"dhcpHandling": "Run a DHCP server",
"dhcpLeaseTime": "1 day",
"fixedIpAssignments": {},
"id": 1,
"name": "INTERNAL",
"networkId": "555",
"reservedIpRanges": [],
"subnet": "10.10.10.10/28"
}
],
"msg": "OK (unknown bytes)",
"pragma": "no-cache",
"redirected": false,
"server": "nginx/1.21.3",
"status": 200,
"strict_transport_security": "max-age=15552000; includeSubDomains",
"transfer_encoding": "chunked"
},
{
"ansible_loop_var": "item",
"cache_control": "no-cache, no-store, max-age=0, must-revalidate",
"changed": false,
"connection": "close",
"content": "[{}]",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Mon, 18 Oct 2021 13:26:29 GMT",
"elapsed": 0,
"expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"client_cert": null,
"client_key": null,
"creates": null,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"remote_src": false,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": false,
"url_password": null
}
},
"item": "abc",
"json": [
{
"applianceIp": "1.5.6.7",
"dhcpBootOptionsEnabled": false,
"dhcpHandling": "Run a DHCP server",
"dhcpLeaseTime": "1 day",
"fixedIpAssignments": {},
"id": 1,
"name": "Default",
"networkId": "abc",
"reservedIpRanges": [],
"subnet": "1.5.6.7/28"
},
{
"applianceIp": "1.2.3.5",
"dhcpBootOptionsEnabled": false,
"dhcpHandling": "Run a DHCP server",
"dhcpLeaseTime": "1 day",
"fixedIpAssignments": {},
"groupPolicyId": "100",
"id": 123,
"name": "Test",
"networkId": "abc",
"reservedIpRanges": [],
"subnet": "1.2.3.4/24"
},
{
"applianceIp": "1.1.3.1",
"dhcpBootOptionsEnabled": false,
"dhcpHandling": "Run a DHCP server",
"dhcpLeaseTime": "1 day",
"dhcpOptions": [],
"dnsNameservers": "upstream_dns",
"fixedIpAssignments": {},
"id": 111,
"name": "sss",
"networkId": "123",
"reservedIpRanges": [],
"subnet": "1.1.3.0/24"
}
],
"msg": "OK (unknown bytes)",
"pragma": "no-cache",
"redirected": false,
"server": "nginx/1.21.3",
"status": 200,
"strict_transport_security": "max-age=15552000; includeSubDomains",
"x_xss_protection": "1; mode=block"
}
]
JSON2:
{
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"cache_control": "no-cache, no-store, max-age=0, must-revalidate",
"changed": false,
"connection": "close",
"content": "{}",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Mon, 18 Oct 2021 13:26:04 GMT",
"elapsed": 0,
"expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"client_cert": null,
"client_key": null,
"creates": null,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"remote_src": false,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": false
}
},
"item": "123",
"json": {
"hubs": [
{
"hubId": "123",
"useDefaultRoute": true
}
],
"mode": "spoke",
"subnets": [
{
"localSubnet": "11.11.11.11/28",
"useVpn": true
},
{
"localSubnet": "0.0.0.0/0",
"useVpn": false
}
]
},
"msg": "OK (unknown bytes)",
"pragma": "no-cache",
"redirected": false,
"server": "nginx/1.21.3",
"status": 200,
"x_ua_compatible": "IE=Edge,chrome=1",
"x_xss_protection": "1; mode=block"
},
{
"ansible_loop_var": "item",
"cache_control": "no-cache, no-store, max-age=0, must-revalidate",
"changed": false,
"connection": "close",
"content": "{}",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Mon, 18 Oct 2021 13:26:06 GMT",
"elapsed": 0,
"expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"client_cert": null,
"client_key": null,
"creates": null,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"owner": null,
"remote_src": false,
"removes": null,
"return_content": true,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
}
},
"item": "def",
"json": {
"hubs": [
{
"hubId": "def",
"useDefaultRoute": false
}
],
"mode": "spoke",
"subnets": [
{
"localSubnet": "10.10.10.10/28",
"useVpn": true
}
]
},
"msg": "OK (unknown bytes)",
"pragma": "no-cache",
"redirected": false,
"server": "nginx/1.21.3",
"status": 200,
"x_xss_protection": "1; mode=block"
},
{
"ansible_loop_var": "item",
"cache_control": "no-cache, no-store, max-age=0, must-revalidate",
"changed": false,
"connection": "close",
"content": "{}",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Mon, 18 Oct 2021 13:26:07 GMT",
"elapsed": 0,
"expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"body": null,
"body_format": "raw",
"ca_path": null,
"client_cert": null,
"client_key": null,
"creates": null,
"dest": null,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"http_agent": "ansible-httpget",
"method": "GET",
"mode": null,
"status_code": [
200
],
"timeout": 30,
"validate_certs": false
}
},
"item": "abc",
"json": {
"hubs": [
{
"hubId": "abc",
"useDefaultRoute": false
}
],
"mode": "spoke",
"subnets": [
{
"localSubnet": "1.5.6.7/28",
"useVpn": true
},
{
"localSubnet": "1.2.3.4/24",
"useVpn": false
},
{
"localSubnet": "1.1.3.0/24",
"useVpn": false
}
]
},
"msg": "OK (unknown bytes)",
"x_xss_protection": "1; mode=block"
}
],
"skipped": false
}
Expected Result:
{
"applianceIp": "1.1.1.3",
"subnet": "1.1.1.1/28",
"useVpn": true
}
Code:
- name: Combine corresponding UseVpn value to each element in json1 inside the result variable
vars:
vpn_value: >-
{{
json2.results[0].json.subnets
| selectattr('localSubnet', '==', item.subnet)
| map(attribute='useVpn')
| first
| default(false, true)
}}
set_fact:
result: >-
{{
result | default([])
+
[item | combine({'useVpn': vpn_value})]
}}
loop: "{{ json1[0].json }}"
- debug:
msg:
- "{{ result }}"
People here usually expect from you an example implementation of what you have already tried and you should seriously think about it for your next question if you want to spend some quality time here (read how to ask and creating an MCVE).
Meanwhile, since I also know data manipulation in ansible can easily get beginners lost, here is a possibility to get your result that will introduce several filters and modules you will need to go through one time or an other.
I strongly suggest you read the following documentation chapters to understand the example below:
Using filters (ansible)
Jinja2 builtin filters
Set fact module
Loops
The following playbook:
---
- hosts: localhost
gather_facts: false
vars:
json1: [ { "applianceIp": "1.1.1.3", "subnet": "1.1.1.1/28" } ]
json2: { "hubs": [ { "hubId": "abs", "useDefaultRoute": true } ], "mode": "spoke", "subnets": [ { "localSubnet": "1.1.1.1/28", "useVpn": true }, { "localSubnet": "0.0.0.0/0", "useVpn": false } ] }
tasks:
- name: Combine corresponding UseVpn value to each element in json1 inside the result variable
vars:
vpn_value: >-
{{
json2.subnets
| selectattr('localSubnet', '==', item.subnet)
| map(attribute='useVpn')
| first
| default(false, true)
}}
set_fact:
result: >-
{{
result | default([])
+
[item | combine({'useVpn': vpn_value})]
}}
loop: "{{ json1 }}"
- name: Show the result
debug:
var: result
Gives:
PLAY [localhost] ***********************************************************************************************************************************************************************************************************************
TASK [Combine corresponding UseVpn value to each element in json1 inside the result variable] *********************************************************************************************************************************************************************
ok: [localhost] => (item={'applianceIp': '1.1.1.3', 'subnet': '1.1.1.1/28'})
TASK [Show the result] *****************************************************************************************************************************************************************************************************************
ok: [localhost] => {
"result": [
{
"applianceIp": "1.1.1.3",
"subnet": "1.1.1.1/28",
"useVpn": true
}
]
}
PLAY RECAP *****************************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
I'm trying to post to my Mockable API using Axios and React Native,
I'm quite inexperienced with Axios and Mockable and am not sure If I'm getting the response that I'm suppose to.
To explain:
In my app I've got a set of data (order data) which I'm trying to post to my mockable api.
So what I expect is
to add an order with the data from below to my API everytime I hit post.
What is happening
Everytime I hit post an order does not get added to my API.
How do I add objects to my Mockable API using Axios and React Native?
class BarPaymentScreen extends Component{
static navigationOptions = {
// header: null,
};
constructor(props){
super(props);
this.state ={
isLoading: false,
orderRestaurantId : 'empty',
orderValue: 'empty',
orderProducts: 'empty',
orderTotalPrice: 'empty',
}
}
handleSubmit = () => {
this.setState({
orderRestaurantId : this.props.restaurantId,
orderValue: this.state.value,
orderProducts: this.props.products,
orderTotalPrice: this.props.totalPrice,
})
axios({
method: 'post',
url: 'https://demo3381137.mockable.io/orders',
data: {
orders: {
orderId: '1',
restaurantId: this.state.orderRestaurantId,
orderKey: "AppOrderKey",
userId: "1",
paymentStatus: "approved",
preparing: "approved",
orderStatus: "approved",
paymentMethod: this.state.orderValue,
totalPrice: this.state.orderTotalPrice,
order: [
{
product : "bier",
qty : "5"
}
]
}
}
}).then(function (response) {
console.log('response',response);
})
.catch(function (error) {
console.log("error response",error);
});
console.log('submit');
}
Response Data
response Object {
"config": Object {
"adapter": [Function xhrAdapter],
"data": "{\"orders\":{\"orderId\":\"1\",\"restaurantId\":\"empty\",\"orderKey\":\"AppOrderKey\",\"userId\":\"1\",\"paymentStatus\":\"approved\",\"preparing\":\"approved\",\"orderStatus\":\"approved\",\"paymentMethod\":\"empty\",\"totalPrice\":\"empty\",\"order\":[{\"product\":\"bier\",\"qty\":\"5\"}]}}",
"headers": Object {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=utf-8",
},
"maxContentLength": -1,
"method": "post",
"timeout": 0,
"transformRequest": Object {
"0": [Function transformRequest],
},
"transformResponse": Object {
"0": [Function transformResponse],
},
"url": "https://demo3381137.mockable.io/orders",
"validateStatus": [Function validateStatus],
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
},
"data": Object {
"orders": Array [
Object {
"restaurantId": "1",
"order": Array [
Object {
"product": "bier",
"qty": "5",
},
Object {
"product": "wisky",
"qty": "5",
},
Object {
"product": "fanta",
"qty": "5",
},
],
"orderId": "1",
"orderKey": "F3SAR566T",
"orderStatus": "approved",
"paymentMethod": "approved",
"paymentStatus": "approved",
"preparing": "approved",
"totalPrice": 10,
"userId": "1",
},
],
},
"headers": Object {
"access-control-allow-origin": "*",
"cache-control": "public, max-age=0",
"content-length": "721",
"content-type": "application/json; charset=UTF-8",
"date": "Mon, 18 Mar 2019 20:45:23 GMT",
"server": "Google Frontend",
"x-cloud-trace-context": "9a52c3976772c84992f870c94d8316a2",
},
"request": XMLHttpRequest {
"DONE": 4,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"OPENED": 1,
"UNSENT": 0,
"_aborted": false,
"_cachedResponse": undefined,
"_hasError": false,
"_headers": Object {
"accept": "application/json, text/plain, */*",
"content-type": "application/json;charset=utf-8",
},
"_incrementalEvents": false,
"_lowerCaseResponseHeaders": Object {
"access-control-allow-origin": "*",
"cache-control": "public, max-age=0",
"content-length": "721",
"content-type": "application/json; charset=UTF-8",
"date": "Mon, 18 Mar 2019 20:45:23 GMT",
"server": "Google Frontend",
"x-cloud-trace-context": "9a52c3976772c84992f870c94d8316a2",
},
"_method": "POST",
"_requestId": null,
"_response": "{
\"orders\": [
{
\"orderId\": \"1\",
\"restaurantId\": \"1\",
\"orderKey\": \"F3SAR566T\",
\"userId\": \"1\",
\"paymentStatus\": \"approved\",
\"preparing\": \"approved\",
\"orderStatus\": \"approved\",
\"paymentMethod\": \"approved\",
\"totalPrice\": 10,
\"order\": [
{
\"product\" : \"bier\",
\"qty\" : \"5\"
},
{
\"product\" : \"wisky\",
\"qty\" : \"5\"
},
{
\"product\" : \"fanta\",
\"qty\" : \"5\"
}
]
}
]
}",
"_responseType": "",
"_sent": true,
"_subscriptions": Array [],
"_timedOut": false,
"_trackingName": "unknown",
"_url": "https://demo3381137.mockable.io/orders",
"readyState": 4,
"responseHeaders": Object {
"Cache-Control": "public, max-age=0",
"access-control-allow-origin": "*",
"content-length": "721",
"content-type": "application/json; charset=UTF-8",
"date": "Mon, 18 Mar 2019 20:45:23 GMT",
"server": "Google Frontend",
"x-cloud-trace-context": "9a52c3976772c84992f870c94d8316a2",
},
"responseURL": "https://demo3381137.mockable.io/orders",
"status": 200,
"timeout": 0,
"upload": XMLHttpRequestEventTarget {
Symbol(listeners): Object {},
},
"withCredentials": true,
Symbol(listeners): Object {
"error": Object {
"kind": 3,
"listener": [Function handleError],
"next": null,
},
"readystatechange": Object {
"kind": 3,
"listener": [Function handleLoad],
"next": null,
},
"timeout": Object {
"kind": 3,
"listener": [Function handleTimeout],
"next": null,
},
},
},
"status": 200,
"statusText": undefined,
}
Code worked, Mockable.io has a page which shows the response to my posts.
I have a JSON log of my application which contains elements in a nested array form, here is the sample of it:-
{
"msgs": [{
"ts": "2017-09-04T07:07:45.6229372Z",
"tid": 25,
"eid": 1,
"lvl": "Information",
"cat": "Microsoft.AspNetCore.Hosting.Internal.WebHost",
"msg": {
"cnt": "Request starting HTTP/1.1 POST http://localhost:20001/Processor text/xml; charset=utf-8 685",
"Protocol": "HTTP/1.1",
"Method": "POST",
"ContentType": "text/xml; charset=utf-8",
"ContentLength": 685,
"Scheme": "http",
"Host": "localhost:20001",
"PathBase": "",
"Path": "/Processor",
"QueryString": ""
}
},
{
"ts": "2017-09-04T07:07:45.6229372Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.Service.ServiceHostMiddleware",
"msg": {
"cnt": "REQ"
},
"data": {
"Headers": {
"Connection": "Keep-Alive",
"Content-Length": "685",
"Content-Type": "text/xml; charset=utf-8",
"Accept-Encoding": "gzip, deflate",
"Expect": "100-continue",
"Host": "localhost:20001",
"SOAPAction": "\"http://servereps.mtxeps.com/TransactionService/SendTransaction\""
}
}
},
{
"ts": "2017-09-04T07:07:45.6239372Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.ProcessorTransactionService",
"msg": {
"cnt": "REQ"
},
"data": {
"Trace": "Aa10031<1C>Ab1<1C>Ac000101<1C>Ad20170616145857<1C>Ae10011<1C>AhVT00009<1C>ArY<1C>Be1812<1C>BfS<1C>BnDB<1C>Bo400296<1C>Bp4803<1C>BqDebit Card<1C>Br16<1C>Da300<1C>Dc0<1C>Dk840<1C>Ga01<1C>Gb1<1C>GfG<1C>GhB/GsF>O<1C>GkOE1<1C>Ia7325980B6B284759<1C>Ib8765432100324A00313<1C>Ic0043<1C>Ig3|1|MX2015-06<1C>IjgnkA7MdNlE2EB1c2B3jlz1G3Kf2U5S3x2H9W6ldIY7QpmlUzYcNHGg==|FFFF987654323D2007CD<1C>Nc5<1C>Oa18"
}
},
{
"ts": "2017-09-04T07:07:45.6249373Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.TransactionProcessingEngine",
"msg": {
"cnt": "REQ"
},
"data": {
"request": {
"Version": "1.0",
"Server": {
"LogicalDatacenterId": 0,
"PhysicalDatacenterId": 0,
"UniqueId": "G00008D4F35EDADCD368",
"UniversalTimestamp": "2017-09-04T07:07:45.6249373Z"
},
"State": {
"Status": "InFlight"
},
"Tenant": {
"CompanyNumber": 10031,
"StoreNumber": 1,
"HostType": {
"Code": 7,
"Name": "ProdConcordHC"
},
"MerchantNumber": "",
"TerminalId": ""
},
"PointOfInteraction": {
"Client": {
"Type": "OpenEPS",
"CardType": "DB",
"CardName": "Debit Card",
"CommandSequence": "B/GsF>O"
},
"Lane": {
"Type": "Attended",
"Number": 1
},
"Terminal": {
"EMVCapabilities": "FullEMV",
"SerialNumber": "0043"
},
"PointOfSale": {
"ReferenceNumber": "VT00009",
"CashierNumber": "1"
},
"LocalTimestamp": "2017-06-16T14:58:57"
},
"Request": {
"MessageType": {
"Code": 0,
"Name": "Standard"
},
"TenderType": {
"Code": 1,
"Name": "Debit"
},
"TransactionType": {
"Code": 1,
"Name": "Purchase"
},
"EntryMode": "Swiped",
"AuditId": 10011,
"CardType": {
"TenderType": {
"Code": 0,
"Name": "Unknown"
},
"Code": 0,
"Name": "Unknown"
},
"AccountNumberFirstSix": "400296",
"AccountNumberLastFour": "4803",
"AccountNumberLength": 16,
"Card": {
"EncryptedTrack": {
"EncryptionType": "Hardware",
"EncryptionKeySerialNumber": "FFFF987654323D2007CD",
"EncryptedValue": "gnkA7MdNlE2EB1c2B3jlz1G3Kf2U5S3x2H9W6ldIY7QpmlUzYcNHGg=="
},
"EncryptedPIN": {
"EncryptionType": "PassThrough",
"EncryptionKeySerialNumber": "8765432100324A00313",
"EncryptedValue": "7325980B6B284759"
}
},
"Currency": {
"Number": 840
},
"Amount": 3.0,
"CashbackAmount": 0.0,
"AllowPartialAuthorization": true,
"Host": {
"HostType": {
"Code": 7,
"Name": "ProdConcordHC"
},
"Values": {
"HostProfileId": 1,
"CompanyNumber": 10031,
"StoreNumber": 1,
"StoreProfileId": 1,
"NumericStateCode": 0,
"AlphaStateCode": "NH",
"CheckAuthService": "3"
}
}
},
"Trace": {
"Path": [{
"Type": "OpenEPS",
"Value": "OE1"
},
{
"NodeId": 0,
"Type": "Gateway",
"Value": "GAT"
},
{
"NodeId": 0,
"ElapsedSeconds": 0.7458587,
"Type": "Tenant",
"Value": "TEN"
}]
}
},
"timeoutInMilliseconds": 45000
}
},
{
"ts": "2017-09-04T07:07:45.6259373Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TenantResolutionClient",
"msg": {
"cnt": "SEND"
},
"data": {
"RequestUri": "http://153.71.66.148:20002/TenantConfigurationService/v1/Resolution",
"Method": "POST",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:45 GMT",
"User-Agent": "ConnectedPayments/1.0",
"x-ms-request-root-id": "6627de44-43a027c7567ddccd",
"x-ms-request-id": "|6627de44-43a027c7567ddccd.1.",
"Request-Id": "|6627de44-43a027c7567ddccd.1.",
"Correlation-Context": "UniqueId=G00008D4F35EDADCD368",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "181"
}
}
},
{
"ts": "2017-09-04T07:07:46.37098Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TenantResolutionClient",
"msg": {
"cnt": "RECV"
},
"data": {
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:46 GMT",
"Transfer-Encoding": "chunked",
"X-Unique-Id": "G00008D4F35EDADCD368",
"X-Node-Id": "0",
"Content-Type": "application/json; charset=utf-8"
}
}
},
{
"ts": "2017-09-04T07:07:46.37098Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.TransactionProcessingEngine",
"msg": {
"cnt": "Resolution performed."
},
"data": {
"Response": {
"Content": {
"Company": {
"Number": 10031,
"Name": "Sprouts"
},
"TransactionProfile": {
"TransactionProfileId": 1,
"CompanyNumber": 10031,
"Number": 1000,
"Description": "Transaction Profile 1000"
},
"TransactionValidation": {
"TransactionValidationId": 1,
"TransactionProfileId": 1,
"MessageTypeCode": 0,
"TenderTypeCode": 1,
"TransactionTypeCode": 1,
"CardTypeCode": 0
},
"Store": {
"Number": 1,
"Name": "Store 1",
"QueueLaneNumber": 0
},
"StoreProfile": {
"StoreProfileId": 1,
"CompanyNumber": 10031,
"StoreNumber": 1,
"TransactionProfileId": 1,
"HostTypeCode": 7,
"MerchantNumber": "",
"TerminalId": ""
},
"HostProfile": {
"HostProfileId": 1,
"CompanyNumber": 10031,
"StoreNumber": 1,
"StoreProfileId": 1,
"NumericStateCode": 0,
"AlphaStateCode": "NH",
"CheckAuthService": "3"
}
},
"NodeId": 0,
"StatusCode": 200
},
"ElapsedSeconds": 0.7458587
}
},
{
"ts": "2017-09-04T07:07:46.37198Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TransactionAuthorizationClient",
"msg": {
"cnt": "SEND"
},
"data": {
"RequestUri": "http://ser22vvm211:8082/OrchestrationService/v1/Authorization",
"Method": "POST",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:46 GMT",
"User-Agent": "ConnectedPayments/1.0",
"x-ms-request-root-id": "6627de44-43a027c7567ddccd",
"x-ms-request-id": "|6627de44-43a027c7567ddccd.2.",
"Request-Id": "|6627de44-43a027c7567ddccd.2.",
"Correlation-Context": "UniqueId=G00008D4F35EDADCD368",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "1821"
}
}
},
{
"ts": "2017-09-04T07:07:49.8941815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TransactionAuthorizationClient",
"msg": {
"cnt": "RECV"
},
"data": {
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:49 GMT",
"Server": "Apache-Coyote/1.1",
"Content-Length": "1672",
"Content-Type": "application/json"
}
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.TransactionProcessingEngine",
"msg": {
"cnt": "RSP"
},
"data": {
"ResponseTransaction": {
"Version": null,
"Server": {
"LogicalDatacenterId": 0,
"PhysicalDatacenterId": 0,
"TransactionId": 10909,
"UniqueId": "G00008D4F35EDADCD368",
"UniversalTimestamp": "2017-09-04T07:07:45.6249373Z"
},
"State": null,
"Tenant": {
"CompanyNumber": 10031,
"StoreNumber": 1,
"HostType": {
"Code": 7,
"Name": "ProdConcordHC"
},
"MerchantNumber": "",
"TerminalId": ""
},
"PointOfInteraction": {
"Client": {
"Type": "B/GsF>O",
"CardType": "DB",
"CardName": "Debit Card",
"CommandSequence": "B/GsF>O",
"Version": null
},
"Lane": {
"Type": "Attended",
"Number": 1
},
"Terminal": {
"EMVCapabilities": "Contact, ContactlessDisabled",
"Type": null,
"SerialNumber": null,
"EMVKernelVersion": null,
"EMVIdentifierCAPK": null,
"PINCapabilities": null
},
"PointOfSale": {
"CashierNumber": "1",
"ReferenceNumber": null
},
"LocalTimestamp": "2017-06-16T14:58:57",
"LocalTimeZoneOffset": null
},
"Request": {
"MessageType": null,
"EntryMode": null,
"CashbackAmount": 0.00,
"AllowPartialAuthorization": true,
"TenderType": null,
"TransactionType": null,
"ReversalType": null,
"ReferenceId": null,
"AuditId": null,
"AccountNumberFirstSix": null,
"AccountNumberLastFour": null,
"AccountNumberLength": null,
"CardType": null,
"PreviousTransaction": null,
"Card": null,
"Check": null,
"Identification": null,
"Currency": null,
"Amount": null,
"TipAmount": null,
"Host": null
},
"Response": {
"ErrorCode": 96,
"ErrorMessage": "E2G",
"IsApproved": false,
"ResponseCode": "96",
"HostResponseCode": "E2G",
"HostResponseMessage": "EDIT ER:OPT DATA",
"ApprovedAmount": 0.00,
"ApprovedCashbackAmount": 0.0,
"IsApprovedLocally": false,
"AuthorizationCode": null,
"ResponseMessage": null,
"BalanceAmount": null,
"Check": null,
"Currency": null,
"Card": null,
"Host": null
},
"Trace": {
"ElapsedSeconds": 4.2694351,
"Path": [{
"NodeId": 0,
"ElapsedSeconds": 4.2694351,
"Type": "Gateway",
"Value": "GAT"
}]
},
"Queue": null,
"SensitiveData": null,
"PreviousTransaction": null,
"Trace": null
}
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.ProcessorTransactionService",
"msg": {
"cnt": "RSP"
},
"data": {
"Trace": "Aa10031<1C>Ab1<1C>Ac000101<1C>Ad20170616145857<1C>Ae10011<1C>Af96<1C>ArY<1C>BnDB<1C>BqDebit Card<1C>Db0<1C>Dc0<1C>Ga1<1C>Gb1<1C>GfG<1C>GhB/GsF>O<1C>GkGAT<1C>Jb96<1C>Ka7<1C>MbE2G<1C>Mg0<1C>Nc5<1C>Ya10909<1C>Yb0<1C>YcG00008D4F35EDADCD368"
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.Service.ServiceHostMiddleware",
"msg": {
"cnt": "RSP"
},
"data": {
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:49 GMT",
"Transfer-Encoding": "chunked",
"Content-Type": "text/xml; charset=utf-8",
"X-Unique-Id": "G00008D4F35EDADCD368",
"X-Node-Id": "0"
}
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"eid": 2,
"lvl": "Information",
"cat": "Microsoft.AspNetCore.Hosting.Internal.WebHost",
"msg": {
"cnt": "Request finished in 4272.8738ms 200 text/xml; charset=utf-8",
"ElapsedMilliseconds": 4272.8738,
"StatusCode": 200,
"ContentType": "text/xml; charset=utf-8"
}
}],
"RequestId": "G00008D4F35EDADCD368",
"RequestPath": "/Processor",
"Action": "http://servereps.mtxeps.com/TransactionService/SendTransaction",
"Contract": "NCR.CP.GatewayService.IProcessorTransactionContract",
"OperationName": "SendTransaction",
"MethodName": "SendTransaction"
}
Here "msgs" element contains nested array object into it, so to create field of every elements inside the array object i had followed the mutate and split approach both:-
Mutate filter:-
mutate {
add_field => {
"ts" => "%{[doc][msgs][0][ts]}"
"tid1" => "%{[doc][msgs][0][tid]}"
"eid1" => "%{[doc][msgs][0][eid]}"
"lvl1" => "%{[doc][msgs][0][lvl]}"
"cat1" => "%{[doc][msgs][0][cat]}"
"msg1" => "%{[doc][msgs][0][msg]}"
"data" => "%{[doc][msgs][1][data]}"
"actual-message" =>"%{[doc][msgs][3][data][Trace]}"
"error" =>"%{[doc][msgs][5][ex][exs][0][ec]}"
"error-type" =>"%{[doc][msgs][5][ex][exs][0][typ]}"
}
}
This approach is static as my logs is occurring dynamically i.e position of error is not fixed as it may come in 6th array element or may be at 7th or 8th,
so i ignored this approach and followed the split filter approach:-
Split Filter in logstash config:-
input{
file{
path=>"C:\Logs\GatewayService\GatewayService-Processor.Transactions-20170830.slog"
}
}
split {
field=>"msgs"
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "g_index"
}
}
now it is showing error as:
[2017-09-19T17:40:07,557][WARN ][logstash.filters.split ] Only String and Array types are splittable. field:msg is of type = NilClass
so how should i able to retrieve every element in this JSON to be a field so as to visualize in kibana by applying metrics in dashboard.
In this response, it includes all fields from jersey response class. How can i remove these field from my response and send only entity as a response object.
I have generated my interfaces and model classes using RAML. So internally it my response object extends jersey response class.
{
"length": -1,
"language": null,
"location": null,
"allowedMethods": [],
"metadata": {
"Content-Type": [
"application/json"
]
},
"mediaType": {
"type": "application",
"subtype": "json",
"parameters": {},
"wildcardType": false,
"wildcardSubtype": false
},
"status": 200,
"date": null,
"headers": {
"Content-Type": [
"application/json"
]
},//Response obj
"entity": {
"user": "abcd",
"password": "xyz123",
"group": "mail"
},
"lastModified": null,
"cookies": {},
"links": [],
"statusInfo": "OK",
"entityTag": null,
"stringHeaders": {
"Content-Type": [
"application/json"
]
}
}
I'm sure I'm doing something wrong in the auth cycle but I keep getting 500s, and the messages are pretty vague.
So, I'm calling box from my node server. First I create a client:
const sdk = new BoxSDK({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
appAuth: {
keyID: process.env.PUBLIC_KEY_ID,
privateKey: fs.readFileSync(path.resolve(__dirname, process.env.PRIVATE_KEY_PATH)),
passphrase: process.env.PRIVATE_KEY_PASSPHRASE,
},
});
app.use((req, res, next) => {
req.sdk = sdk.getAppAuthClient('user', process.env.BOX_USER_ID);
next();
});
Once I've created the client I trigger a request:
export function yearEnd(req, res) {
req.sdk.folders.create({
name: 'test',
parent: {
id: '0',
},
}, (e, r) => {
if (e) {
return res.send(e);
}
return res.status(201).send(r);
});
}
The response I get back is:
{
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.box.com",
"port": 443,
"hostname": "api.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/2.0/folders",
"path": "/2.0/folders",
"href": "https://api.box.com/2.0/folders"
},
"method": "POST",
"headers": {
"User-Agent": "Box Node.js SDK v1.0.0",
"Authorization": "[REMOVED BY SDK]",
"accept": "application/json",
"content-type": "application/json",
"content-length": 75
}
},
"response": {
"statusCode": 500,
"body": {
"type": "error",
"status": 500,
"code": "internal_server_error",
"help_url": "http://developers.box.com/docs/#errors",
"message": "Internal Server Error",
"request_id": "29462704457e0f3876ee08"
},
"headers": {
"server": "ATS",
"date": "Tue, 20 Sep 2016 08:29:59 GMT",
"content-type": "application/json",
"content-length": "188",
"cache-control": "no-cache, no-store",
"strict-transport-security": "max-age=31536000; includeSubDomains",
"vary": "Accept-Encoding",
"age": "0",
"connection": "keep-alive"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "api.box.com",
"port": 443,
"hostname": "api.box.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/2.0/folders",
"path": "/2.0/folders",
"href": "https://api.box.com/2.0/folders"
},
"method": "POST",
"headers": {
"User-Agent": "Box Node.js SDK v1.0.0",
"Authorization": "[REMOVED BY SDK]",
"accept": "application/json",
"content-type": "application/json",
"content-length": 75
}
}
},
"statusCode": 500,
"maxRetriesExceeded": true
}
Can anybody tell me what I'm doing wrong??
So, the docs and the method signature don't match. I had to go into the package and check the code by hand. To create, it's:
req.sdk.folders.create(<parent_id>, <folderName>, (e, r) => {...});