Jump to content

Datenbank-Eintrag per Powershell


Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

Empfohlene Beiträge

Hallo zusammen,

 

wir verwenden für unsere Serververwaltung das Tool Racktables.

 

Da wir virtuelle Server (VMwware) per Powerhell und PowerCLI ausrollen, bin ich jetzt dabei automatisiert einen Eintrag in der Datenbank erzeugen zu lassen.

 

Leider kenne ich mich damit noch gar nicht aus und bin auf jede Hilfe angewiesen

 

BIsher habe ich mir im Netz folgendendes zusammengesucht

cls

$apiUser="be28f0a29e7df3b9a455871abdb25d2a"

$apiPass="a8b15299dbbc374a05c7b8068001b634"

$res="http://serverdoku.XXX.local:9292/object"



$apiHash = ConvertTo-SecureString $apiPass -AsPlainText -Force

$apiCred = New-Object Management.Automation.PSCredential ($apiUser, $apiHash)



$data = "{ 'name':VNTS999, 'Funktion':'Test'}"



Invoke-WebRequest -Uri $res -Credential $apiCred -Method Post -Body $data -ContentType "application/json"

Fehlermeldung

Invoke-WebRequest : MultiJson::LoadError at /object

795: unexpected token at '{ 'name':VNTS999, 'Funktion':'Test'}'

Ruby/usr/ruby/2.1/lib/ruby/2.1.0/json/common.rb: in parse, line 155

WebPOST serverdoku.XXXX.local/object

Jump to:

GET POST Cookies ENV Traceback (innermost first)

/usr/ruby/2.1/lib/ruby/2.1.0/json/common.rb: in parse

# the default.

# * *create_additions*: If set to false, the Parser doesn't create

# additions even if a matching class and create_id was found. This option

# defaults to true.

# * *object_class*: Defaults to Hash

# * *array_class*: Defaults to Array

def parse(source, opts = {})

Parser.new(source, opts).parse...end

# Parse the JSON document _source_ into a Ruby data structure and return it.

# The bang version of the parse method defaults to the more dangerous values

# for the _opts_ hash, so be sure only to parse trusted _source_ documents.

#

# _opts_ can have the following keys:

/usr/ruby/2.1/lib/ruby/2.1.0/json/common.rb: in parse

# the default.

# * *create_additions*: If set to false, the Parser doesn't create

# additions even if a matching class and create_id was found. This option

# defaults to true.

# * *object_class*: Defaults to Hash

# * *array_class*: Defaults to Array

def parse(source, opts = {})

Parser.new(source, opts).parse...end

# Parse the JSON document _source_ into a Ruby data structure and return it.

# The bang version of the parse method defaults to the more dangerous values

# for the _opts_ hash, so be sure only to parse trusted _source_ documents.

#

# _opts_ can have the following keys:

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/multi_json-1.8.4/lib/multi_json/adapters/json_common.rb: in load

string = string.read if string.respond_to?(:read)

if string.respond_to?(:force_encoding)

string = string.dup.force_encoding(::Encoding::ASCII_8BIT)

end

options[:symbolize_names] = true if options.delete(:symbolize_keys)

::JSON.parse(string, options)...end

def dump(object, options={})

options.merge!(::JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)

object.to_json(options)

end

end

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/multi_json-1.8.4/lib/multi_json/adapter.rb: in load

metaclass.instance_eval do

define_method("default_#{action}_options"){ value }

end

end

def load(string, options={})

raise self::ParseError if blank?(string)

instance.load(string, collect_load_options(options).clone)...end

def dump(object, options={})

instance.dump(object, collect_dump_options(options).clone)

end

protected

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/multi_json-1.8.4/lib/multi_json.rb: in load

# <b>Options</b>

#

# <tt>:symbolize_keys</tt> :: If true, will use symbols instead of strings for the keys.

# <tt>:adapter</tt> :: If set, the selected adapter will be used for this call.

def load(string, options={})

adapter = current_adapter(options)

begin

adapter.load(string, options)...rescue adapter::ParseError => exception

raise LoadError.new(exception.message, exception.backtrace, string)

end

end

alias decode load

def current_adapter(options={})

/opt/racktables/racktables_api/lib/logistician/repository/multi_resource.rb: in post

ups = 0

updates = repository.multi_update(ctx, input, objects )

ups = updates.do!

return success( ctx, 'updated' => ups )

end

def post( ctx, env )

input = MultiJson.load(env['rack.input'])...nu = nil

create = repository.create(ctx, input )

nu = create.do!

return created( ctx, nu )

end

end

/opt/racktables/racktables_api/lib/logistician/resource.rb: in call

def patch(ctx, env)

raise Unsupported

end

def call(env)

method = ACTION[env["REQUEST_METHOD"]]

ctx = Utils.context(env)

self.__send__(method, ctx, env)...end

end

end

/opt/racktables/racktables_api/lib/logistician/repository/shared.rb: in block in call

end

def call(env)

Logistician::Utils.context(env).use(:statsd) do |statsd|

statsd_prefix = ['resources',name,'actions',env['addressive'].action,env['REQUEST_METHOD']].join('.')

time = Time.now

begin

result = super...if result[0] == 200

statsd.timing("#{statsd_prefix}.inner_time", (Time.now - time)*1000 )

end

return result

ensure

statsd.increment("#{statsd_prefix}.count")

end

/opt/racktables/racktables_api/lib/logistician/context.rb: in use

@data = {}

@builder = {}

end

def use(*modules)

if useable? *modules

if block_given?

return yield( *modules.map{|r| @data[r] } )...else

return *modules.map{|r| @data[r] }

end

else

return nil

end

end

/opt/racktables/racktables_api/lib/logistician/repository/shared.rb: in call

end

def to_s

return ['<',self.class.name,' for ',repository,'>'].join

end

def call(env)

Logistician::Utils.context(env).use(:statsd) do |statsd|...statsd_prefix = ['resources',name,'actions',env['addressive'].action,env['REQUEST_METHOD']].join('.')

time = Time.now

begin

result = super

if result[0] == 200

statsd.timing("#{statsd_prefix}.inner_time", (Time.now - time)*1000 )

end

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/addressive-0.1.0/lib/addressive/router.rb: in block in call

"[ ? ] url: #{rr.url.inspect}, path: #{rr.fullpath.inspect}"

end

matches = routes_for(rr.fullpath, rr.url)

result = nil

matches.each do |addressive|

env[ADDRESSIVE_ENV_KEY] = addressive

begin

result = (addressive.spec.callback || addressive.spec.app).call(env)...db.call(DEBUG_NAME) do

"[#{result[0]}] #{addressive.spec.template.pattern} with #{addressive.variables.inspect} on #{addressive.spec.app} ( route #{addressive.data[:'routes.scanned']} /

#{addressive.data[:'routes.total']} ) after #{'%.6f' % addressive.data[:duration]}"

end

rescue

db.call(DEBUG_NAME) do

"[!!!] #{addressive.spec.template.pattern} with #{addressive.variables.inspect} on #{addressive.spec.app} ( route #{addressive.data[:'routes.scanned']} /

#{addressive.data[:'routes.total']} ) after #{'%.6f' % addressive.data[:duration]}"

end

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/addressive-0.1.0/lib/addressive/router.rb: in block in each

# @yield {Addressive::Match}

def each

total = @routes.size

scan_time = Time.now

@routes.each(@proto,@host,@path) do |spec, vars, scanned|

node, action = @actions[spec];

t = Time.now

yield Match.new(node, action, vars, spec, {:'routes.scanned'=>scanned,:'routes.total'=>total,:duration => (t - scan_time)})...# still here?, the passed time should

be added

scan_time += (Time.now - t)

end

end

end

(eval): in each

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/addressive-0.1.0/lib/addressive/router.rb: in each

@routes,@proto,@host,@path,@actions = routes, proto, host,path, actions

end

# @yield {Addressive::Match}

def each

total = @routes.size

scan_time = Time.now

@routes.each(@proto,@host,@path) do |spec, vars, scanned|...node, action = @actions[spec];

t = Time.now

yield Match.new(node, action, vars, spec, {:'routes.scanned'=>scanned,:'routes.total'=>total,:duration => (t - scan_time)})

# still here?, the passed time should be added

scan_time += (Time.now - t)

end

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/addressive-0.1.0/lib/addressive/router.rb: in call

l = env['rack.logger']

db = l ? l.method(:debug) : DEBUG_NULL

db.call(DEBUG_NAME) do

"[ ? ] url: #{rr.url.inspect}, path: #{rr.fullpath.inspect}"

end

matches = routes_for(rr.fullpath, rr.url)

result = nil

matches.each do |addressive|...env[ADDRESSIVE_ENV_KEY] = addressive

begin

result = (addressive.spec.callback || addressive.spec.app).call(env)

db.call(DEBUG_NAME) do

"[#{result[0]}] #{addressive.spec.template.pattern} with #{addressive.variables.inspect} on #{addressive.spec.app} ( route #{addressive.data[:'routes.scanned']} /

#{addressive.data[:'routes.total']} ) after #{'%.6f' % addressive.data[:duration]}"

end

rescue

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/urlmap.rb: in block in call

rest = m[1]

next unless !rest || rest.empty? || rest[0] == ?/

env['SCRIPT_NAME'] = (script_name + location)

env['PATH_INFO'] = rest

return app.call(env)...end

[404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]]

ensure

env['PATH_INFO'] = path

env['SCRIPT_NAME'] = script_name

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/urlmap.rb: in each

def call(env)

path = env["PATH_INFO"]

script_name = env['SCRIPT_NAME']

hHost = env['HTTP_HOST']

sName = env['SERVER_NAME']

sPort = env['SERVER_PORT']

@mapping.each do |host, location, match, app|...unless hHost == host \

|| sName == host \

|| (!host && (hHost == sName || hHost == sName+':'+sPort))

next

end

next unless m = match.match(path.to_s)

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/urlmap.rb: in call

def call(env)

path = env["PATH_INFO"]

script_name = env['SCRIPT_NAME']

hHost = env['HTTP_HOST']

sName = env['SERVER_NAME']

sPort = env['SERVER_PORT']

@mapping.each do |host, location, match, app|...unless hHost == host \

|| sName == host \

|| (!host && (hHost == sName || hHost == sName+':'+sPort))

next

end

next unless m = match.match(path.to_s)

/opt/racktables/racktables_api/lib/caller.rb: in call

end

def initialize(app)

@app = app

end

def call(env)

return @app.call(env)...end

end

/opt/racktables/racktables_api/lib/racktables_api.rb: in block (2 levels) in builder

use Logistician::Context::Build, :addressive do |ctx, mod, env|

ctx[:addressive] = env['addressive'] if env.key?('addressive')

end

use ClientCounter

use Caller do |env|

env['QUERY_STRING'].gsub!('+','%20')

super(env)...end

node_old = Addressive.node(:api) do

edge :object do

app API[Model::RackObject], rewrite: ->(spec){

/opt/racktables/racktables_api/lib/client_counter.rb: in call

@app = app

end

def call(env)

Logistician::Utils.context(env).use(:statsd) do |statsd|

statsd.increment('user_agent.'+parse_user_agent(env['HTTP_USER_AGENT']))

end

@app.call(env)...end

private

def parse_user_agent(ua)

case(ua)

when /\Axar\/v(\d+(?:\.\d+)*)\z/ then 'xar.'+$1

/opt/racktables/racktables_api/lib/logistician/context.rb: in call

end

def call(env)

ctx = Logistician::Utils.context(env)

ctx.build(@name) do |*args|

@block.call(*args, env, *@rest)

end

return @app.call(env)...end

end

extend Forwardable

def_delegators :@data, :[]=, :fetch, :each, :to_h, :to_hash, *Enumerable.instance_methods

/opt/racktables/racktables_api/lib/logistician/context.rb: in call

@rest = rest

@block = block

end

def call(env)

ctx = Logistician::Utils.context(env)

ctx[@name] ||= @block.call(env, *@rest)

return @app.call(env)...end

end

class Build

def initialize(app, name, *rest, &block)

/opt/racktables/racktables_api/lib/api_key_authenticator.rb: in call

auth = Rack::Auth::Basic::Request.new(env)

return unauthorized unless auth.provided?

return bad_request unless auth.basic?

if( auth.credentials[0] =~ /\A\h{32}\z/ and auth.credentials[1] =~ /\A\h{32}\z/ )

if valid_api?( *auth.credentials )

key = Model::ApiKey[auth.credentials[0]]

authenticate_env!(env, key)

return @app.call(env)...end

end

unauthorized

end

end

end

/opt/racktables/racktables_api/lib/caller.rb: in call

end

def initialize(app)

@app = app

end

def call(env)

return @app.call(env)...end

end

/opt/racktables/racktables_api/lib/racktables_api.rb: in block (2 levels) in builder

Rack::Builder.new do

use Rack::Lint

use Caller do |env|

time = Time.now

result = super(env)...

if result[0] == 200 && env['addressive']

Logistician::Utils.context(env).use(:statsd) do |statsd|

statsd.timing( ['resources',env['addressive'].spec.app.name,'actions',env['addressive'].action, env['REQUEST_METHOD'] ,'total_time'].join('.'), (Time.now -

time)*1000 )

end

end

/usr/ruby/2.1/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/lint.rb: in _call

assert("No env given") { env }

check

In Zeile:11 Zeichen:1

+ Invoke-WebRequest -Uri $res -Credential $apiCred -Method Post -Body $data -Conte ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Ersteinmal soll der Eintrag automatisch erstellt werden. Zum Test mit festeingetragenen Werten.

 

Wenn das funktioniert, will ich das gaze mit Variablen, die bei der Erstellung eines Server verwendet werden, versuchen.

 

 

Ich hoffe ihr könnt mir weiter helfen.

 

 

Vielen Danke schon einmal

bearbeitet von Kuddel071089
Link zu diesem Kommentar
Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

Schreibe einen Kommentar

Du kannst jetzt antworten und Dich später registrieren. Falls Du bereits ein Mitglied bist, logge Dich jetzt ein.

Gast
Auf dieses Thema antworten...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Editor-Fenster leeren

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...