opsview_rest 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfa4e246ec52cf6f0b8b699c7f6f67a2da4e666f
4
- data.tar.gz: ee030b2293fae3a6f9ee7bc58546efc35aa9f751
3
+ metadata.gz: c3c018cd70aa9e7dfc6bc0bb869b9534c26924e7
4
+ data.tar.gz: 059f6d2d3a7881ae87bbc8eeb1d8d9e6b9916255
5
5
  SHA512:
6
- metadata.gz: 0db7d102c8a545c6802bad27f6d036d9e046ce5b6da0dcc6cd607836d872f6d746d537b977f413ef92a336173901f9b01a94262846d61f04d9c7ace893eaf2d4
7
- data.tar.gz: 94ff594613010e1027df70663864cea58837e81dfc9285d8f1c9fbfaebbf2549ffe93116f5f9c0c3faf2667952cfb484a0f8ba77c01f3e184b2340bbddd379e5
6
+ metadata.gz: 1469d086dbbec0a9e075dc0511cbf5ab9c11dbec5532ebf1cde7b2f78569f5e11650d52b15147c2102e0f016ff81ea837a2acdba84b8757e9ff94985176c6fc2
7
+ data.tar.gz: 907a169ee73d3149330e12226969313a7127cf1c15c25fedbe65613d43e25efc03d364e91f75fada4a12f921ad9ddfa5ec6b1dc3cc0bc2ecf0b39cd9e2759a98
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ doc
21
+ .yardoc
22
+ Gemfile.lock
23
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+ script: bundle exec rake
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: ruby-head
10
+ - rvm: 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in opsview_rest.gemspec
4
+ gemspec
5
+
6
+
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # opsview_rest
2
+ [![Build Status](https://travis-ci.org/cparedes/opsview_rest?branch=master)](https://travis-ci.org/cparedes/opsview_rest)
3
+
4
+ A Ruby Gem that allows you to interact with an Opsview server.
5
+
6
+ ## License
7
+
8
+ Apache 2.0.
9
+
10
+ ## Resources
11
+
12
+ This gem is heavily based off of Adam Jacob's "dynect_rest" gem.
13
+
14
+ First iteration will focus on creating/updating/deleting resources on an
15
+ Opsview server. The following resources are currently supported (you would
16
+ enter these types in as parameter :type in "create", "purge", and "list"):
17
+
18
+ * attribute
19
+ * contact
20
+ * host
21
+ * hostcheckcommand
22
+ * hostgroup
23
+ * hosttemplate
24
+ * keyword
25
+ * monitoringserver
26
+ * notificationmethod
27
+ * role
28
+ * servicecheck
29
+ * servicegroup
30
+ * timeperiod
31
+
32
+ Check out [http://docs.opsview.com/doku.php?id=opsview-community:restapi:config](http://docs.opsview.com/doku.php?id=opsview-community:restapi:config)
33
+ for a list of possible parameters to pass in to each resource type.
34
+
35
+ Keep in mind that in general, you can pass in just the name of an object that
36
+ is a dependency for the object you're creating, and the library should figure
37
+ out the best way to map those resources in the right way to send to the Opsview
38
+ Server. For example, for a "host" resource, you can pass in an array of
39
+ hosttemplates that you want to apply to a host - you can specify the list of
40
+ hosttemplates like this:
41
+
42
+ ```ruby
43
+ connection.create(:type => host,
44
+ :name => "foobar",
45
+ :hosttemplates => [ "ht1", "ht2" ],
46
+ )
47
+ ```
48
+
49
+ and the library will properly format the payload in JSON like this:
50
+
51
+ ```ruby
52
+ {
53
+ "name": "foobar",
54
+ "hosttemplates": [
55
+ { "name": "ht1" },
56
+ { "name": "ht2" }
57
+ ]
58
+ }
59
+ ```
60
+
61
+ There's a few that might not do this by default, since the API requires a bit
62
+ more information than can be implied by just a list of names. I'm still
63
+ looking for a good way to represent this data, so if anyone has any great
64
+ ideas, I'm all ears.
65
+
66
+ One good example of what I'm talking about is the "notificationprofiles"
67
+ parameter for the "contacts" resource (look at
68
+ http://docs.opsview.com/doku.php?id=opsview-community:restapi:config#contacts
69
+ for an example): there's a lot of information that seems to be better served by
70
+ instantiating a "Notification Profiles" object and embedding it within the
71
+ payload. Again, not too sure how to handle this gracefully other than having
72
+ the user just pass in the array with all of the parameters manually.
73
+
74
+ Anyway, this is how you would use the gem to create a resource:
75
+
76
+ ```ruby
77
+ require 'opsview_rest'
78
+
79
+ connection = OpsviewRest.new("http://127.0.0.1/", :username => "admin", :password => "initial")
80
+
81
+ host = connection.create(
82
+ :name => "foobar",
83
+ :ip => "192.168.1.2",
84
+ :hostgroup => "Monitoring Servers",
85
+ :hosttemplates => [ "OS - Unix Base", "Network - Base" ],
86
+ :type => :host,
87
+ :replace => false
88
+
89
+ )
90
+
91
+ # Let's say we want to peer into what we have so far for hosts:
92
+
93
+ connection = Opsview.new(...)
94
+ hosts = connection.list(:type => "host")
95
+
96
+ # And what if we knew the name of the server and wanted to delete it?
97
+
98
+ connection = Opsview.new(...)
99
+ connection.purge(:type => "host", :name => "foobar")
100
+ ```
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ #encoding: utf-8
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ Bundler.setup
8
+ Bundler::GemHelper.install_tasks
9
+
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ task :default => :spec
14
+
15
+ begin
16
+ require 'yard'
17
+ YARD::Rake::YardocTask.new
18
+ rescue LoadError
19
+ task :yardoc do
20
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
21
+ end
22
+ end
data/TODO.md ADDED
@@ -0,0 +1,20 @@
1
+ TODO List
2
+ =========
3
+
4
+ 1. Figure out a way to instantiate a ton of methods for all of the different
5
+ resource types. There isn't a nice way to deal with, say, hosts, and
6
+ hostgroups at the moment (since they all have different parameters.)
7
+ The only things that are common between the different resource types
8
+ are "name" and "id".
9
+ 1a. If not this, then there should be a better way to deal with the plethora
10
+ of fields that we could possibly update in Opsview for each resource type.
11
+ I've mostly based the code off of Adam Jacob's dynect_rest gem, which
12
+ has a much simpler API and a predictable set of parameters - thus, it
13
+ makes sense to dynamically create a ton of methods and allow stuff like
14
+ "dynect.record.ip.foobar" as an accessor.
15
+
16
+ One thought is to simply choose a functional subset of the parameters we
17
+ could pass into each type of resource, and add more as the need arises.
18
+ Another thought is to simply pass in a hash with a bunch of data in it,
19
+ but I'd rather not do this, as it'd make the user guess how best to format
20
+ the data.
@@ -0,0 +1,32 @@
1
+ require 'opsview_rest/mixin'
2
+
3
+ class OpsviewRest
4
+ class Attribute
5
+
6
+ include OpsviewRest::Mixin
7
+
8
+ attr_accessor :options, :opsview, :resource_type
9
+
10
+ def initialize(opsview, options = {})
11
+ @options = {
12
+ :name => "PROCESSES",
13
+ :arg1 => "",
14
+ :arg2 => "",
15
+ :arg3 => "",
16
+ :arg4 => "",
17
+ :value => "",
18
+ :servicechecks => [],
19
+ :save => true,
20
+ :replace => false
21
+ }.update options
22
+
23
+ @opsview = opsview
24
+ @resource_type = @options[:type]
25
+
26
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
27
+
28
+ save(@options[:replace]) if @options[:save]
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,71 @@
1
+ require 'opsview_rest/mixin'
2
+
3
+ class OpsviewRest
4
+ class Contact
5
+
6
+ include OpsviewRest::Mixin
7
+
8
+ attr_accessor :options, :opsview, :resource_type
9
+
10
+ def initialize(opsview, options = {})
11
+ @options = {
12
+ :name => "foobar",
13
+ :fullname => "",
14
+ :description => "",
15
+ :encrypted_password => "$apr1$HTQogYE7$09TNcZWa/WzoBXdUF6Iyr1",
16
+ :realm => "local",
17
+ :language => "",
18
+ :role => "View all, change none",
19
+ :variables => [
20
+ { :value => "", :name => "EMAIL" },
21
+ { :value => 1, :name => "RSS_COLLAPSED" },
22
+ { :value => 1440, :name => "RSS_MAXIMUM_AGE" },
23
+ { :value => 30, :name => "RSS_MAXIMUM_ITEMS" }
24
+ ],
25
+ :notificationprofiles => [
26
+ { :name => "24x7",
27
+ :host_notification_options => "u,d,r,f",
28
+ :notificationmethods => [
29
+ { :name => "Email" }
30
+ ],
31
+ :servicegroups => [],
32
+ :all_servicegroups => 1,
33
+ :all_hostgroups => 0,
34
+ :keywords => [],
35
+ :service_notification_options => "w,c,r,u,f",
36
+ :hostgroups => [],
37
+ :notification_level => 1,
38
+ :notification_period => { :name => "24x7" } },
39
+ { :name => "8x5",
40
+ :host_notification_options => "u,d,r,f",
41
+ :notificationmethods => [
42
+ { :name => "Email" }
43
+ ],
44
+ :servicegroups => [],
45
+ :all_servicegroups => 1,
46
+ :all_hostgroups => 0,
47
+ :keywords => [],
48
+ :service_notification_options => "w,c,r,u,f",
49
+ :hostgroups => [],
50
+ :notification_level => 1,
51
+ :notification_period => { :name => "workhours" } }
52
+ ],
53
+ :save => true,
54
+ :replace => false
55
+ }.update options
56
+
57
+ @opsview = opsview
58
+ @resource_type = @options[:type]
59
+
60
+ @options[:all_servicegroups] = if @options[:all_servicegroups] then 1 else 0 end
61
+ @options[:all_hostgroups] = if @options[:all_hostgroups] then 1 else 0 end
62
+ @options[:servicegroups] = @options[:servicegroups].map { |x| { "name" => x } }
63
+ @options[:keywords] = @options[:keywords].map { |x| { "name" => x } }
64
+ @options[:hostgroups] = @options[:hostgroups].map { |x| { "name" => x } }
65
+ @options[:role] = { "name" => @options[:role] }
66
+
67
+ save(@options[:replace]) if @options[:save]
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,77 @@
1
+ require 'opsview_rest/mixin'
2
+
3
+ class OpsviewRest
4
+ class Host
5
+
6
+ include OpsviewRest::Mixin
7
+
8
+ attr_accessor :options, :opsview, :resource_type
9
+
10
+ def initialize(opsview, options = {})
11
+ # Default set of attributes to send to Opsview:
12
+ @options = {
13
+ :flap_detection_enabled => false,
14
+ :snmpv3_privprotocol => nil,
15
+ :hosttemplates => [],
16
+ :keywords => [],
17
+ :check_period => "24x7",
18
+ :hostattributes => [],
19
+ :notification_period => "24x7",
20
+ :name => "unknown",
21
+ :rancid_vendor => nil,
22
+ :snmp_community => "public",
23
+ :hostgroup => "Unknown",
24
+ :enable_snmp => false,
25
+ :monitored_by => "Master Monitoring Server",
26
+ :alias => "Managed Host",
27
+ :uncommitted => false,
28
+ :parents => [],
29
+ :icon => { "name" => "LOGO - Opsview" },
30
+ :retry_check_interval => 1,
31
+ :ip => "localhost",
32
+ :use_mrtg => false,
33
+ :servicechecks => [],
34
+ :use_rancid => false,
35
+ :nmis_node_type => "router",
36
+ :snmp_version => "2c",
37
+ :snmp_authpassword => "",
38
+ :use_nmis => false,
39
+ :rancid_connection_type => "ssh",
40
+ :snmpv3_authprotocol => nil,
41
+ :rancid_username => nil,
42
+ :rancid_password => nil,
43
+ :check_command => "ping",
44
+ :check_attempts => 2,
45
+ :check_interval => 0,
46
+ :notification_interval => 60,
47
+ :snmp_port => 161,
48
+ :snmpv3_username => "",
49
+ :snmpv3_privpassword => "",
50
+ :other_addresses => "",
51
+ :save => true,
52
+ :replace => false
53
+ }.update options
54
+
55
+ @opsview = opsview
56
+ @resource_type = @options[:type]
57
+
58
+ # Add any weird exceptions here (like hostgroups having to be mapped
59
+ # to "name" => hostgroup, etc.):
60
+ @options[:flap_detection_enabled] = if @options[:flap_detection_enabled] then 1 else 0 end
61
+ @options[:enable_snmp] = if @options[:enable_snmp] then 1 else 0 end
62
+ @options[:use_mrtg] = if @options[:use_mrtg] then 1 else 0 end
63
+ @options[:use_rancid] = if @options[:use_rancid] then 1 else 0 end
64
+ @options[:use_nmis] = if @options[:use_nmis] then 1 else 0 end
65
+ @options[:uncommitted] = if @options[:uncommitted] then 1 else 0 end
66
+ @options[:check_period] = { "name" => @options[:check_period] }
67
+ @options[:hostgroup] = { "name" => @options[:hostgroup] }
68
+ @options[:notification_period] = { "name" => @options[:notification_period] }
69
+ @options[:monitored_by] = { "name" => @options[:monitored_by] }
70
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
71
+ @options[:check_command] = { "name" => @options[:check_command] }
72
+
73
+ save(@options[:replace]) if @options[:save]
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,32 @@
1
+ require 'opsview_rest/mixin'
2
+
3
+ class OpsviewRest
4
+ class Hostcheckcommand
5
+
6
+ include OpsviewRest::Mixin
7
+
8
+ attr_accessor :opsview, :options, :resource_type
9
+
10
+ def initialize(opsview, options = {})
11
+ @options = {
12
+ :name => "ping",
13
+ :args => "-H $HOSTADDRESS$ -t 3 -w 500.0,80% -c 1000.0,100%",
14
+ :priority => 1,
15
+ :plugin => "check_icmp",
16
+ :uncommitted => false,
17
+ :save => true,
18
+ :replace => false
19
+ }.update options
20
+
21
+ @opsview = opsview
22
+ @resource_type = @options[:type]
23
+
24
+ @options[:plugin] = { "name" => @options[:plugin] }
25
+ @options[:hosts] = @options[:hosts].map { |x| { "name" => x } }
26
+ @options[:uncommitted] = if @options[:uncommitted] then 1 else 0 end
27
+
28
+ save(@options[:replace]) if @options[:save]
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'opsview_rest/mixin'
2
+
3
+ class OpsviewRest
4
+ class Hostgroup
5
+
6
+ include OpsviewRest::Mixin
7
+
8
+ attr_accessor :opsview, :options, :resource_type
9
+
10
+ def initialize(opsview, options = {})
11
+ @options = {
12
+ :parent => "Opsview",
13
+ :name => "unknown",
14
+ :save => true,
15
+ :replace => false
16
+ }.update options
17
+
18
+ @opsview = opsview
19
+ @resource_type = @options[:type]
20
+
21
+ @options[:parent] = { "name" => @options[:parent] }
22
+ @options[:hosts] = @options[:hosts].map { |x| { "name" => x } }
23
+ @options[:children] = @options[:children].map { |x| { "name" => x } }
24
+
25
+ save(@options[:replace]) if @options[:save]
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require 'opsview_rest/mixin'
2
+
3
+ class OpsviewRest
4
+ class Hosttemplate
5
+
6
+ include OpsviewRest::Mixin
7
+
8
+ attr_accessor :options, :opsview, :resource_type
9
+
10
+ def initialize(opsview, options = {})
11
+ @options = {
12
+ :name => "Unknown",
13
+ :description => "Unknown",
14
+ :servicechecks => [],
15
+ :managementurls => [],
16
+ :save => true,
17
+ :replace => false
18
+ }.update options
19
+
20
+ @opsview = opsview
21
+ @resource_type = @options[:type]
22
+
23
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
24
+
25
+ save(@options[:replace]) if @options[:save]
26
+ end
27
+
28
+ end
29
+ end