Commit 6856a089 authored by Cool Fire's avatar Cool Fire
Browse files

Minor cleanups

parent d41fd77e
# frozen_string_literal: true
# /usr/bin/env ruby
require 'net/http'
......@@ -9,12 +10,12 @@ config = YAML.load_file 'config.yaml'
uri = URI("#{config['url']}#{config['ip']}")
data = nil
result = {
'ok' => true,
'rrcs' => {}
}
'ok' => true,
'rrcs' => {}
}
# Make HTTP API request and parse response
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
request = Net::HTTP::Get.new uri
response = http.request request
data = YAML.load response.body
......@@ -31,8 +32,8 @@ end
data['data']['rrcs'].each do |rrc|
result['rrcs'][rrc['rrc']] = {}
result['rrcs'][rrc['rrc']]['location'] = rrc['location']
result['rrcs'][rrc['rrc']]['badasns'] = []
result['rrcs'][rrc['rrc']]['badroutes'] = []
result['rrcs'][rrc['rrc']]['badasns'] = []
result['rrcs'][rrc['rrc']]['badroutes'] = []
rrc['peers'].each do |peer|
unless config['asn'].include? peer['asn_origin']
......@@ -41,8 +42,8 @@ data['data']['rrcs'].each do |rrc|
end
unless config['asn'].include? peer['as_path'].split.last.to_i
result['ok'] = false
result['rrcs'][rrc['rrc']]['badroutes'].push " AS path: #{peer['as_path']}"
result['ok'] = false
result['rrcs'][rrc['rrc']]['badroutes'].push " AS path: #{peer['as_path']}"
end
end
end
......@@ -57,7 +58,7 @@ end
if result['ok'] == false || config['verbose']
result['rrcs'].each do |rrc, data|
print "#{rrc} (#{data['location']}): "
if data['badasns'].size == 0 && data['badroutes'].size == 0
if data['badasns'].empty? && data['badroutes'].empty?
puts 'OK'
else
puts 'FAIL'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment