opsview_rest 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,30 +2,28 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Hostcheckcommand
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :opsview, :options, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @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
11
+ name: 'ping',
12
+ args: '-H $HOSTADDRESS$ -t 3 -w 500.0,80% -c 1000.0,100%',
13
+ priority: 1,
14
+ plugin: 'check_icmp',
15
+ uncommitted: false,
16
+ save: true,
17
+ replace: false
19
18
  }.update options
20
19
 
21
20
  @opsview = opsview
22
21
  @resource_type = @options[:type]
23
22
 
24
- @options[:plugin] = { "name" => @options[:plugin] }
25
- @options[:uncommitted] = if @options[:uncommitted] then 1 else 0 end
23
+ @options[:plugin] = { 'name' => @options[:plugin] }
24
+ @options[:uncommitted] = (@options[:uncommitted] ? 1 : 0)
26
25
 
27
26
  save(@options[:replace]) if @options[:save]
28
27
  end
29
-
30
28
  end
31
29
  end
@@ -2,28 +2,26 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Hostgroup
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :opsview, :options, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :parent => "Opsview",
13
- :name => "unknown",
14
- :save => true,
15
- :replace => false
11
+ parent: 'Opsview',
12
+ name: 'unknown',
13
+ save: true,
14
+ replace: false
16
15
  }.update options
17
16
 
18
17
  @opsview = opsview
19
18
  @resource_type = @options[:type]
20
19
 
21
- @options[:parent] = { "name" => @options[:parent] }
22
- @options[:hosts] = @options[:hosts].map { |x| { "name" => x } }
23
- @options[:children] = @options[:children].map { |x| { "name" => x } }
20
+ @options[:parent] = { 'name' => @options[:parent] }
21
+ @options[:hosts] = @options[:hosts].map { |x| { 'name' => x } }
22
+ @options[:children] = @options[:children].map { |x| { 'name' => x } }
24
23
 
25
24
  save(@options[:replace]) if @options[:save]
26
25
  end
27
-
28
26
  end
29
27
  end
@@ -2,28 +2,26 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Hosttemplate
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "Unknown",
13
- :description => "Unknown",
14
- :servicechecks => [],
15
- :managementurls => [],
16
- :save => true,
17
- :replace => false
11
+ name: 'Unknown',
12
+ description: 'Unknown',
13
+ servicechecks: [],
14
+ managementurls: [],
15
+ save: true,
16
+ replace: false
18
17
  }.update options
19
18
 
20
19
  @opsview = opsview
21
20
  @resource_type = @options[:type]
22
21
 
23
- @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
22
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { 'name' => x } }
24
23
 
25
24
  save(@options[:replace]) if @options[:save]
26
25
  end
27
-
28
26
  end
29
27
  end
@@ -2,38 +2,36 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Keyword
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "Unknown",
13
- :all_hosts => false,
14
- :hosts => [],
15
- :roles => [ "View some, change none" ],
16
- :all_servicechecks => false,
17
- :servicechecks => [],
18
- :description => "",
19
- :style => "group_by_host",
20
- :enabled => true,
21
- :save => true,
22
- :replace => false
11
+ name: 'Unknown',
12
+ all_hosts: false,
13
+ hosts: [],
14
+ roles: ['View some, change none'],
15
+ all_servicechecks: false,
16
+ servicechecks: [],
17
+ description: '',
18
+ style: 'group_by_host',
19
+ enabled: true,
20
+ save: true,
21
+ replace: false
23
22
  }.update options
24
23
 
25
24
  @opsview = opsview
26
25
  @resource_type = @options[:type]
27
26
 
28
- @options[:all_hosts] = if @options[:all_hosts] then 1 else 0 end
29
- @options[:all_servicechecks] = if @options[:all_servicechecks] then 1 else 0 end
30
- @options[:enabled] = if @options[:enabled] then 1 else 0 end
31
- @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
32
- @options[:hosts] = @options[:hosts].map { |x| { "name" => x } }
33
- @options[:roles] = @options[:roles].map { |x| { "name" => x } }
27
+ @options[:all_hosts] = (@options[:all_hosts] ? 1 : 0)
28
+ @options[:all_servicechecks] = (@options[:all_servicechecks] ? 1 : 0)
29
+ @options[:enabled] = (@options[:enabled] ? 1 : 0)
30
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { 'name' => x } }
31
+ @options[:hosts] = @options[:hosts].map { |x| { 'name' => x } }
32
+ @options[:roles] = @options[:roles].map { |x| { 'name' => x } }
34
33
 
35
34
  save(@options[:replace]) if @options[:save]
36
35
  end
37
-
38
36
  end
39
37
  end
@@ -1,25 +1,23 @@
1
1
  class OpsviewRest
2
2
  module Mixin
3
-
4
- def resource_path(full=false)
5
- if (full == true || full == :full)
6
- "/rest/config/#{self.resource_type}"
3
+ def resource_path(full = false)
4
+ if full == true || full == :full
5
+ "/rest/config/#{resource_type}"
7
6
  else
8
- "config/#{self.resource_type}"
7
+ "config/#{resource_type}"
9
8
  end
10
9
  end
11
10
 
12
- def save(replace=false)
11
+ def save(replace = false)
13
12
  if replace == true || replace == :replace
14
- self.opsview.put(self.resource_path, self)
13
+ opsview.put(resource_path, self)
15
14
  else
16
- self.opsview.post(self.resource_path, self)
15
+ opsview.post(resource_path, self)
17
16
  end
18
17
  end
19
18
 
20
19
  def to_json
21
- self.options.to_json
20
+ options.to_json
22
21
  end
23
-
24
22
  end
25
23
  end
@@ -2,32 +2,30 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class MonitoringServer
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "Slave",
13
- :roles => [],
14
- :activated => true,
15
- :monitors => [],
16
- :nodes => [],
17
- :save => true,
18
- :replace => false
11
+ name: 'Slave',
12
+ roles: [],
13
+ activated: true,
14
+ monitors: [],
15
+ nodes: [],
16
+ save: true,
17
+ replace: false
19
18
  }.update options
20
19
 
21
20
  @opsview = opsview
22
21
  @resource_type = @options[:type]
23
22
 
24
- @option[:roles] = @option[:roles].map { |x| { "name" => x } }
25
- @option[:monitors] = @option[:monitors].map { |x| { "name" => x } }
26
- @option[:nodes] = @option[:nodes].map { |x| { "host" => { "name" => x } } }
27
- @options[:activated] = if @options[:activated] then 1 else 0 end
23
+ @option[:roles] = @option[:roles].map { |x| { 'name' => x } }
24
+ @option[:monitors] = @option[:monitors].map { |x| { 'name' => x } }
25
+ @option[:nodes] = @option[:nodes].map { |x| { 'host' => { 'name' => x } } }
26
+ @options[:activated] = (@options[:activated] ? 1 : 0)
28
27
 
29
28
  save(@options[:replace]) if @options[:save]
30
29
  end
31
-
32
30
  end
33
31
  end
@@ -2,30 +2,28 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class NotificationMethod
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "Unknown",
13
- :master => false,
14
- :active => true,
15
- :command => "notify_by_email",
16
- :contact_variables => "EMAIL",
17
- :save => true,
18
- :replace => false
11
+ name: 'Unknown',
12
+ master: false,
13
+ active: true,
14
+ command: 'notify_by_email',
15
+ contact_variables: 'EMAIL',
16
+ save: true,
17
+ replace: false
19
18
  }.update options
20
19
 
21
20
  @opsview = opsview
22
21
  @resource_type = @options[:type]
23
22
 
24
- @options[:master] = if @options[:master] then 1 else 0 end
25
- @options[:active] = if @options[:active] then 1 else 0 end
23
+ @options[:master] = (@options[:master] ? 1 : 0)
24
+ @options[:active] = (@options[:active] ? 1 : 0)
26
25
 
27
26
  save(@options[:replace]) if @options[:save]
28
27
  end
29
-
30
28
  end
31
29
  end
@@ -2,40 +2,38 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Role
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "Unknown",
13
- :description => "",
14
- :all_hostgroups => true,
15
- :all_servicegroups => true,
16
- :all_keywords => false,
17
- :access_hostgroups => [],
18
- :access_servicegroups => [],
19
- :access_keywords => [],
20
- :hostgroups => [],
21
- :monitoringservers => [],
22
- :accesses => [ "NOTIFYSOME", "PASSWORDSAVE", "VIEWALL" ],
23
- :save => true,
24
- :replace => false
11
+ name: 'Unknown',
12
+ description: '',
13
+ all_hostgroups: true,
14
+ all_servicegroups: true,
15
+ all_keywords: false,
16
+ access_hostgroups: [],
17
+ access_servicegroups: [],
18
+ access_keywords: [],
19
+ hostgroups: [],
20
+ monitoringservers: [],
21
+ accesses: %w(NOTIFYSOME PASSWORDSAVE VIEWALL),
22
+ save: true,
23
+ replace: false
25
24
  }.update options
26
25
 
27
26
  @opsview = opsview
28
27
  @resource_type = @options[:type]
29
28
 
30
- @options[:hostgroups] = @options[:hostgroups].map { |x| { "name" => x } }
31
- @options[:monitoringservers] = @options[:monitoringservers].map { |x| { "name" => x } }
32
- @options[:accesses] = @options[:accesses].map { |x| { "name" => x } }
33
- @options[:all_hostgroups] = if @options[:all_hostgroups] then 1 else 0 end
34
- @options[:all_servicegroups] = if @options[:all_servicegroups] then 1 else 0 end
35
- @options[:all_keywords] = if @options[:all_keywords] then 1 else 0 end
29
+ @options[:hostgroups] = @options[:hostgroups].map { |x| { 'name' => x } }
30
+ @options[:monitoringservers] = @options[:monitoringservers].map { |x| { 'name' => x } }
31
+ @options[:accesses] = @options[:accesses].map { |x| { 'name' => x } }
32
+ @options[:all_hostgroups] = (@options[:all_hostgroups] ? 1 : 0)
33
+ @options[:all_servicegroups] = (@options[:all_servicegroups] ? 1 : 0)
34
+ @options[:all_keywords] = (@options[:all_keywords] ? 1 : 0)
36
35
 
37
36
  save(@options[:replace]) if @options[:save]
38
37
  end
39
-
40
38
  end
41
39
  end
@@ -2,52 +2,50 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Servicecheck
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "Unknown",
13
- :description => "Unknown",
14
- :keywords => [],
15
- :attribute => nil,
16
- :servicegroup => "Unknown",
17
- :dependencies => [ "Opsview Agent" ],
18
- :check_period => "24x7",
19
- :check_interval => "5",
20
- :check_attempts => "3",
21
- :retry_check_interval => "1",
22
- :plugin => "check_nrpe",
23
- :args => "",
24
- :stalking => nil,
25
- :volatile => false,
26
- :invertresults => false,
27
- :notification_options => "w,c,r",
28
- :notification_period => nil,
29
- :notification_interval => nil,
30
- :flap_detection_enabled => true,
31
- :checktype => "Active Plugin",
32
- :save => true,
33
- :replace => false
11
+ name: 'Unknown',
12
+ description: 'Unknown',
13
+ keywords: [],
14
+ attribute: nil,
15
+ servicegroup: 'Unknown',
16
+ dependencies: ['Opsview Agent'],
17
+ check_period: '24x7',
18
+ check_interval: '5',
19
+ check_attempts: '3',
20
+ retry_check_interval: '1',
21
+ plugin: 'check_nrpe',
22
+ args: '',
23
+ stalking: nil,
24
+ volatile: false,
25
+ invertresults: false,
26
+ notification_options: 'w,c,r',
27
+ notification_period: nil,
28
+ notification_interval: nil,
29
+ flap_detection_enabled: true,
30
+ checktype: 'Active Plugin',
31
+ save: true,
32
+ replace: false
34
33
  }.update options
35
34
 
36
35
  @opsview = opsview
37
36
  @resource_type = @options[:type]
38
37
 
39
- @options[:keywords] = @options[:keywords].map { |x| { "name" => x } }
40
- @options[:servicegroup] = { "name" => @options[:servicegroup] }
41
- @options[:dependencies] = @options[:dependencies].map { |x| { "name" => x } }
42
- @options[:check_period] = { "name" => @options[:check_period] }
43
- @options[:plugin] = { "name" => @options[:plugin] }
44
- @options[:volatile] = if @options[:volatile] then 1 else 0 end
45
- @options[:invertresults] = if @options[:invertresults] then 1 else 0 end
46
- @options[:flap_detection_enabled] = if @options[:flap_detection_enabled] then 1 else 0 end
47
- @options[:checktype] = { "name" => @options[:checktype] }
38
+ @options[:keywords] = @options[:keywords].map { |x| { 'name' => x } }
39
+ @options[:servicegroup] = { 'name' => @options[:servicegroup] }
40
+ @options[:dependencies] = @options[:dependencies].map { |x| { 'name' => x } }
41
+ @options[:check_period] = { 'name' => @options[:check_period] }
42
+ @options[:plugin] = { 'name' => @options[:plugin] }
43
+ @options[:volatile] = (@options[:volatile] ? 1 : 0)
44
+ @options[:invertresults] = (@options[:invertresults] ? 1 : 0)
45
+ @options[:flap_detection_enabled] = (@options[:flap_detection_enabled] ? 1 : 0)
46
+ @options[:checktype] = { 'name' => @options[:checktype] }
48
47
 
49
48
  save(@options[:replace]) if @options[:save]
50
49
  end
51
-
52
50
  end
53
51
  end
@@ -2,26 +2,24 @@ require 'opsview_rest/mixin'
2
2
 
3
3
  class OpsviewRest
4
4
  class Servicegroup
5
-
6
5
  include OpsviewRest::Mixin
7
6
 
8
7
  attr_accessor :options, :opsview, :resource_type
9
8
 
10
9
  def initialize(opsview, options = {})
11
10
  @options = {
12
- :name => "Unknown",
13
- :servicechecks => [ "" ],
14
- :save => true,
15
- :replace => false
11
+ name: 'Unknown',
12
+ servicechecks: [''],
13
+ save: true,
14
+ replace: false
16
15
  }.update options
17
16
 
18
17
  @opsview = opsview
19
18
  @resource_type = @options[:type]
20
19
 
21
- @options[:servicechecks] = @options[:servicechecks].map { |x| { "name" => x } }
20
+ @options[:servicechecks] = @options[:servicechecks].map { |x| { 'name' => x } }
22
21
 
23
22
  save(@options[:replace]) if @options[:save]
24
23
  end
25
-
26
24
  end
27
25
  end