I am trying to transform the following JSON log: (AWS CloudWatch/Trail if it matters)
{
"eventVersion": "1.08",
"userIdentity": {
"type": "IAMUser",
"principalId": "xxx",
"arn": "arn:aws:iam::xxx",
"accountId": "xxx",
"accessKeyId": "xxx",
"userName": "xxx",
"sessionContext": {
"sessionIssuer": {},
"webIdFederationData": {},
"attributes": {
"mfaAuthenticated": "true",
"creationDate": "2021-01-07T13:50:07Z"
}
}
},
"eventTime": "2021-01-07T14:55:03Z",
"eventSource": "ec2.amazonaws.com",
"eventName": "AuthorizeSecurityGroupIngress",
"awsRegion": "us-east-1",
"sourceIPAddress": "xxx",
"userAgent": "console.ec2.amazonaws.com",
"requestParameters": {
"groupId": "sg-xxx",
"ipPermissions": {
"items": [
{
"ipProtocol": "tcp",
"fromPort": 22,
"toPort": 22,
"groups": {},
"ipRanges": {
"items": [
{
"cidrIp": "x.x.x.x/32"
"description": "x"
}
]
},
"ipv6Ranges": {},
"prefixListIds": {}
}
]
}
},
"responseElements": {
"requestId": "xxx",
"_return": true
},
"requestID": "xxx",
"eventID": "xxx",
"readOnly": false,
"eventType": "AwsApiCall",
"managementEvent": true,
"eventCategory": "Management",
"recipientAccountId": "xxx"
}
To the following output:
"AuthorizeSecurityGroupIngress made against sg-xxx on [accountname] from [user#x.x.x.x]"
"Port range: 22"
"Source IP: x.x.x.x"
"Description: x"
Currently, by passing these 2 blocks into the CloudWatch Input Transformer:
{
"event":"$.detail.eventName",
"sg":"$.detail.requestParameters.groupId",
"user":"$.detail.userIdentity.userName",
"sourceip":"$.detail.sourceIPAddress",
"dsc":"$.detail.requestParameters.ipPermissions.items"
}
"<event> made against <sg> on [accountname] from [<user>#<sourceip>]"
"Details: <dsc>"
I am able to create the following output:
"AuthorizeSecurityGroupIngress made against sg-xxx on [accountname] from [x#x.x.x.x]"
"Details: {items:[{ipProtocol:tcp,fromPort:22,toPort:22,groups:{},ipRanges:{items:[{cidrIp:x.x.x.x/32,description:x}]},ipv6Ranges:{},prefixListIds:{}}]}"
However, when I attempt to specify the input path even further by passing more specific placeholders:
{
"event":"$.detail.eventName",
"sg":"$.detail.requestParameters.groupId",
"user":"$.detail.userIdentity.userName",
"sourceip":"$.detail.sourceIPAddress",
"prt":"$.detail.requestParameters.ipPermissions.items.toPort",
"src":"$.detail.requestParameters.ipPermissions.items.ipRanges.items.cidrIp",
"dsc":"$.detail.requestParameters.ipPermissions.items.ipRanges.items.description"
}
"<event> made against <sg> on [accountname] from [<user>#<sourceip>]"
"Port Range: <prt>"
"Source IP: <src>"
"Description: <dsc>"
The output is blank for the placeholders' (prt,src,dsc) values:
"AuthorizeSecurityGroupIngress made against sg-xxx on [accountname] from [user#x.x.x.x]"
"Port range: "
"Source IP: "
"Description: "
VS. expected
"AuthorizeSecurityGroupIngress made against sg-xxx on [accountname] from [user#x.x.x.x]"
"Port range: 22"
"Source IP: x.x.x.x"
"Description: x"
Where am I messing up in the input path?
Is it the '[]' brackets causing the issue?
In two places your JSON has an items array, but your code treats them like objects. You need to call out the array element you want to pluck properties from:
"prt":"$.detail.requestParameters.ipPermissions.items[0].toPort",
"src":"$.detail.requestParameters.ipPermissions.items[0].ipRanges.items[0].cidrIp",
"dsc":"$.detail.requestParameters.ipPermissions.items[0].ipRanges.items[0].description"
Related
I am new to Solr and am trying to add the Suggest Search Component via the Config API.
My Solr 9.0.0 setup is as follows:
bin/solr start -e cloud with _default config
Add the search component with a POST request to http://localhost:8983/api/collections/collection_name/config:
{
"add-searchcomponent": {
"name": "suggest",
"class": "solr.SuggestComponent",
"lookupImpl": "FuzzyLookupFactory",
"dictionaryImpl": "DocumentDictionaryFactory",
"field": "name",
"suggestAnalyzerFieldType": "string",
"buildOnStartup": "false"
}
}
Until here everything is fine and I receive a responseHeader with status 0.
Add the request handler with a POST request to http://localhost:8983/api/collections/collection_name/config:
{
"add-requesthandler": {
"name": "/suggest",
"class": "solr.SearchHandler",
"defaults": {
"suggest": "true",
"rows": "10"
},
"components": "suggest"
}
}
In step 3 I receive a responseHeader with status 500 and the following error message:
1 out of 2 the property overlay to be of version 4 within 30 seconds! Failed cores: [http://localhost:8983/solr/collection_name1_replica_n1/]
What am I doing wrong?
I could solve it. My error was not adding “components” in the add-requesthandler as an array.
original:
{
"add-requesthandler": {
"name": "/suggest",
"class": "solr.SearchHandler",
"defaults": {
"suggest": "true",
"rows": "10"
},
"components": "suggest"
}
}
correct:
{
"add-requesthandler": {
"name": "/suggest",
"class": "solr.SearchHandler",
"defaults": {
"suggest": "true",
"rows": "10"
},
"components": [“suggest"]
}
}
I'm working with an API from snowflake and to deal with the json data, I would need to receive data as key-value paired instead of rowType.
I've been searching for results but haven't found any
e.g. A table user with name and email attributes
Name
Email
Kelly
kelly#email.com
Fisher
fisher#email.com
I would request this body:
{
"statement": "SELECT * FROM user",
"timeout": 60,
"database": "DEV",
"schema": "PLACE",
"warehouse": "WH",
"role": "DEV_READER",
"bindings": {
"1": {
"type": "FIXED",
"value": "123"
}
}
}
The results would come like:
{
"resultSetMetaData": {
...
"rowType": [
{ "name": "Name",
...},
{ "name": "Email",
...}
],
},
"data": [
[
"Kelly",
"kelly#email.com"
],
[
"Fisher",
"fisher#email.com"
]
]
}
And the results needed would be:
{
"resultSetMetaData": {
...
"data": [
[
"Name":"Kelly",
"Email":"kelly#email.com"
],
[
"Name":"Fisher",
"Email":"fisher#email.com"
]
]
}
Thank you for any inputs
The output is not valid JSON, but the return can arrive in a slightly different format:
{
"resultSetMetaData": {
...
"data":
[
{
"Name": "Kelly",
"Email": "kelly#email.com"
},
{
"Name": "Fisher",
"Email": "fisher#email.com"
}
]
}
}
To get the API to send it that way, you can change the SQL from select * to:
select object_construct(*) as KVP from "USER";
You can also specify the names of the keys using:
select object_construct('NAME', "NAME", 'EMAIL', EMAIL) from "USER";
The object_construct function takes an arbitrary number of parameters, as long as they're even, so:
object_construct('KEY1', VALUE1, 'KEY2', VALUE2, <'KEY_N'>, <VALUE_N>)
I need some guidance please.
I have a data structure that looks like this (note that the certResults field is an array, in this case - apple.com and reuters.com, but typically there are more results within the certResults array):
{
"deviceTag": "",
"clientHostName": "555317e186a0",
"dataFormatVersion": 10,
"certResults":
[
{
"hostname": "apple.com",
"port": 443,
"startTime": "2022/07/01 03:50:57.867716",
"endTime": "2022/07/01 03:50:57.960064",
"queryTime": 92.35,
"certificateInfo":
{
"subject":
{
"countryName": "US",
"stateOrProvinceName": "California",
"localityName": "Cupertino",
"organizationName": "Apple Inc.",
"commonName": "apple.com"
},
"certificateIssuer":
{
"countryName": "US",
"organizationName": "Apple Inc.",
"commonName": "Apple Public EV Server ECC CA 1 - G1"
},
"version": 3,
"serialNumber": "6A1D3FA84A43C329F1051060FF4698BA",
"notBefore": "Apr 26 21:58:37 2022 GMT",
"notAfter": "May 26 21:58:36 2023 GMT",
"OCSP":
[
"http://ocsp.apple.com/ocsp03-apevsecc1g101"
],
"crlDistributionPoints":
[
"http://crl.apple.com/apevsecc1g1.crl"
],
"caIssuers":
[
"http://certs.apple.com/apevsecc1g1.der"
],
"subjectAltName":
{
"DNS0": "apple.com"
}
},
"timeLeft": "10 months, 25 days, 18 hours, 7 minutes, 39 seconds",
"percentageUtilization": 16.52
},
{
"hostname": "reuters.com",
"port": 443,
"startTime": "2022/07/01 03:50:57.962692",
"endTime": "2022/07/01 03:50:58.271235",
"queryTime": 308.54,
"certificateInfo":
{
"subject":
{
"commonName": "reuters.com"
},
"certificateIssuer":
{
"countryName": "US",
"organizationName": "Let's Encrypt",
"commonName": "R3"
},
"version": 3,
"serialNumber": "04203F2F15F8194772481DABC1061E213EAB",
"notBefore": "Jun 6 12:54:06 2022 GMT",
"notAfter": "Sep 4 12:54:05 2022 GMT",
"OCSP":
[
"http://r3.o.lencr.org"
],
"caIssuers":
[
"http://r3.i.lencr.org/"
],
"subjectAltName":
{
"DNS0": "reuters.com"
}
},
"timeLeft": "2 months, 3 days, 9 hours, 3 minutes, 7 seconds",
"percentageUtilization": 27.36
}
]
}
This data structure is similar in that it is executed every hour for the same hosts - i.e. each document is the same with updated results in the certResults array.
I'm struggling with the syntax for MongoDB aggregate function.
Using MongoDB's find function, I can collate entries for a specific host by first filtering the dataFormatVersion:10 and then looking at the certResults.hostname field for "reuters.com":
db.certCollection.find({ dataFormatVersion:10, certResults: {$elemMatch: {hostname: "reuters.com"}} }, {_id: 0, certResults: {"hostname.$": 1, "startTime": 1 , "port": 1, "percentageUtilization": 1 }} );
Which presents this information:
{ "certResults" : [ { "hostname" : "reuters.com", "port" : 443, "startTime" : "2022/06/28 16:31:49.919962", "percentageUtilization" : 24.61 } ] }
{ "certResults" : [ { "hostname" : "reuters.com", "port" : 443, "startTime" : "2022/06/28 16:34:55.868512", "percentageUtilization" : 24.61 } ] }
{ "certResults" : [ { "hostname" : "reuters.com", "port" : 443, "startTime" : "2022/06/28 16:57:38.926443", "percentageUtilization" : 24.63 } ] }
{ "certResults" : [ { "hostname" : "reuters.com", "port" : 443, "startTime" : "2022/06/28 17:00:02.359976", "percentageUtilization" : 24.63 } ] }
etc.
I'm not sure how to aggregate data for the percentageUtilization field.
I'd like to find out the average for the percentageUtilization field across the responding documents for this hostname "reuters.com" only. Is there a way to filter on startTime and endTime fields as well?
Similarly, I'd like to find out the average percentageUtilization across all host entries for all responding documents (i.e. reuters.com and apple.com) within a certain timeframe (based on startTime and endTime fields).
Any help would be greatly appreciated!
Thank you!
Aha! The trick I was looking for was to use $unwind for the certResults array.
I have to pass a JSON in the HTTP request and that JSON contains an array of addresses. Up until I add the array, the request is fine and I do get a response but as soon as I add the array of addresses, I get a bad request error
Below is my bad request
{
"searchType": "XXXXXX",
"searchCriteria": {
"firstName": "J",
"lastName": "S",
"birthYear": 1980,
"birthMonth": 1,
"birthDay": 1
"addresses":{
"address": [
{
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777-3917"
},
{
"_address1": "920 E LAMAR ALEXANDER PARKWAY",
"_city": "MARYVILLE",
"_state": "TN",
"_zip": "37804"
},
{
"_address1": "Last Reported Address - Out of State",
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777"
}
]
}
},
"identification": {
"ipAddress": "XXXXXXXX",
"applicationID": "XXXX"
}
}
Can someone please guide me how this can be achieved in Jmeter?
What you provide is not a valid JSON you can double check it using an online JSON validator
Since we don't have any idea regarding how the "good" request should look like we cannot come up with the 100% valid solution.
You can try to use the below JSON payload as the reference, it's syntactically correct but I don't guarantee your application will accept it:
{
"searchType": "XXXXXX",
"searchCriteria": {
"firstName": "J",
"lastName": "S",
"birthYear": 1980,
"birthMonth": 1,
"birthDay": {
"addresses": {
"address": [
{
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777-3917"
},
{
"_address1": "920 E LAMAR ALEXANDER PARKWAY",
"_city": "MARYVILLE",
"_state": "TN",
"_zip": "37804"
},
{
"_address1": "Last Reported Address - Out of State",
"_city": "LOUISVILLE",
"_state": "TN",
"_zip": "37777"
}
]
}
}
},
"identification": {
"ipAddress": "XXXXXXXX",
"applicationID": "XXXX"
}
}
I would recommend recording the request which is successful using JMeter's HTTP(S) Test Script Recorder and once you have a working request which you can successfully replay you can correlate dynamic and parameterize user-specific values.
I am working on a food delivery app, which uses parse as its backend. I am facing a problem while calling the placeOrder API through
PFCloud.callFunction(inBackground: PlaceOrder, withParameters: params) { (data, err) in}
Please have a look at the JSON which I need to post below.
{
"source": "card_1EVYuOEynlyM6L4SHgBMJYRQ",
"userId": "YjSZYSXEp7",
"data": {
"menuItems": [{
"id": "QSYa2JDcIm",
"title": "Rice With Tibss(Beef)",
"menuTitle": "Rice With Tibss",
"submenuItem": [{
"id": "zaOo6G4KSV",
"name": "Beef",
"price": 12,
"desc": "Fillings?"
}],
"price": 24,
"qty": 1,
"storeId": "yqBCDmzaDP",
"storeName": "Ibex Ethiopian Cusine and Bar",
"orderType": "takeout",
"taxState": 0.0925,
"storeInfo": {
"cart_storeId": "yqBCDmzaDP",
"cart_storeName": "Ibex Ethiopian Cusine and Bar",
"cart_storeImage": "https://res.cloudinary.com/http-get-tolofood-com/image/upload/c_scale,h_199,q_auto,w_270/v1461575640/Ibex_lopx38.jpg",
"cart_storeCuisine": "Ethiopian",
"cart_storeDescription": "We always serve a quality food. We always serve a quality food. We always serve a quality food. We always serve a quality food.",
"cart_storeRating": 3.33,
"cart_storeDelivery": false,
"takeout": true,
"address": "12255 Greenville Ave,Dallas, TX 75243",
"slugname": "TX_DAL_ibex_ethiopian_cuisine_and_bar",
"multiple_location": false,
"cart_storeDeliveryFee": 15,
"cart_storeServes": "Lunch,Dinner",
"busy": false,
"cart_storeSeoSlug": "ibex-ethiopian-cusine-and-bar"
},
"enable": true,
"voice_read_mi_label": "fbgcb",
"voice_read_mi_option": false,
"menuTypeName": "Standard"
}],
"lastOrderType": "takeout",
"searchedAddress": "takeout",
"timeData": {
"day": "06-05-2019",
"time": "12:55 am",
"tz": "America/Los_Angeles"
}
},
"unavailable_option": "restaurant_recommendation"
}
And below is the Swift code which I have used to make pass it.
let storeInfo: Dictionary = [CartStoreId: self.cartStoreId, CartStoreName: self.cartRestaurantName, CartStoreImage: self.cartStoreImage, CartStoreCuisine: self.cartStoreCuisine, CartStoreDescription: self.cartStoreDescription, CartStoreRating: self.cartStoreRating, CartStoreDelivery: self.cartStoreDelivery, Takeout: self.takeOut, Address: self.address, Slugname: self.slugName, MultipleLocation: self.multipleLocation, CartStoreDeliveryFee: self.cartStoreDelivery, CartStoreServes: self.cartStoreServes, Busy: self.busy, CartStoreSeoSlug: self.cartStoreSeoSlug] as Dictionary
let subMenuItem = ["id": "zaOo6G4KSV", "name": "Beef", "price": 12, "desc": "Fillings?", "voice_read_submi_label":"bf", "voice_read_submi_option":false, "disabled": false] as [String: Any]
let ordersDictionary = [
"id" : "1234",
"title" : "Test",
"menuTitle" : "MenuName",
"price" : 23,
"qty" : 2,
"storeId" : 23,
"orderType" : "standard",
"taxState" : 0.22,
"enable" : true,
"menuTypeName" : "Type Name",
"voice_read_mi_label":"fdfs",
"voice_read_mi_option":"false",
"submenuitem": subMenuItem,
"storeInfo": storeInfo
] as Dictionary
let timeData = ["day" : 17-06-2019, "time": "11:00 AM", "tz": "America/Los_Angeles"] as Dictionary
let data = ["menuItems": ordersDictionary, "lastOrderType": "takeout", "searchedAddress": "takeout", "timeData" : timeData] as Dictionary
let params = [UserId: self.userId, "source":"card_1EVYuOEynlyM6L4SHgBMJYRQ", "data": data, "unavailable_option":"restaurant_recommendation","_ApplicationId":"6EuadToYoFGJhI1sX8XnuFBz9tp9l3yH6HxzzXZO", "_JavaScriptKey":"rQkALu9saFtF2oq9yCibyw6mEcs3PVqct3uuP6vg", "_ClientVersion":"js1.6.14", "_InstallationId":"444ec64d-5fcc-7b8e-596e-6be627892c2a",
"_SessionToken":"r:c966376120c8eca77aa63c29d5bebe1a"] as Dictionary
After all this is done I call the parse function like below.
PFCloud.callFunction(inBackground: PlaceOrder, withParameters: params) { (data, err) in
if err != nil {
print(err!)
} else {
print(data!)
}
}
But this gives me error after a few seconds saying
"Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}"
I have searched the web with the error and made fixes accordingly but still no success. Please help me guys.
I noticed that your params var is not compatible with the JSON you sent, there are more fields and also missing fields. Moreover, menuItems and submenuItem are an Array in your JSON and an Object in your code. It is probably making the cloud code function to fail and you are therefore not receiving back a valid JSON. Try the following and check if it works. In the case it works, just replace the values by your vars.
let params = [
"source": "card_1EVYuOEynlyM6L4SHgBMJYRQ",
"userId": "YjSZYSXEp7",
"data": [
"menuItems": [[
"id": "QSYa2JDcIm",
"title": "Rice With Tibss(Beef)",
"menuTitle": "Rice With Tibss",
"submenuItem": [[
"id": "zaOo6G4KSV",
"name": "Beef",
"price": 12,
"desc": "Fillings?"
]],
"price": 24,
"qty": 1,
"storeId": "yqBCDmzaDP",
"storeName": "Ibex Ethiopian Cusine and Bar",
"orderType": "takeout",
"taxState": 0.0925,
"storeInfo": [
"cart_storeId": "yqBCDmzaDP",
"cart_storeName": "Ibex Ethiopian Cusine and Bar",
"cart_storeImage": "https://res.cloudinary.com/http-get-tolofood-com/image/upload/c_scale,h_199,q_auto,w_270/v1461575640/Ibex_lopx38.jpg",
"cart_storeCuisine": "Ethiopian",
"cart_storeDescription": "We always serve a quality food. We always serve a quality food. We always serve a quality food. We always serve a quality food.",
"cart_storeRating": 3.33,
"cart_storeDelivery": false,
"takeout": true,
"address": "12255 Greenville Ave,Dallas, TX 75243",
"slugname": "TX_DAL_ibex_ethiopian_cuisine_and_bar",
"multiple_location": false,
"cart_storeDeliveryFee": 15,
"cart_storeServes": "Lunch,Dinner",
"busy": false,
"cart_storeSeoSlug": "ibex-ethiopian-cusine-and-bar"
],
"enable": true,
"voice_read_mi_label": "fbgcb",
"voice_read_mi_option": false,
"menuTypeName": "Standard"
]],
"lastOrderType": "takeout",
"searchedAddress": "takeout",
"timeData": [
"day": "06-05-2019",
"time": "12:55 am",
"tz": "America/Los_Angeles"
]
],
"unavailable_option": "restaurant_recommendation"
]