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)
- Fortigate Backups Timing Out HOT 6
- Oxidized not using specified IP and model credentials for SSH HOT 1
- Amount of data logged
- Rugged::SshError: Failed to authenticate SSH session: Unable to send userauth-publickey request HOT 2
- Specify format for configuration backup for VyOS/Vyatta/EdgeOS HOT 1
- unable to connect to FS devices using TMOS with 'raised RuntimeError with msg "could not execute command: "tmsh -q show sys version" '
- Not pulling Cisco ASA contexts HOT 5
- Oxidized not running on Rocky Linux 9.3 HOT 1
- Oxidized with Aruba model wont work successfully
- Version on web 0.28 after update 0.29.1
- Swos not working HOT 1
- Oxidize integration with LibreNMS over HTTPS HOT 1
- raised Net::SSH::Exception (rescued RuntimeError) with msg "could not settle on host_key algorithm with ssh-ed25519
- Oxidized::ModelNotFound - symbol OS from my ExtremeNetworks WLC needs to be added - Feature Request
- Oxidized prompt problem
- MLNXOS Pager issue in newer releases of OS
- Add extra command to execute while doing the backup
- Cannot use hook githubrepo with output git-crypt HOT 1
- (FortiOS) CRLF line endings break ruby multi-line regex HOT 1
- RouterOS v7 logging repeated changes due to changing timestamp HOT 1
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.