如何在bash中创建从文件中获取输入的骨架脚本.JSON(文件表示设备)



我需要在bash中创建脚本,该脚本将json文件作为文件夹中的输入。假设json文件如下所示:

{"mac_address": null, "serial_number": "A-HCI1", "device_type": "STORAGE", "device_model": "NIMBLE DHCI STORAGE", "part_number": "6790", "extra_attributes": [
{"attribute_type": "ENTITLEMENT_ID", "attribute_value": "YIZUYYNEYSFO9ghhhgAU"}

然后CCS在Kafka事件的事件数据字段中引用json-一个有效的Kafka活动看起来像

{
"specversion": "4.0",
"id": "(i will be using uuid genereator for that",
"source": "CCS",
"type": "DEVICE_PROVISION_EVENT",
"time": "local time",
"data": "{"mac_address": null, "serial_number": "ADL23231", "device_type": "DHCI_STORAGE", "device_model": "NIMBLE DHCI STORAGE", "part_number": "6320", "extra_attributes": [{"attribute_type": "ENTITLEMENT_ID", "attribute_value": "YIZUYYNEYSFO9ZV0LVAU"}],"tag_entities": [], "platform_customer_id": "a07db108sadasd33325ee95", "application_customer_id": "31187723dfd32a93178", "folder_name": null}"
}

如果将JSON扁平化为一行,则只需输入到kafka控制台的消费者

kafka-console-producer.sh --topic foo --bootstrap-server localhost:9092 < data.json

但从您之前的问题来看,为了获得灵活性,您最好坚持使用基于Python或Go的生产者脚本,而不是shell脚本。

最新更新