Class: Zenoss::Model::Device

Inherits:
Object
  • Object
show all
Includes:
Zenoss::Model, DeviceResultInt, EventView, RRDView
Defined in:
lib/model/devices/device.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from DeviceResultInt

#device_class, #get_device_class_name, #get_device_class_path

Methods included from RRDView

#get_rrd_data_points, #get_rrd_values

Methods included from Zenoss::Model

#model_init

Methods included from Zenoss

devices, services, set_auth, systems, uri

Methods included from EventView

#get_event_history, #get_event_manager, #get_status, #get_status_css_class, #get_status_img_src

Constructor Details

- (Device) initialize(device_path)

A new instance of Device



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/model/devices/device.rb', line 30

def initialize(device_path)
  device_path.sub(/^\/zport\/dmd\/(.*)\/([^\/]+)$/) do |m|
    @path = $1
    @device = $2
  end

  @os = OperatingSystem.new(self)
  @hw = DeviceHW.new(self)

  # Initialize common things from Model
  model_init
end

Instance Attribute Details

- (Object) device (readonly)

Returns the value of attribute device



28
29
30
# File 'lib/model/devices/device.rb', line 28

def device
  @device
end

- (Object) hw (readonly)

Returns the value of attribute hw



28
29
30
# File 'lib/model/devices/device.rb', line 28

def hw
  @hw
end

- (Object) os (readonly)

Returns the value of attribute os



28
29
30
# File 'lib/model/devices/device.rb', line 28

def os
  @os
end

- (Object) path (readonly)

Returns the value of attribute path



28
29
30
# File 'lib/model/devices/device.rb', line 28

def path
  @path
end

Instance Method Details

- (Object) change_device_class(device_class)

Move this Device to the given DeviceClass.



56
57
58
59
# File 'lib/model/devices/device.rb', line 56

def change_device_class(device_class)
  reset_cache_vars
  rest("changeDeviceClass?deviceClassPath=#{device_class.organizer_name}")
end

- (Object) get_data_for_json

Returns data ready for serialization



89
90
91
# File 'lib/model/devices/device.rb', line 89

def get_data_for_json
  plist_to_array( rest('getDataForJSON') )
end

- (Object) get_device_components(monitored = nil, collector = nil, type = nil)

Return list of all DeviceComponents on this device



188
189
190
191
192
193
194
195
196
197
# File 'lib/model/devices/device.rb', line 188

def get_device_components(monitored=nil, collector=nil, type=nil)
  method = "getDeviceComponents"
  method << '?' unless(monitored.nil? && collector.nil? && type.nil?)
  method << "monitored=#{monitored}&" unless monitored.nil?
  method << "collector=#{collector}&" unless collector.nil?
  method << "type=#{type}" unless type.nil?
  components = rest(method)

  plist_to_array(components)
end

- (Object) get_device_group_names



93
94
95
# File 'lib/model/devices/device.rb', line 93

def get_device_group_names
  plist_to_array( rest('getDeviceGroupNames') )
end

- (Object) get_events

------------------ Custom REST Calls ------------------ # These are not part of the official Zenoss API



47
48
49
# File 'lib/model/devices/device.rb', line 47

def get_events
  get_event_manager.get_event_list(nil,"device='#{@device}'")
end

- (Object) get_hw_product_name



72
73
74
# File 'lib/model/devices/device.rb', line 72

def get_hw_product_name
  rest('getHWProductName')
end

- (Object) get_id

Instead of calling the /getId REST method, this method simply returns the @device value since it is the same anyway.



64
65
66
# File 'lib/model/devices/device.rb', line 64

def get_id()
  @device
end

- (Object) get_last_change

Returns a DateTime instance when this device was last modified.



98
99
100
# File 'lib/model/devices/device.rb', line 98

def get_last_change
  pdatetime_to_datetime( rest('getLastChange') )
end

Get the HTML formatted link to the Location that this devices exists at. If you are looking for just the name, use #get_location_name instead.



78
79
80
# File 'lib/model/devices/device.rb', line 78

def get_location_link
  rest('getLocationLink')
end

- (Object) get_location_name

Returns a String value of the Location that this device exists at. You can also issue #get_location_link if you want an HTML link to the location page.



84
85
86
# File 'lib/model/devices/device.rb', line 84

def get_location_name
  rest('getLocationName')
end

- (Object) get_manage_ip

Return the management ip for this device.



103
104
105
# File 'lib/model/devices/device.rb', line 103

def get_manage_ip
  rest('getManageIp')
end

- (Object) get_monitored_components(collector = nil, type = nil)

Return list of monitored DeviceComponents on this device



176
177
178
179
180
181
182
183
184
185
# File 'lib/model/devices/device.rb', line 176

def get_monitored_components(collector=nil, type=nil)
  method = "getMonitoredComponents"
  method << '?' unless(collector.nil? && type.nil?)
  method << "collector=#{collector}&" unless collector.nil?
  method << "type=#{type}" unless type.nil?
  components = rest(method)

  # Turn the return string into an array of components
  (components.gsub /[\[\]]/,'').split /,\s+/
end

- (Object) get_performance_server_name

Returns the name of the Zenoss Collector that this host currently belogs to.



108
109
110
# File 'lib/model/devices/device.rb', line 108

def get_performance_server_name
  rest('getPerformanceServerName')
end

- (Object) get_ping_status_string

Return the pingStatus as a string



113
114
115
# File 'lib/model/devices/device.rb', line 113

def get_ping_status_string
  rest('getPingStatusString')
end


117
118
119
# File 'lib/model/devices/device.rb', line 117

def get_pretty_link
  rest('getPrettyLink')
end

- (Object) get_priority

Return the numeric device priority.



122
123
124
# File 'lib/model/devices/device.rb', line 122

def get_priority
  (rest('getPriority')).to_i
end

- (Object) get_priority_string

Return the device priority as a string.



127
128
129
# File 'lib/model/devices/device.rb', line 127

def get_priority_string
  rest('getPriorityString')
end

- (Object) get_production_state_string

Return the prodstate as a string.



132
133
134
# File 'lib/model/devices/device.rb', line 132

def get_production_state_string
  rest('getProductionStateString')
end

- (Object) get_rrd_templates



136
137
# File 'lib/model/devices/device.rb', line 136

def get_rrd_templates
end

- (Object) get_snmp_last_collection

Returns a DateTime instance when this device was last collected from.



140
141
142
# File 'lib/model/devices/device.rb', line 140

def get_snmp_last_collection
  pdatetime_to_datetime( rest('getSnmpLastCollection') )
end

- (Object) get_snmp_status_string

Return the snmpStatus as a string.



145
146
147
# File 'lib/model/devices/device.rb', line 145

def get_snmp_status_string
  rest('getSnmpStatusString')
end

- (Object) get_system_names

Returns an Array of Zenoss /Systems that this device belogs to.



150
151
152
# File 'lib/model/devices/device.rb', line 150

def get_system_names
  plist_to_array( rest('getSystemNames') )
end

- (Object) get_system_names_string(sep = ','))

Return the Zenoss /Systems that this device belogs to in a string separated by "sep".



201
202
203
# File 'lib/model/devices/device.rb', line 201

def get_system_names_string(sep=',')
  rest("getSystemNamesString?sep=#{sep}")
end

- (Boolean) monitor_device?

Returns true if the device production state >= zProdStateThreshold.

Returns:

  • (Boolean)


155
156
157
# File 'lib/model/devices/device.rb', line 155

def monitor_device?
  (rest('monitorDevice')).eql?('True') ? true : false
end

- (Object) set_hw_tag(asset_tag)

Update the devices hardware tag with the passed string



170
171
172
173
# File 'lib/model/devices/device.rb', line 170

def set_hw_tag(asset_tag)
  puts "No REST implementation yet."
  #rest("setHWTag?assettag#{asset_tag}")
end

- (Boolean) snmp_monitor_device?

Returns true if the device is subject to SNMP monitoring

Returns:

  • (Boolean)


160
161
162
# File 'lib/model/devices/device.rb', line 160

def snmp_monitor_device?
  (rest('snmpMonitorDevice')).eql?('True') ? true : false
end

- (Object) sys_uptime



68
69
70
# File 'lib/model/devices/device.rb', line 68

def sys_uptime
  rest("sysUpTime")
end

- (Object) uptime_str

Return the SNMP uptime



165
166
167
# File 'lib/model/devices/device.rb', line 165

def uptime_str
  rest('uptimeStr')
end