mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-13 14:17:54 +00:00
Implement the AMQP BasicDeliver
This commit is contained in:
parent
75899a9868
commit
5effd97c27
@ -118,29 +118,7 @@ func emitBasicPublish(event BasicPublish, connectionInfo *api.ConnectionInfo, em
|
|||||||
emitter.Emit(item)
|
emitter.Emit(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
func representBasicPublish(event map[string]interface{}) []interface{} {
|
func representProperties(properties map[string]interface{}, rep []interface{}) ([]interface{}, string, string) {
|
||||||
rep := make([]interface{}, 0)
|
|
||||||
|
|
||||||
details, _ := json.Marshal([]map[string]string{
|
|
||||||
{
|
|
||||||
"name": "Exchange",
|
|
||||||
"value": event["Exchange"].(string),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Immediate",
|
|
||||||
"value": strconv.FormatBool(event["Immediate"].(bool)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Mandatory",
|
|
||||||
"value": strconv.FormatBool(event["Mandatory"].(bool)),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
rep = append(rep, map[string]string{
|
|
||||||
"type": "table",
|
|
||||||
"title": "details",
|
|
||||||
"data": string(details),
|
|
||||||
})
|
|
||||||
|
|
||||||
contentType := ""
|
contentType := ""
|
||||||
contentEncoding := ""
|
contentEncoding := ""
|
||||||
deliveryMode := ""
|
deliveryMode := ""
|
||||||
@ -154,8 +132,6 @@ func representBasicPublish(event map[string]interface{}) []interface{} {
|
|||||||
userId := ""
|
userId := ""
|
||||||
appId := ""
|
appId := ""
|
||||||
|
|
||||||
properties := event["Properties"].(map[string]interface{})
|
|
||||||
|
|
||||||
if properties["ContentType"] != nil {
|
if properties["ContentType"] != nil {
|
||||||
contentType = properties["ContentType"].(string)
|
contentType = properties["ContentType"].(string)
|
||||||
}
|
}
|
||||||
@ -249,44 +225,168 @@ func representBasicPublish(event map[string]interface{}) []interface{} {
|
|||||||
"data": string(props),
|
"data": string(props),
|
||||||
})
|
})
|
||||||
|
|
||||||
headers := make([]map[string]string, 0)
|
return rep, contentType, contentEncoding
|
||||||
for name, value := range properties["Headers"].(map[string]interface{}) {
|
}
|
||||||
headers = append(headers, map[string]string{
|
|
||||||
"name": name,
|
func representBasicPublish(event map[string]interface{}) []interface{} {
|
||||||
"value": value.(string),
|
rep := make([]interface{}, 0)
|
||||||
})
|
|
||||||
}
|
details, _ := json.Marshal([]map[string]string{
|
||||||
headersMarshaled, _ := json.Marshal(headers)
|
{
|
||||||
|
"name": "Exchange",
|
||||||
|
"value": event["Exchange"].(string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Routing Key",
|
||||||
|
"value": event["RoutingKey"].(string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mandatory",
|
||||||
|
"value": strconv.FormatBool(event["Mandatory"].(bool)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Immediate",
|
||||||
|
"value": strconv.FormatBool(event["Immediate"].(bool)),
|
||||||
|
},
|
||||||
|
})
|
||||||
rep = append(rep, map[string]string{
|
rep = append(rep, map[string]string{
|
||||||
"type": "table",
|
"type": "table",
|
||||||
"title": "Headers",
|
"title": "Details",
|
||||||
"data": string(headersMarshaled),
|
"data": string(details),
|
||||||
})
|
})
|
||||||
|
|
||||||
rep = append(rep, map[string]string{
|
properties := event["Properties"].(map[string]interface{})
|
||||||
"type": "body",
|
rep, contentType, contentEncoding := representProperties(properties, rep)
|
||||||
"title": "Body",
|
|
||||||
"encoding": contentEncoding,
|
if properties["Headers"] != nil {
|
||||||
"mime_type": contentType,
|
headers := make([]map[string]string, 0)
|
||||||
"data": event["Body"].(string),
|
for name, value := range properties["Headers"].(map[string]interface{}) {
|
||||||
}) // FIXME: `Body` value seems wrong
|
headers = append(headers, map[string]string{
|
||||||
|
"name": name,
|
||||||
|
"value": value.(string),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
headersMarshaled, _ := json.Marshal(headers)
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "table",
|
||||||
|
"title": "Headers",
|
||||||
|
"data": string(headersMarshaled),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if event["Body"] != nil {
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "body",
|
||||||
|
"title": "Body",
|
||||||
|
"encoding": contentEncoding,
|
||||||
|
"mime_type": contentType,
|
||||||
|
"data": event["Body"].(string),
|
||||||
|
}) // FIXME: `Body` value seems wrong
|
||||||
|
}
|
||||||
|
|
||||||
return rep
|
return rep
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEventBasicDeliver(eventBasicDeliver BasicDeliver) {
|
func emitBasicDeliver(event BasicPublish, connectionInfo *api.ConnectionInfo, emitter api.Emitter) {
|
||||||
return
|
request := &api.GenericMessage{
|
||||||
fmt.Printf(
|
IsRequest: true,
|
||||||
"[%s] ConsumerTag: %s, DeliveryTag: %d, Redelivered: %t, Exchange: %s, RoutingKey: %s, Properties: %v, Body: %s\n",
|
CaptureTime: time.Now(),
|
||||||
basicMethodMap[60],
|
Payload: AMQPPayload{
|
||||||
eventBasicDeliver.ConsumerTag,
|
Type: "basic_deliver",
|
||||||
eventBasicDeliver.DeliveryTag,
|
Data: &AMQPWrapper{
|
||||||
eventBasicDeliver.Redelivered,
|
Method: basicMethodMap[60],
|
||||||
eventBasicDeliver.Exchange,
|
Url: event.Exchange,
|
||||||
eventBasicDeliver.RoutingKey,
|
Details: event,
|
||||||
eventBasicDeliver.Properties,
|
},
|
||||||
eventBasicDeliver.Body,
|
},
|
||||||
)
|
}
|
||||||
|
item := &api.OutputChannelItem{
|
||||||
|
Protocol: protocol,
|
||||||
|
Timestamp: time.Now().UnixNano() / int64(time.Millisecond),
|
||||||
|
ConnectionInfo: connectionInfo,
|
||||||
|
Pair: &api.RequestResponsePair{
|
||||||
|
Request: *request,
|
||||||
|
Response: api.GenericMessage{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
emitter.Emit(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
func representBasicDeliver(event map[string]interface{}) []interface{} {
|
||||||
|
rep := make([]interface{}, 0)
|
||||||
|
|
||||||
|
consumerTag := ""
|
||||||
|
deliveryTag := ""
|
||||||
|
redelivered := ""
|
||||||
|
|
||||||
|
if event["ConsumerTag"] != nil {
|
||||||
|
consumerTag = event["ConsumerTag"].(string)
|
||||||
|
}
|
||||||
|
if event["DeliveryTag"] != nil {
|
||||||
|
deliveryTag = fmt.Sprintf("%g", event["DeliveryTag"].(float64))
|
||||||
|
}
|
||||||
|
if event["Redelivered"] != nil {
|
||||||
|
redelivered = strconv.FormatBool(event["Redelivered"].(bool))
|
||||||
|
}
|
||||||
|
|
||||||
|
details, _ := json.Marshal([]map[string]string{
|
||||||
|
{
|
||||||
|
"name": "Consumer Tag",
|
||||||
|
"value": consumerTag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delivery Tag",
|
||||||
|
"value": deliveryTag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Redelivered",
|
||||||
|
"value": redelivered,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Exchange",
|
||||||
|
"value": event["Exchange"].(string),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Routing Key",
|
||||||
|
"value": event["RoutingKey"].(string),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "table",
|
||||||
|
"title": "Details",
|
||||||
|
"data": string(details),
|
||||||
|
})
|
||||||
|
|
||||||
|
properties := event["Properties"].(map[string]interface{})
|
||||||
|
rep, contentType, contentEncoding := representProperties(properties, rep)
|
||||||
|
|
||||||
|
if properties["Headers"] != nil {
|
||||||
|
headers := make([]map[string]string, 0)
|
||||||
|
for name, value := range properties["Headers"].(map[string]interface{}) {
|
||||||
|
headers = append(headers, map[string]string{
|
||||||
|
"name": name,
|
||||||
|
"value": value.(string),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
headersMarshaled, _ := json.Marshal(headers)
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "table",
|
||||||
|
"title": "Headers",
|
||||||
|
"data": string(headersMarshaled),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if event["Body"] != nil {
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "body",
|
||||||
|
"title": "Body",
|
||||||
|
"encoding": contentEncoding,
|
||||||
|
"mime_type": contentType,
|
||||||
|
"data": event["Body"].(string),
|
||||||
|
}) // FIXME: `Body` value seems wrong
|
||||||
|
}
|
||||||
|
|
||||||
|
return rep
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEventQueueDeclare(eventQueueDeclare QueueDeclare) {
|
func printEventQueueDeclare(eventQueueDeclare QueueDeclare) {
|
||||||
|
@ -106,7 +106,7 @@ func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, em
|
|||||||
emitBasicPublish(*eventBasicPublish, connectionInfo, emitter)
|
emitBasicPublish(*eventBasicPublish, connectionInfo, emitter)
|
||||||
case *BasicDeliver:
|
case *BasicDeliver:
|
||||||
eventBasicDeliver.Body = f.Body
|
eventBasicDeliver.Body = f.Body
|
||||||
printEventBasicDeliver(*eventBasicDeliver)
|
emitBasicDeliver(*eventBasicPublish, connectionInfo, emitter)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,6 +265,9 @@ func (d dissecting) Represent(entry string) ([]byte, error) {
|
|||||||
case basicMethodMap[40]:
|
case basicMethodMap[40]:
|
||||||
repRequest = representBasicPublish(details)
|
repRequest = representBasicPublish(details)
|
||||||
break
|
break
|
||||||
|
case basicMethodMap[60]:
|
||||||
|
repRequest = representBasicDeliver(details)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
// response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
// response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||||
// repRequest := representRequest(request)
|
// repRequest := representRequest(request)
|
||||||
|
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AMQPPayload struct {
|
type AMQPPayload struct {
|
||||||
@ -16,10 +15,11 @@ type AMQPPayloader interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h AMQPPayload) MarshalJSON() ([]byte, error) {
|
func (h AMQPPayload) MarshalJSON() ([]byte, error) {
|
||||||
switch h.Type {
|
return json.Marshal(h.Data)
|
||||||
case "basic_publish":
|
// switch h.Type {
|
||||||
return json.Marshal(h.Data)
|
// case "basic_publish":
|
||||||
default:
|
// return json.Marshal(h.Data)
|
||||||
panic(fmt.Sprintf("AMQP payload cannot be marshaled: %s\n", h.Type))
|
// default:
|
||||||
}
|
// panic(fmt.Sprintf("AMQP payload cannot be marshaled: %s\n", h.Type))
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user