Class: OpsviewRest::Host

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin

#resource_path, #save, #to_json

Constructor Details

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



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
68
69
70
71
72
73
# File 'lib/opsview_rest/host.rb', line 9

def initialize(opsview, options = {})
  # Default set of attributes to send to Opsview:
  @options = {
    flap_detection_enabled: false,
    snmpv3_privprotocol: nil,
    hosttemplates: [],
    keywords: [],
    check_period: '24x7',
    hostattributes: [],
    notification_period: '24x7',
    name: 'unknown',
    rancid_vendor: nil,
    snmp_community: 'public',
    hostgroup: 'Unknown',
    enable_snmp: false,
    monitored_by: 'Master Monitoring Server',
    alias: 'Managed Host',
    uncommitted: false,
    parents: [],
    icon: { 'name' => 'LOGO - Opsview' },
    retry_check_interval: 1,
    ip: 'localhost',
    use_mrtg: false,
    servicechecks: [],
    use_rancid: false,
    nmis_node_type: 'router',
    snmp_version: '2c',
    snmp_authpassword: '',
    use_nmis: false,
    rancid_connection_type: 'ssh',
    snmpv3_authprotocol: nil,
    rancid_username: nil,
    rancid_password: nil,
    check_command: 'ping',
    check_attempts: 2,
    check_interval: 0,
    notification_interval: 60,
    snmp_port: 161,
    snmpv3_username: '',
    snmpv3_privpassword: '',
    other_addresses: '',
    save: true,
    replace: false
  }.update options

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

  # Add any weird exceptions here (like hostgroups having to be mapped
  # to "name" => hostgroup, etc.):
  @options[:flap_detection_enabled] = (@options[:flap_detection_enabled] ? 1 : 0)
  @options[:enable_snmp] = (@options[:enable_snmp] ? 1 : 0)
  @options[:use_mrtg] = (@options[:use_mrtg] ? 1 : 0)
  @options[:use_rancid] = (@options[:use_rancid] ? 1 : 0)
  @options[:use_nmis] = (@options[:use_nmis] ? 1 : 0)
  @options[:uncommitted] = (@options[:uncommitted] ? 1 : 0)
  @options[:check_period] = { 'name' => @options[:check_period] }
  @options[:hostgroup] = { 'name' => @options[:hostgroup] }
  @options[:notification_period] = { 'name' => @options[:notification_period] }
  @options[:monitored_by] = { 'name' => @options[:monitored_by] }
  @options[:servicechecks] = @options[:servicechecks].map { |x| { 'name' => x } }
  @options[:check_command] = { 'name' => @options[:check_command] }

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

Instance Attribute Details

#opsviewObject

Returns the value of attribute opsview.



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

def opsview
  @opsview
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#resource_typeObject

Returns the value of attribute resource_type.



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

def resource_type
  @resource_type
end