
API Ruby class
192
# output until we "cancel" the command. We only want to receive 10 responses:
$reply_limit = 10
# Execute the command:
$reply_count = 0
connection.get_reply_each(
"/interface/monitor-traffic",
"=interface=ether1",
"=.proplist=rx-bits-per-second,tx-bits-per-second"
) do |request_object, reply_sentence|
if reply_sentence.key?('!re') # We only pay attention to reply sentences
# Print the reply sentence:
p reply_sentence
# Increment the reply counter:
$reply_count += 1
# If we've reached our reply goal, cancel:
if $reply_count >= $reply_limit
# Cancel this command request:
request_object.cancel
end
end
end
connection.close
</noqiki>
Here's an example of output:
<<< '/login' (6)
<<< '.tag=0' (6)
<<< END-OF-SENTENCE
>>> '!done' (5)
>>> 'ret=cb21408d7123ebfc96bec24effe3409f' (36)
>>> '.tag=0' (6)
>>> END-OF SENTENCE
<<< '/login' (6)
<<< '=name=admin' (11)
<<< '=response=0ce20d1ed4bd3ef821dc203a1ff2698461' (44)
<<< '.tag=1' (6)
<<< END-OF-SENTENCE
>>> '!done' (5)
>>> '.tag=1' (6)
>>> END-OF SENTENCE
Comentários a estes Manuais