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

Returns a new instance of Host.



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
74
# File 'lib/opsview_rest/host.rb', line 10

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] = if @options[:flap_detection_enabled] then 1 else 0 end
  @options[:enable_snmp] = if @options[:enable_snmp] then 1 else 0 end
  @options[:use_mrtg] = if @options[:use_mrtg] then 1 else 0 end
  @options[:use_rancid] = if @options[:use_rancid] then 1 else 0 end
  @options[:use_nmis] = if @options[:use_nmis] then 1 else 0 end
  @options[:uncommitted] = if @options[:uncommitted] then 1 else 0 end
  @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.



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

def opsview
  @opsview
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#resource_typeObject

Returns the value of attribute resource_type.



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

def resource_type
  @resource_type
end