ltm rule command MQTT payload
iRule(1) BIG-IP TMSH Manual iRule(1)
MQTT::payload
Manipulate payload of MQTT PUBLISH message
SYNOPSIS
MQTT::payload (('length') |
('replace' CONTENT) |
('prepend' CONTENT) |
('append' CONTENT))?
DESCRIPTION
This command can be used to manipulate payload of MQTT message. This command is valid only for following MQTT
message types:
PUBLISH
Syntax
MQTT::payload [ length | replace | prepend | append ]
MQTT::payload
* Returns the collected payload obtained as a result of a prior call to MQTT::collect.
This command should be called without an argument only from MQTT_CLIENT_DATA or MQTT_SERVER_DATA events.
MQTT::payload length
* Returns the length of payload of MQTT PUBLISH message.
Make sure to call this method and call MQTT::collect only when payload length is not zero.
MQTT::payload replace
* Replace the entire payload of the MQTT PUBLISH message with specified .
MQTT::payload prepend
* Add the specified to the beginning of the payload of MQTT PUBLISH message.
MQTT::payload append
* Add the specified to the end of the collected payload of MQTT PUBLISH message.
For this command to work, MQTT::collect must be called prior to calling this.
This command should be called only from MQTT_CLIENT_DATA or MQTT_SERVER_DATA events.
Please note that in order to append the at the end of payload, the MQTT::collect
must collect entire payload. If collect is partial, this command will append to
the end of the data collected at the time this command is invoked. This can happen when
MQTT::collect is called with a length smaller than the payload length as the argument.
RETURN VALUE
When called without an argument, this command returns the collected payload of MQTT PUBLISH message.
VALID DURING
MQTT_CLIENT_INGRESS MQTT_CLIENT_DATA MQTT_SERVER_INGRESS MQTT_SERVER_DATA
EXAMPLES
#Example: Redirect PUBLISH that has payloads with blocked keywords defined in
#blacklisted_keywords_datagroup in first 200 bytes. Prepend a admin message in
#the payload.
#
when MQTT_CLIENT_INGRESS {
set type [MQTT::type]
switch $type {
"PUBLISH" {
if { [class exists blacklisted_keywords_datagroup] } {
MQTT::collect 200
}
}
}
}
when MQTT_CLIENT_DATA {
set type [MQTT::type]
switch $type {
"PUBLISH" {
set payload [MQTT::payload]
set found [class match $payload contains blacklisted_keywords_datagroup]
if { $found != "" } {
set topic [MQTT::topic]
MQTT::topic "/bigip/quarantined/$topic"
MQTT::payload prepend "!!!!!! QUARANTINED Message !!!!!!"
}
MQTT::release
}
}
}
HINTS
SEE ALSO
CHANGE LOG
@BIGIP-13.0.0 --First introduced the command.
BIG-IP 2020-06-23 iRule(1)