-
Notifications
You must be signed in to change notification settings - Fork 1
import scripts
Oliver Gaida edited this page Nov 14, 2019
·
4 revisions
check the first record with
mlr --icsv --ifs ';' --ojson cat import.csv | jq -s '[.[0]]'then you may transform the json with jq:
mlr --icsv --ifs ';' --ojson cat import.csv | jq -s '[.[]|{name: .Hostname,class: {"@id": "400042"},z_variante: {"@COMMON_NAME": "5 - Full managed"},description: .Description}]' > create.json
Now you import the records with a ruby script:
#!/usr/bin/env ruby
require "usd"
usdp = Usd.new("username","password","http://sdmserver:8050")
data={}
arr = JSON.parse(File.open("create.json").read)
arr.each do |e|
data["nr"] = e
json = JSON.pretty_generate(data)
puts json
puts usdp.create({:type => "json", :data => json})
end