Class: OpsviewRest::Contact

Inherits:
Object
  • Object
show all
Includes:
Mixin
Defined in:
lib/opsview_rest/contact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin

#resource_path, #save, #to_json

Constructor Details

#initialize(opsview, options = {}) ⇒ Contact

Returns a new instance of Contact.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/opsview_rest/contact.rb', line 9

def initialize(opsview, options = {})
  @options = {
    name: 'foobar',
    fullname: '',
    description: '',
    encrypted_password: '$apr1$HTQogYE7$09TNcZWa/WzoBXdUF6Iyr1',
    realm: 'local',
    language: '',
    role: 'View all, change none',
    variables: [
      { value: '', name: 'EMAIL' },
      { value: 1, name: 'RSS_COLLAPSED' },
      { value: 1440, name: 'RSS_MAXIMUM_AGE' },
      { value: 30, name: 'RSS_MAXIMUM_ITEMS' }
    ],
    notificationprofiles: [
      { name: '24x7',
        host_notification_options: 'u,d,r,f',
        notificationmethods: [
          { name: 'Email' }
        ],
        servicegroups: [],
        all_servicegroups: 1,
        all_hostgroups: 0,
        keywords: [],
        service_notification_options: 'w,c,r,u,f',
        hostgroups: [],
        notification_level: 1,
        notification_period: { name: '24x7' } },
      { name: '8x5',
        host_notification_options: 'u,d,r,f',
        notificationmethods: [
          { name: 'Email' }
        ],
        servicegroups: [],
        all_servicegroups: 1,
        all_hostgroups: 0,
        keywords: [],
        service_notification_options: 'w,c,r,u,f',
        hostgroups: [],
        notification_level: 1,
        notification_period: { name: 'workhours' } }
    ],
    save: true,
    replace: false
  }.update options

  @opsview = opsview
  @resource_type = @options[:type]

  @options[:all_servicegroups] = (@options[:all_servicegroups] ? 1 : 0)
  @options[:all_hostgroups] = (@options[:all_hostgroups] ? 1 : 0)
  @options[:servicegroups] = @options[:servicegroups].map { |x| { 'name' => x } } unless @options[:servicegroups].nil?
  @options[:keywords] = @options[:keywords].map { |x| { 'name' => x } } unless @options[:keywords].nil?
  @options[:hostgroups] = @options[:hostgroups].map { |x| { 'name' => x } } unless @options[:hostgroups].nil?
  @options[:role] = { 'name' => @options[:role] }

  save(@options[:replace]) if @options[:save]
end

Instance Attribute Details

#opsviewObject

Returns the value of attribute opsview.



7
8
9
# File 'lib/opsview_rest/contact.rb', line 7

def opsview
  @opsview
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/opsview_rest/contact.rb', line 7

def options
  @options
end

#resource_typeObject

Returns the value of attribute resource_type.



7
8
9
# File 'lib/opsview_rest/contact.rb', line 7

def resource_type
  @resource_type
end