Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How use LIBRARY with multiples switchs ? #48

Open
getienne53 opened this issue Feb 8, 2024 · 1 comment
Open

How use LIBRARY with multiples switchs ? #48

getienne53 opened this issue Feb 8, 2024 · 1 comment

Comments

@getienne53
Copy link

getienne53 commented Feb 8, 2024

hi,

I'm trying to use the LIBRARY to issue commands on a series of switches, but I don't know Ruby.

I tried several writes like the following one. The script found 27 switches but the command is only executed on the first switch !

#!/usr/bin/env ruby

require 'oxidized/script'

Oxidized::Config.load
Oxidized.setup_logger

Oxidized::Script.new(:ostype=>'cisco', :verbose=>true) do |oxs|
puts oxs.cmd 'show running-config view full | inc hostname'
end


oxidized@ct-oxid:~$ ./ruby1.cmd
I, [2024-02-08T18:30:25.407738 #3685] INFO -- : lib/oxidized/nodes.rb: Loading nodes
I, [2024-02-08T18:30:25.506940 #3685] INFO -- : lib/oxidized/nodes.rb: Loaded 27 nodes
HOST -
OXS - show running-config view full | inc hostname
hostname BRIO-DCC761


I dont understand which option i can use. In the script.rb, the constructor is defined like that :

# @param [Hash] opts options for Oxidized::Script
# @option opts [String]  :host      @hostname or ip address for Oxidized::Node
# @option opts [String]  :model     node model (ios, junos etc) if defined, nodes are not loaded from source
# @option opts [String]  :ostype    OS Type (ios, junos, etc)
# @option opts [Fixnum]  :timeout   oxidized timeout
# @option opts [String]  :username  username for login
# @option opts [String]  :passsword password for login
# @option opts [String]  :enable    enable password to use
# @option opts [String]  :community community to use for discovery
# @option opts [String]  :protocols protocols to use to connect, default "ssh ,telnet"
# @option opts [boolean] :verbose   extra output, e.g. show command given in output
# @yieldreturn [self] if called in block, returns self and disconnnects session after exiting block
# @return [void]
def initialize opts, &block
  @host       = opts.delete :host
  model       = opts.delete :model
  ostype      = opts.delete :ostype
  timeout     = opts.delete :timeout
  username    = opts.delete :username
  password    = opts.delete :password
  enable      = opts.delete :enable
  community   = opts.delete :community
  group       = opts.delete :group
  @verbose    = opts.delete :verbose

Any help would be welcome :-)

GE

@getienne53
Copy link
Author

hi,

Here a workaround script for dummie in ruby like me. It's slow but it works.

#!/usr/bin/env ruby

require 'oxidized/script'

Oxidized::Config.load
Oxidized.setup_logger

source = ".config/oxidized/router.db"

file = File.open(source)
file_data = file.readlines.map(&:chomp)

for line in file_data
switch = line.split(":")
name = switch[0]
ip = switch[1]
print "Name = #{name}, IP = #{ip}\n"

 Oxidized::Script.new(:host=>ip, :verbose=>false) do |oxs|
    puts oxs.cmd 'show clock'
 end

 print"\n\n"

end

file.close

bye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant