Im using Debezium to sync data from MySQL to S3. Now I want to make some changes.
Sample insert:
create table new (id int);
insert into new (1);
1. Custom Payload
{
"schema": {
"type": "struct",
bla bla bla
"optional": false,
"name": "_72.31.84.129.test.new.Envelope"
},
"payload": {
"before": null,
"after": {
"id": 10
},
"source": {
"version": "0.10.0.Final",
"connector": "mysql",
"name": "11.11.84.129",
"ts_ms": 1576605998000,
"snapshot": "false",
"db": "test",
"table": "new",
"server_id": 1,
"gtid": "3a7b90e9-207e-11ea-b3ed-121a0cbac3cb:51",
"file": "mysql-bin.000003",
"pos": 12770,
"row": 0,
"thread": 47,
"query": null
},
"op": "c",
"ts_ms": 1576605998231
}
}
I want to only push the payload option with some custom changes. I need to include the source,op,ts_ms are inside the payload.after.
Expected output:
{
"id": 10,
"source": {
"version": "0.10.0.Final",
"connector": "mysql",
"name": "11.11.84.129",
"ts_ms": 1576605998000,
"snapshot": "false",
"db": "test",
"table": "new",
"server_id": 1,
"gtid": "3a7b90e9-207e-11ea-b3ed-121a0cbac3cb:51",
"file": "mysql-bin.000003",
"pos": 12770,
"row": 0,
"thread": 47,
"query": null
},
"op": "c",
"ts_ms": 1576605998231
}
I don't want schema, payload.before. Im not sure how to get this output.
Check out the SMT for extracting the new record state. It will only propagate what's in after. Optionally, you can let it add chosen field from source, too.
...
transforms=unwrap
transforms.unwrap.type=io.debezium.transforms.ExtractNewRecordState
transforms.unwrap.add.source.fields=table,lsn
...
You cannot insert the op and ts_ms fields atm., but they can be propgated as message headers.
Related
I need help with jq syntax on how to return the Gitlab job ID if it contains an artifact. The JSON output looks like this (removed a lot of unrelated info from it and added [...]):
[{
"id": 3219589880,
"status": "success",
"stage": "test",
"name": "job_with_no_artifact",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.119Z",
"started_at": "2022-10-24T18:21:25.986Z",
"finished_at": "2022-10-24T18:21:38.464Z",
"duration": 12.478682,
"queued_duration": 0.499786,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
"pipeline": {
"id": 123456789,
[...]
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts": [],
"runner": {
"id": 12270859,
[...]
},
"artifacts_expire_at": null,
"tag_list": []
}, {
"id": 3219589878,
"status": "success",
"stage": "test",
"name": "create_artifact_job_2",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.111Z",
"started_at": "2022-10-24T18:21:25.922Z",
"finished_at": "2022-10-24T18:21:39.090Z",
"duration": 13.168405,
"queued_duration": 0.464364,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
},
"pipeline": {
"id": 675641982,
[...],
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts_file": {
"filename": "artifacts.zip",
"size": 223
},
"artifacts": [{
"file_type": "archive",
"size": 223,
"filename": "artifacts.zip",
"file_format": "zip"
}, {
"file_type": "metadata",
"size": 153,
"filename": "metadata.gz",
"file_format": "gzip"
}],
"runner": {
"id": 12270845,
[...]
},
"artifacts_expire_at": "2022-10-25T18:21:35.859Z",
"tag_list": []
}, {
"id": 3219589876,
"status": "success",
"stage": "test",
"name": "create_artifact_job_1",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.103Z",
"started_at": "2022-10-24T18:21:25.503Z",
"finished_at": "2022-10-24T18:21:41.407Z",
"duration": 15.904028,
"queued_duration": 0.098837,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
},
"pipeline": {
"id": 123456789,
[...]
},
"web_url": "WEB_URL",
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts_file": {
"filename": "artifacts.zip",
"size": 217
},
"artifacts": [{
"file_type": "archive",
"size": 217,
"filename": "artifacts.zip",
"file_format": "zip"
}, {
"file_type": "metadata",
"size": 152,
"filename": "metadata.gz",
"file_format": "gzip"
}],
"runner": {
"id": 12270857,
},
"artifacts_expire_at": "2022-10-25T18:21:37.808Z",
"tag_list": []
}]
I've been trying to do either of the following using jQ:
Either:
Check if artifacts_file key exists in each iteration and if it does return the (job) id (so .[].id)
Check if artifacts array is empty in each iteration and if it is empty return the (job) id.
In both cases I'm able to do the first part but I am not sure how to return the .id key.
Related stackoverflow questions that I've been trying to utilize and adapt to my case:
jq - return array value if its length is not null
How to check for presence of 'key' in jq before iterating over the values
What I have so far: jq '[.[].artifacts[]|select(length > 0)] | .[]' which returns all the artifacts found (but it doesn't contain the .id of the job).
Checking the existence of a field using has:
.[] | select(has("artifacts_file")).id
3219589878
3219589876
Demo
Checking if a field is an empty array by comparing it to []:
.[] | select(.artifacts == []).id
3219589880
Demo
I receive the following json from an vendor API call. I can pull the data.extendedProprty into a varchar column, but then I need to add code to break it down into entityId, reference. Is there a simpler way to have SQL reference that data?
Sample code
[
{
"data": {
"extendedProperty": "#{entityId=a56e2696-03ea-4550-8bd4-e52e52a49f9f; reference=/reference/extendedProperty/a56e2696-03ea-4550-8bd4-e52e52a49f9f; body=}",
"name": "A",
"displayOrder": 2
},
"id": {
"entityId": "6d960f08-1a6c-4b10-a8ab-dd6ce8cf5126",
"entityVersion": 1,
"entityOrigin": "BulkUpload",
"createdOn": "2015-04-29T18:51:31.77",
"deleted": false
}
},
{
"data": {
"extendedProperty": "#{entityId=f658af92-cb88-4f3d-9e71-e436e445a158; reference=/reference/extendedProperty/f658af92-cb88-4f3d-9e71-e436e445a158; body=}",
"name": "B",
"displayOrder": 2
},
"id": {
"entityId": "71cc0553-1d33-45b5-9097-2d0dbc11d84d",
"entityVersion": 1,
"entityOrigin": "BulkUpload",
"createdOn": "2018-12-10T21:44:38.607",
"deleted": false
}
}
]
so I am working with Clickup API, there we have a number of lists we would like to fetch the data from and insert that data as a wordpress post for our website.
I have tested all the API requests with Postman and the data i get back is similar to this, basically would need to fetch the data with "custom fields", but I am not sure how to work it out with PHP, any help would be appreciated.
"custom_fields": [
{
"id": "39ed2191-443e-4d45-84d4-de9eff89cc97",
"name": "Cost",
"type": "currency",
"type_config": {
"default": null,
"precision": 2,
"currency_type": "USD"
},
"date_created": "1616008796860",
"hide_from_guests": false,
"required": false
},
{
"id": "bcca51b8-a903-4194-8d24-8e663de0618e",
"name": "Deadline",
"type": "short_text",
"type_config": {},
"date_created": "1613070997077",
"hide_from_guests": false,
"required": false
},
{
"id": "35af20c5-5469-40b6-afc7-d7e9d5f3c451",
"name": "Industry",
"type": "drop_down",
"type_config": {
"default": 0,
"placeholder": null,
"new_drop_down": true,
"options": [
{
"id": "227658be-5cc6-4c33-a539-029c13a18416",
"name": "Agriculture",
"color": null,
"orderindex": 0
},
{
"id": "2d5041ff-e557-42ae-859a-51698d01d2f7",
"name": "Automation",
"color": null,
"orderindex": 1
},
{
"id": "d2c33aa5-de68-4f16-ad79-5308893c66a6",
"name": "Beauty",
"color": null,
"orderindex": 2
},
{
"id": "bcbf40c4-bcb8-41c4-81ed-7afffca9eccd",
"name": "Construction",
"color": null,
"orderindex": 3
},
{
"id": "47bc5b7d-0fb9-4c64-8887-249e55d31f85",
"name": "Sanitation",
"color": null,
"orderindex": 4
},
{
"id": "10b0e274-4996-4cc9-9c1e-4d44f78694d1",
"name": "Travel",
"color": null,
"orderindex": 5
}
]
},
"date_created": "1639080879165",
"hide_from_guests": false,
"required": false
},
Here's a very abstract description of the possible steps you'll need to take:
Fetch the data using wp_remote_request()
Parse the data using json_decode()
Get all the data you need from the object(-s)
Create a post using wp_insert_post()
Save all the additional data in the post(-s) meta fields using update_post_meta()
i can't parse this json with logstash... someone could help me?
seems like the way it is parsed can't be readed by logstash.
there is a ruby code to parse this?
I cannot extract the fields nested in the square brackets
[
{
"capacity": 0,
"created_at": "2021-04-06T16:18:34+02:00",
"decisions": [
{
"duration": "22h16m4.141220361s",
"id": 842,
"origin": "CAPI",
"scenario": "crowdsecurity/http-bad-user-agent",
"scope": "ip",
"simulated": false,
"type": "ban",
"value": "3.214.184.223/32"
},
.
.
.
{
"duration": "22h16m4.195897491s",
"id": 904,
"origin": "CAPI",
"scenario": "crowdsecurity/http-backdoors-attempts",
"scope": "ip",
"simulated": false,
"type": "ban",
"value": "51.68.11.195/32"
}
],
"events": null,
"events_count": 0,
"id": 12,
"labels": null,
"leakspeed": "",
"machine_id": "N/A",
"message": "",
"scenario": "update : +63/-0 IPs",
"scenario_hash": "",
"scenario_version": "",
"simulated": false,
"source": {
"scope": "Community blocklist",
"value": ""
},
"start_at": "2021-04-06 16:18:34.750588276 +0200 +0200",
"stop_at": "2021-04-06 16:18:34.750588717 +0200 +0200"
}
]
Require JSON
JSON.parse(yourString)
Would likely be what you're looking for.
The module is described here
I am using QuickBooks Online Plus, which means i can edit the item. I would like to use the API to change the on hand # for an item. I've created an item "test1" through QuickBooks Online Plus. When i read the item from API i got the following in the attached json file. things looks great as follow:
{
"QueryResponse": {
"Item": [
{
"Name": "test1",
"Active": true,
"FullyQualifiedName": "test1",
"Taxable": false,
"UnitPrice": 3,
"Type": "Inventory",
"IncomeAccountRef": {
"value": "60",
"name": "Sales of Product Income"
},
"PurchaseCost": 1,
"ExpenseAccountRef": {
"value": "61",
"name": "Cost of Goods Sold"
},
"AssetAccountRef": {
"value": "62",
"name": "Inventory Asset"
},
"TrackQtyOnHand": true,
"QtyOnHand": 6,
"InvStartDate": "2015-12-02",
"domain": "QBO",
"sparse": false,
"Id": "19",
"SyncToken": "1",
"MetaData": {
"CreateTime": "2015-12-01T14:38:23-08:00",
"LastUpdatedTime": "2015-12-01T14:38:42-08:00"
}
}
],
"startPosition": 1,
"maxResults": 1
},
"time": "2015-12-02T09:59:29.936-08:00"
}
But when i tried to update that item using the json object below:
{
"Name": "test1",
"Active": true,
"Taxable": false,
"UnitPrice": 3,
"Type": "Inventory",
"IncomeAccountRef": {
"value": "60",
"name": "Sales of Product Income"
},
"PurchaseCost": 1,
"ExpenseAccountRef": {
"value": "61",
"name": "Cost of Goods Sold"
},
"AssetAccountRef": {
"value": "62",
"name": "Inventory Asset"
},
"TrackQtyOnHand": true,
"QtyOnHand": 16,
"InvStartDate": "2015-12-02",
"domain": "QBO",
"sparse": false,
"Id": "19",
"SyncToken": "2"
}
, i got an error like this:
{"Fault":{"Error":[{"Message":"Stale Object Error","Detail":"Stale Object Error : You and seven.li#hotschedules.com were working on this at the same time. seven.li#hotschedules.com finished before you did, so your work was not saved.","code":"5010","element":""}],"type":"ValidationFault"},"time":"2015-12-02T10:42:52.466-08:00"}
I would like to update the on hand quantity. Does anyone know what's wrong and how to do it? Thanks.
The problem is with the "SyncToken". I believe when you try to update the new item, you should not increment the "SyncToken", you should keep it the same. QBO will update the "SyncToken" for you.