Comments (4)
And you're specifically providing in your source (sql or 'router.db') 'ip' field, instead of 'name' field, or you're providing both? And what you want is node.rb to also accept that source can provide 'ip'?
If I understood correctly, I think it's useful. And I'm wondering why #length > 0? Wouldn't just 'if opt[:ip]' work? Or is there case when it's defined but it's empty?
@ip = opt[:ip]
@ip ||= Resolve.getaddress @name
So if opt[:ip] is defined, we use it, if it's not defined, we try to resolve?
Should we try to validate it being actually IP adddress?
Something like this maybe?
[[email protected] ~]% pry -r ipaddr
[1] pry(main)> ip_src = '192.0.2.42'
=> "192.0.2.42"
[2] pry(main)> ip = IPAddr.new(ip_src).to_s rescue nil
=> "192.0.2.42"
[3] pry(main)> ip ||= 'name'
=> "192.0.2.42"
[4] pry(main)> ip_src = '2001:db8::42'
=> "2001:db8::42"
[5] pry(main)> ip = IPAddr.new(ip_src).to_s rescue nil
=> "2001:db8::42"
[6] pry(main)> ip ||= 'name'
=> "2001:db8::42"
[7] pry(main)> ip_src = ''
=> ""
[8] pry(main)> ip = IPAddr.new(ip_src).to_s rescue nil
=> nil
[9] pry(main)> ip ||= 'name'
=> "name"
[10] pry(main)> ip_src = nil
=> nil
[11] pry(main)> ip = IPAddr.new(ip_src).to_s rescue nil
=> nil
[12] pry(main)> ip ||= 'name'
=> "name"
[13] pry(main)>
from oxidized.
I should have included my config :) I am providing both, like this:
source:
default: sql
sql:
adapter: sqlite
database: "/home/oxidized/devices.db"
table: devices
map:
name: name
ip: ipv4
model: model
In the database the "name" column is our friendly name of the device.
I think checking the length is good as if somebody inserts into the database a hostname with an empty "ipv4" column then it will attempt to resolve the host. Of course, it should be null in the database, but that depends on the db schema.
Ruby is something I'm new to, so please be gentle :)
from oxidized.
I think it makes sense and is a good idea. But maybe we should be more strict about getting real IP address.
Can you test this:
ytti@ytti ~/u/g/o/l/oxidized> git diff
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb
index 6bc2b0f..12ed5cc 100644
--- a/lib/oxidized/node.rb
+++ b/lib/oxidized/node.rb
@@ -1,5 +1,6 @@
module Oxidized
require 'resolv'
+ require 'ipaddr'
require 'ostruct'
require_relative 'node/stats'
class MethodNotFound < OxidizedError; end
@@ -10,7 +11,8 @@ module Oxidized
alias :running? :running
def initialize opt
@name = opt[:name]
- @ip = Resolv.getaddress @name
+ @ip = IPAddr.new(opt[:ip]).to_s rescue nil
+ @ip ||= Resolv.getaddress @name
@group = opt[:group]
@input = resolve_input opt
@output = resolve_output opt
ytti@ytti ~/u/g/o/l/oxidized>
If possible with bogus data in SQL too and monitor syslog.
from oxidized.
That looks to work good to me. Tests I have done:
- Name and IP - Works as expected
- Name and invalid IP specified - Ignores IP and looks up host.
- Name and blank IP (Length 0) - Same as 2
- Name and null IP - Same as both above
A elegant solution compared to mine :)
from oxidized.
Related Issues (20)
- RouterOS 7.15 - error in logs HOT 1
- zynosgs model not working with switch GS1900-8HP HOT 7
- tplink model not working with Tplink SX-3008F switch
- Multiple HTTP sources not working HOT 8
- Rocky Linux PromptUndetect HOT 11
- Problem with changing ios.rb HOT 3
- Single UBNT EdgeSwitch constantly adding/removing last 50-ish lines of config HOT 1
- Slackdiff Hook Fails Due to Depreciation of files.upload API method HOT 1
- Tp-link change backup HOT 1
- Hook to gogs authentication issue HOT 4
- HTTP/Mechanize and custom port
- Problem with saving large configurations HOT 2
- docker-compose GPG encryption of router.db HOT 1
- Installing gem package oxidized-script is failing HOT 1
- Ruby Sass has reached end-of-life and should no longer be used. HOT 1
- Help with ArubaOS8 - Prompt HOT 4
- Huawei Model extend to save config HOT 3
- http input log HOT 1
- Monkey patching changes the order of commands. HOT 1
- Rugged::NetworkError: unsupported URL protocol HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oxidized.