Skip to content

Commit 5537348

Browse files
committed
Addes Statistics support from the API. When typing status in a hardware bridge it will also print packet statistics.
Signed-off-by: Craig Smith <[email protected]>
1 parent c4a6cc1 commit 5537348

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

lib/rex/post/hwbridge/client.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def get_status
6363
send_request("/status")
6464
end
6565

66+
#
67+
# Gets the devices statistics
68+
#
69+
def get_statistics
70+
send_request("/statistics")
71+
end
72+
6673
#
6774
# Fetches custom methods from HW, if any
6875
#

lib/rex/post/hwbridge/ui/console/command_dispatcher/core.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def cmd_info_tabs(*args)
161161
def cmd_status_help
162162
print_line("Usage: status")
163163
print_line
164-
print_line "Retrives the devices current status and capabilities"
164+
print_line "Retrives the devices current status and statistics"
165165
end
166166

167167
#
@@ -173,15 +173,20 @@ def cmd_status(*args)
173173
return true
174174
end
175175
status = client.get_status
176+
stats = client.get_statistics
176177
if status.has_key? 'operational'
177178
op = 'Unknown'
178179
op = 'Yes' if status['operational'] == 1
179180
op = 'No' if status['operational'] == 2
180181
print_status("Operational: #{op}")
181182
end
182-
print_status("Device: #{status['device_name']}") if status.has_key? 'device_name'
183-
print_status("FW Version: #{status['fw_version']}") if status.has_key? 'fw_version'
184-
print_status("HW Version: #{status['hw_version']}") if status.has_key? 'hw_version'
183+
print_status("Device: #{status['device_name']}") if status.key? 'device_name'
184+
print_status("FW Version: #{status['fw_version']}") if status.key? 'fw_version'
185+
print_status("HW Version: #{status['hw_version']}") if status.key? 'hw_version'
186+
print_status("Uptime: #{stats["uptime"]} seconds") if stats.key? "uptime"
187+
print_status("Packets Sent: #{stats["packet_stats"]}") if stats.key? "packet_stats"
188+
print_status("Last packet Sent: #{Time.at(stats["last_request"])}") if stats.key? "last_request"
189+
print_status("Voltage: #{stats["voltage"]}") if stats.key? "voltage" and not stats["voltage"] == "not supported"
185190
end
186191

187192
def cmd_specialty_help

modules/auxiliary/server/local_hwbridge.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def initialize(info = {})
4141
@server_started = Time.new
4242
@can_interfaces = []
4343
@pkt_response = {} # Candump returned packets
44+
@packets_sent = 0
45+
@last_sent = nil
4446
end
4547

4648
def detect_can
@@ -72,8 +74,8 @@ def get_status
7274
def get_statistics
7375
stats = {}
7476
stats["uptime"] = Time.now - @server_started
75-
stats["packet_stats"] = "not supported"
76-
stats["last_request"] = "not supported"
77+
stats["packet_stats"] = @packets_sent
78+
stats["last_request"] = @last_sent if @last_sent
7779
stats["voltage"] = "not supported"
7880
stats
7981
end
@@ -134,6 +136,8 @@ def cansend(bus, id, data)
134136
@can_interfaces.each do |can|
135137
if can == bus
136138
system("cansend #{bus} #{id}##{bytes.join}")
139+
@packets_sent += 1
140+
@last_sent = Time.now.to_i
137141
result["Success"] = true if $?.success?
138142
end
139143
end
@@ -194,6 +198,8 @@ def isotp_send_and_wait(bus, srcid, dstid, data, timeout = 2000, maxpkts = 3)
194198
if can == bus
195199
candump(bus, dstid, timeout, maxpkts)
196200
system("cansend #{bus} #{srcid}##{bytes}")
201+
@packets_sent += 1
202+
@last_sent = Time.now.to_i
197203
result["Success"] = true if $?.success?
198204
result["Packets"] = []
199205
$candump_sniffer.join

0 commit comments

Comments
 (0)