Last active
July 1, 2020 14:17
-
-
Save matsubo/488d23a674231bacf4032fc9cc37088f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
Bundler.require | |
class Rtx830 | |
def initialize(hash = {}) | |
username = hash[:username] || 'admin' | |
password = hash[:password] || 'admin' | |
database = hash[:database] || 'db0' | |
@name = hash[:name] || 'rtx830' | |
@influxdb = InfluxDB::Client.new database, username: username, password: password | |
@router = hash[:router] || '192.168.1.1' | |
@logger = Logger.new(STDOUT) | |
end | |
def arp | |
command = 'show arp' | |
value = `./rtx_command.sh #{@router} "#{command}" | grep "Count" | awk '{print $2}' | tr -d '\r\n'` | |
data = { | |
values: { value: value.to_i }, | |
tags: { wave: 'arp' } | |
} | |
@influxdb.write_point(@name, data) | |
@logger.info(data) | |
end | |
def dhcp | |
command = 'show status dhcp' | |
value = `./rtx_command.sh #{@router} "#{command}" | grep "Usable" | awk '{print $2}' | tr -d '\r\n'` | |
data = { | |
values: { value: value.to_i }, | |
tags: { wave: 'dhcp_usable' } | |
} | |
@influxdb.write_point(@name, data) | |
@logger.info(data) | |
end | |
def nat | |
command = 'show nat descriptor masquerade session summary' | |
value = `./rtx_command.sh #{@router} "#{command}" | grep "PP" | awk '{print $4}' | awk -F '/' '{print $1}' | tr -d '\r\n'` | |
data = { | |
values: { value: value.to_i }, | |
tags: { wave: 'nat' } | |
} | |
@influxdb.write_point(@name, data) | |
@logger.info(data) | |
end | |
def session_pp1 | |
command = 'show ip connection summary' | |
value = `./rtx_command.sh #{@router} "#{command}" | grep "PP" | awk '{print $3}' | tr -d '\r\n'` | |
data = { | |
values: { value: value.to_i }, | |
tags: { wave: 'session_pp1' } | |
} | |
@influxdb.write_point(@name, data) | |
@logger.info(data) | |
end | |
def session_tunnel1 | |
command = 'show ip connection summary' | |
value = `./rtx_command.sh #{@router} "#{command}" | grep "TUNNEL" | awk '{print $3}' | tr -d '\r\n'` | |
data = { | |
values: { value: value.to_i }, | |
tags: { wave: 'session_tunnel1' } | |
} | |
@influxdb.write_point(@name, data) | |
@logger.info(data) | |
end | |
def nat_1000 | |
command = 'show nat descriptor masquerade session 1000 summary' | |
value = `./rtx_command.sh #{@router} "#{command}" | grep "PP" | awk '{print $4}' | cut -d '/' -f 1 | tr -d '\r\n'` | |
data = { | |
values: { value: value.to_i }, | |
tags: { wave: 'nat_1000' } | |
} | |
@influxdb.write_point(@name, data) | |
@logger.info(data) | |
end | |
def nat_20000 | |
command = 'show nat descriptor masquerade session 20000 summary' | |
value = `./rtx_command.sh #{@router} "#{command}" | grep "TUNNEL" | awk '{print $4}' | cut -d '/' -f 1 | tr -d '\r\n'` | |
data = { | |
values: { value: value.to_i }, | |
tags: { wave: 'nat_20000' } | |
} | |
@influxdb.write_point(@name, data) | |
@logger.info(data) | |
end | |
end | |
rtx830 = Rtx830.new | |
rtx830.arp | |
rtx830.dhcp | |
rtx830.nat | |
rtx830.session_pp1 | |
rtx830.session_tunnel1 | |
rtx830.nat_1000 | |
rtx830.nat_20000 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment