0

So I'm creating an API script in ruby for Bluecat(IPAM). I'm having no problem logging on, but when I try to run an add IPv4 command I get this error:

in `raise_soap_and_http_errors!': (env:Server) Not logged in (Savon::SOAPFault)

my script (with some extra code taken out) is below:

require 'savon'
require 'csv'

module Bluecat
class Api

WsdlUrl = 'http:/bluecat/Services/API?wsdl'
User = 'username'
Pass = 'password'

attr_accessor :auth_cookies
attr_accessor :client
def initialize
  @client = Savon.client(wsdl: WsdlUrl)
  unless client.nil?
    login
    puts client.operations
    addIP4Network
  else
    print "No client\n"
  end
  print "Got cookies %s\n" % auth_cookies
  logout
end

def login
  response = client.call(:login) do
    message username: User, password: Pass
  end
  @auth_cookies = response.http.cookies
end

def logout
  puts "logging out"
  client.call(:logout)
end

def addIP4Network
  CSV.foreach('CSV', :headers => true , :encoding => 'ISO-8859-1') do |row,i|

    message = {'blockId' => 'example' , 'CIDR' => row[0] , 'properties' => "configuration = COV "}
    response = client.call(:add_ip4_network, message: message)

  end
end
end
end

Any ideas as to why I am getting this error? Thanks

1 Answer 1

0

I had the same problem. Apparently, you need to send the cookies with every request.

Change

response = client.call(:add_ip4_network, message: message)

to

response = client.call(:add_ip4_network, message: message, cookies: auth_cookies)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.