opsviewconfig 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/opsviewconfig.rb +50 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 51b8d3c6b9a1dccc2f1afa1487da05047161b3a1
|
4
|
+
data.tar.gz: baf8ba1bef60a158207e02b89f1f4a1b30f4f69a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27fb4a21cf837bc272673f2891c68ae556bba25b44d51fee31099eaf73a7ba99feac4a3886ffa88fd5afddd13078e114f0dcebbf8d202e3b4093357d6356f567
|
7
|
+
data.tar.gz: af71352f53cff766ce9b5fd31bb7df94eb6c1d23e9b6ec3ef96197740affa711e6061d71034f055cebb2a7f57878cb195171cd67e8954245ca2321894fed0089
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'opsview_rest'
|
3
|
+
|
4
|
+
class Opsviewconfig
|
5
|
+
def initialize(config)
|
6
|
+
# Connect to opsview and return handler
|
7
|
+
@connection = OpsviewRest.new("http://" + config['opsviewhost'] + "/", :username => config['opsviewuser'], :password => config['opsviewpassword'])
|
8
|
+
end
|
9
|
+
|
10
|
+
def connection
|
11
|
+
return @connecton
|
12
|
+
end
|
13
|
+
|
14
|
+
def export(resource,folder)
|
15
|
+
res = @connection.list(:type => resource)
|
16
|
+
# Need to parse out junk we don't need to export
|
17
|
+
res = export_parse(res)
|
18
|
+
res.each do |resource|
|
19
|
+
filename = resource['name']
|
20
|
+
filename.gsub!(/[^0-9A-Za-z.\-]/, '_')
|
21
|
+
#puts "Exporting #{resource['name']} to #{filename}"
|
22
|
+
Dir.mkdir(folder) unless Dir.exist?(folder)
|
23
|
+
File.write("#{folder}/#{filename}.json",JSON.pretty_generate(resource))
|
24
|
+
end
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
|
28
|
+
# Function to clean up the exported object
|
29
|
+
def export_parse(export)
|
30
|
+
cleanexport = Array.new()
|
31
|
+
export.each do |resource|
|
32
|
+
resource.delete("id")
|
33
|
+
cleanexport << resource
|
34
|
+
end
|
35
|
+
return cleanexport
|
36
|
+
end
|
37
|
+
|
38
|
+
def import(type,filename=nil,folder=nil)
|
39
|
+
resourceconfig = JSON.parse(File.read(filename))
|
40
|
+
resourceconfig[:type] = :"#{type}"
|
41
|
+
resourceconfig[:replace] = true
|
42
|
+
res = @connection.create(resourceconfig)
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
|
46
|
+
def reload()
|
47
|
+
@connection.initiate_reload()
|
48
|
+
return true
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opsviewconfig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitriy M
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple class to import and export OpsView config
|
14
|
+
email: dmitriy.mar@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/opsviewconfig.rb
|
20
|
+
homepage: https://github.com/kainam00/opsviewconfig
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.14
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: OpsView configuration import and export class
|
44
|
+
test_files: []
|