所以我在Ruby中为Bluecat(IPAM)创建一个API脚本。我没有登录的问题,但是当我尝试运行添加IPv4命令时,我收到此错误:
in `raise_soap_and_http_errors!': (env:Server) Not logged in (Savon::SOAPFault)
我的脚本(带有一些额外的代码)如下:
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
为什么我收到此错误的任何想法?感谢
答案 0 :(得分:0)
我遇到了同样的问题。显然,您需要在每次请求时发送cookie。
更改
response = client.call(:add_ip4_network, message: message)
到
response = client.call(:add_ip4_network, message: message, cookies: auth_cookies)