Class: Netmidget
- Inherits:
-
Object
- Object
- Netmidget
- Defined in:
- lib/netmidget.rb
Instance Attribute Summary collapse
-
#device_name ⇒ Object
Returns the value of attribute device_name.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#log ⇒ Object
Returns the value of attribute log.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #device_str ⇒ Object
-
#initialize(opts) ⇒ Netmidget
constructor
A new instance of Netmidget.
- #ping ⇒ Object
- #ping? ⇒ Boolean
- #ping_output_str_fail ⇒ Object
- #ping_output_str_prefix ⇒ Object
- #ping_output_str_success ⇒ Object
- #stdout_prefix ⇒ Object
- #traceroute ⇒ Object
- #traceroute_output_str ⇒ Object
Constructor Details
#initialize(opts) ⇒ Netmidget
Returns a new instance of Netmidget.
10 11 12 13 14 15 16 |
# File 'lib/netmidget.rb', line 10 def initialize(opts) @hostname = opts[:hostname] || `/bin/hostname`.chomp @site = opts[:site] @ip = opts[:ip] @device_name = opts[:device_name] @log = opts[:log] || nil end |
Instance Attribute Details
#device_name ⇒ Object
Returns the value of attribute device_name.
4 5 6 |
# File 'lib/netmidget.rb', line 4 def device_name @device_name end |
#hostname ⇒ Object
Returns the value of attribute hostname.
4 5 6 |
# File 'lib/netmidget.rb', line 4 def hostname @hostname end |
#ip ⇒ Object
Returns the value of attribute ip.
4 5 6 |
# File 'lib/netmidget.rb', line 4 def ip @ip end |
#log ⇒ Object
Returns the value of attribute log.
4 5 6 |
# File 'lib/netmidget.rb', line 4 def log @log end |
#site ⇒ Object
Returns the value of attribute site.
4 5 6 |
# File 'lib/netmidget.rb', line 4 def site @site end |
Instance Method Details
#device_str ⇒ Object
18 19 20 |
# File 'lib/netmidget.rb', line 18 def device_str "#{site}::#{device_name}::#{ip}" end |
#ping ⇒ Object
22 23 24 |
# File 'lib/netmidget.rb', line 22 def ping Net::Ping::External.new(ip).ping? end |
#ping? ⇒ Boolean
26 27 28 29 30 31 32 33 |
# File 'lib/netmidget.rb', line 26 def ping? if not resp = ping warn_str = "#{device_str} was unresponsive...trying again" log ? log.warn(warn_str) : puts(Time.now.to_s + ": " + warn_str) resp = ping end resp end |
#ping_output_str_fail ⇒ Object
59 60 61 62 63 |
# File 'lib/netmidget.rb', line 59 def ping_output_str_fail str = ping_output_str_prefix + "Fail" log ? log.error(str) : puts(str = (stdout_prefix + str)) str end |
#ping_output_str_prefix ⇒ Object
49 50 51 |
# File 'lib/netmidget.rb', line 49 def ping_output_str_prefix "Pinging #{device_str}: " end |
#ping_output_str_success ⇒ Object
53 54 55 56 57 |
# File 'lib/netmidget.rb', line 53 def ping_output_str_success str = ping_output_str_prefix + "Success" log ? log.info(str) : puts(str = (stdout_prefix + str)) str end |
#stdout_prefix ⇒ Object
45 46 47 |
# File 'lib/netmidget.rb', line 45 def stdout_prefix "#{Time.now.to_s}: #{hostname} " end |
#traceroute ⇒ Object
35 36 37 |
# File 'lib/netmidget.rb', line 35 def traceroute `/usr/sbin/traceroute -n -m 20 -w 2 #{ip} 2>&1` end |
#traceroute_output_str ⇒ Object
39 40 41 42 43 |
# File 'lib/netmidget.rb', line 39 def traceroute_output_str str = traceroute log ? log.error(str) : puts(str = (stdout_prefix + str)) str end |