HTTP의 Content-Type 헤더가 application/octet-stream인 경우, (Content-Encoding에 따라 디코딩한 후) 데이터는 가공되지 않은 8비트 데이터라는 뜻이며, 전송자는 해당 데이터가 실제로 어떤 타입인지 모른다는 것을 의미합니다. 보다 구체적인 Content-Type이 없으면, 데이터가 실제로 무엇을 나타내는지 알 수 없기 때문에, 원시 데이터를 분석하고 추측에 의존할 수밖에 없습니다. 물론, 다른 방법을 통해 데이터의 의미를 알고 있다면 그에 따라 처리할 수 있습니다.
보통 바이너리 데이터 포맷은 데이터 맨 앞에 데이터가 무엇인지 식별할 수 있도록 헤더나 시그니처를 가지고 있습니다. 그래서 먼저 그것부터 확인하는 것이 일반적입니다.
데이터 타입을 식별할 수 있을 때까지는, 어떤 바이트가 어떤 종류의 값을 나타내는지, 멀티 바이트 값에 어떤 엔디언(Endian) 방식을 사용하는지 등을 알 수 없습니다. 요약하면, 다운로드한 데이터를 처리하려면 데이터에 대한 추가 정보가 필요합니다.
Web Service Setup
# pip install flask
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/test')
def test():
data = b"This is raw binary data" # bytes-like object
return Response(data, mimetype='application/octet-stream')
if __name__ == '__main__':
app.run(debug=True)
from flask import Flask, request
app = Flask(__name__)
@app.route('/upload', methods=['POST'])
def upload_file():
binary_data = request.get_data() # Raw binary
with open('received_file.bin', 'wb') as f:
f.write(binary_data)
return 'File received and saved!', 200
if __name__ == '__main__':
app.run(debug=True)
curl -X POST http://127.0.0.1:5000/test \
-H "Content-Type: application/octet-stream" \
--data-binary @your_file.bin
import requests
with open("your_file.bin", "rb") as f:
data = f.read()
response = requests.post(
"http://127.0.0.1:5000/test",
headers={"Content-Type": "application/octet-stream"},
data=data
)
print(response.text)
input {
stdin{}
}
filter {
ruby {
path => "/usr/share/logstash/tobinary.rb"
}
}
output {
stdout {
codec => rubydebug
}
file {
path => "/usr/share/logstash/outputfile.bin"
codec => line { format => "%{binary_payload}" }
}
http {
url => "http://172.16.4.128:5000/upload"
http_method => "post"
content_type => "application/octet-stream"
format => "message"
message => "%{binary_payload}"
headers => {
"X-Content-Length" => "%{binary_size}"
}
}
}
def filter(event)
str1 = "0000111200001100"
str2 = "00000000"
str3 = "1.0"
str4 = "KO"
str5 = "D"
str6 = " "
str7 = "172.16.4.201"
str8 = "EAI"
str9 = "한글"
str10 = " @@"
combined = "#{str1}#{str2}#{str3}#{str4}#{str5}#{str6}#{str7}#{str8}#{str9}#{str10}"
#binary_data = combined.force_encoding("ASCII-8BIT")
utf_data = combined.encode("UTF-8")
#ascii_data = utf_data.force_encoding("ASCII-8BIT")
event.set("binary_payload", utf_data.bytes)
event.set("binary_size", utf_data.bytesize)
#event.set("binary_payload", binary_data)
#event.set("binary_size", binary_data.bytesize)
return [event]
end'제품 > ELK' 카테고리의 다른 글
| logstash - db query 1 (0) | 2025.05.02 |
|---|---|
| syslog 분석 중 (0) | 2025.04.02 |
| logstash jdbc input 플러그인 (0) | 2025.03.27 |
| Webhook 커넥터 테스트 (0) | 2025.02.22 |
| 데이터 가져오기 (0) | 2025.02.15 |