Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read entire JSON file and apply remap ? #21262

Closed
sankyfunky opened this issue Sep 10, 2024 Discussed in #21261 · 1 comment
Closed

How to read entire JSON file and apply remap ? #21262

sankyfunky opened this issue Sep 10, 2024 Discussed in #21261 · 1 comment

Comments

@sankyfunky
Copy link

Discussed in #21261

Originally posted by sankyfunky September 10, 2024
I have the use case where I have the valid JSON files are being generated in a folder.

I want to parse those file and extract events from it.

file01.json and other files are all same format like this.

{
    "scan_data": {
        "version": 1,
        "ip_info": "",
        "hostname": "examplehost.example.com"
    },
    "vulnerabilities": [
        {
            "id": 1001,
            "status": "",
            "secure": false,
            "details": "some details",
            "title": "ICMP Responses Logged"
        },
        {
            "id": 1002,
            "status": "",
            "secure": false,
            "details": "some details",
            "title": "Resolved DNS Name"
        }
    ]
}

events needs to be generated
event01

 {
        "version": 1,
        "ip_info": "",
        "hostname": "examplehost.example.com",
        "id": 1001,
        "status": "",
        "secure": false,
        "details": "some details",
        "title": ""title": "Resolved DNS Name""
}

event02

{
        "version": 1,
        "ip_info": "",
        "hostname": "examplehost.example.com",
        "id": 1002,
        "status": "",
        "secure": false,
        "details": "some details",
        "title": "ICMP Responses Logged"
}

Just like that. I want all events to be streamed.

how should I write my source and transform config.

this is what i have but it reads line by line and I can't parse json. Is it something available out of the box ?

data_dir = "/Users/folder/vector_data/"

[sources.file_source]
  type = "file"
  include = [ "/Users/folder/hs_logs/result/*.json" ]
  read_from = "beginning"

[transforms.asep_transform]
  type = "remap"
  inputs = ["file_source"]
  source = '''
    . = parse_json!(.message)
  '''

[sinks.console]
  type = "console"
  inputs = ["asep_transform"]
  target = "stdout"
  encoding.codec = "json"
@jszwedko
Copy link
Member

Closing since this is a discussion rather than an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants