Class: Zenoss::Model::Device

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

Instance Method Summary collapse

Methods included from ZenPropertyManager

#cust_property_ids, #delete_cust_property, #delete_zen_property, #get_cust_property, #set_cust_property, #set_zen_property, #zen_property_ids, #zen_property_items

Methods included from DeviceResultInt

#device_class, #get_device_class_name, #get_device_class_path

Methods included from RRDView

#fetch_rrd_value, #get_rrd_data_points, #get_rrd_values, #parse_rrd_fetch

Methods included from Zenoss::Model

#model_init

Methods included from Zenoss

connect, #parse_array, #pdatetime_to_datetime, #pdict_to_hash, #plist_to_array, #ptuples_to_hash, #sanitize_str

Methods included from EventView

#get_status, #get_status_css_class, #get_status_img_src

Constructor Details

#initialize(zenoss, zhash) ⇒ Device

Initialize this object from a Hash returned via getDevices from the JSON api @param zenoss the current instance we are connecting with @param zhash a hash of values used to create this Device instance



32
33
34
35
36
# File 'lib/zenoss/model/devices/device.rb', line 32

def initialize(zenoss,zhash)
  @zenoss = zenoss
  super zhash
  self.ipAddress = IPAddr.new(IPAddr.inet_ntoa(self.ipAddress)) if self.ipAddress
end

Instance Method Details

#change_device_class(device_class) ⇒ Object

Move this Device to the given DeviceClass.



61
62
63
64
# File 'lib/zenoss/model/devices/device.rb', line 61

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

#get_data_for_jsonObject

Returns data ready for serialization



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

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

#get_device_components(monitored = nil, collector = nil, type = nil) ⇒ Object

Return list of all DeviceComponents on this device



193
194
195
196
197
198
199
200
201
202
# File 'lib/zenoss/model/devices/device.rb', line 193

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

#get_device_group_namesObject



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

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

#get_event_historyObject



45
46
47
# File 'lib/zenoss/model/devices/device.rb', line 45

def get_event_history
  @zenoss.query_events(self.uid,{:history => true})
end

#get_eventsObject

Get events for this device



41
42
43
# File 'lib/zenoss/model/devices/device.rb', line 41

def get_events
  @zenoss.query_events(self.uid)
end

#get_hw_product_nameObject



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

def get_hw_product_name
  rest('getHWProductName')
end

#get_idObject

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



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

def get_id()
  @device
end

#get_info(keys = nil) ⇒ Object



49
50
51
# File 'lib/zenoss/model/devices/device.rb', line 49

def get_info(keys = nil)
  @zenoss.get_info(self.uid, keys)
end

#get_last_changeObject

Returns a DateTime instance when this device was last modified.



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

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.



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

def get_location_link
  rest('getLocationLink')
end

#get_location_nameObject

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.



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

def get_location_name
  rest('getLocationName')
end

#get_manage_ipObject

Return the management ip for this device.



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

def get_manage_ip
  rest('getManageIp')
end

#get_monitored_components(collector = nil, type = nil) ⇒ Object

Return list of monitored DeviceComponents on this device



181
182
183
184
185
186
187
188
189
190
# File 'lib/zenoss/model/devices/device.rb', line 181

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

#get_performance_server_nameObject

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



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

def get_performance_server_name
  rest('getPerformanceServerName')
end

#get_ping_status_stringObject

Return the pingStatus as a string



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

def get_ping_status_string
  rest('getPingStatusString')
end


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

def get_pretty_link
  rest('getPrettyLink')
end

#get_priorityObject

Return the numeric device priority.



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

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

#get_priority_stringObject

Return the device priority as a string.



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

def get_priority_string
  rest('getPriorityString')
end

#get_production_state_stringObject

Return the prodstate as a string.



137
138
139
# File 'lib/zenoss/model/devices/device.rb', line 137

def get_production_state_string
  rest('getProductionStateString')
end

#get_rrd_templatesObject



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

def get_rrd_templates
end

#get_snmp_last_collectionObject

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



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

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

#get_snmp_status_stringObject

Return the snmpStatus as a string.



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

def get_snmp_status_string
  rest('getSnmpStatusString')
end

#get_system_namesObject

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



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

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

#get_system_names_string(sep = ',') ⇒ Object

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



206
207
208
# File 'lib/zenoss/model/devices/device.rb', line 206

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

#monitor_device?Boolean

Returns true if the device production state >= zProdStateThreshold.

Returns:

  • (Boolean)


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

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

#rename_device(new_name) ⇒ Object

Change name of the device



211
212
213
214
215
216
217
# File 'lib/zenoss/model/devices/device.rb', line 211

def rename_device(new_name)
  ret = rest("renameDevice?newId=#{new_name}")
  if ret
    self.name  = new_name
  end
  return ret
end

#set_hw_tag(asset_tag) ⇒ Object

Update the devices hardware tag with the passed string



175
176
177
178
# File 'lib/zenoss/model/devices/device.rb', line 175

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

#set_info(opts = {}) ⇒ Object



53
54
55
56
# File 'lib/zenoss/model/devices/device.rb', line 53

def set_info(opts = {})
  opts[:uid] = self.uid
  @zenoss.set_info(opts)
end

#snmp_monitor_device?Boolean

Returns true if the device is subject to SNMP monitoring

Returns:

  • (Boolean)


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

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

#sys_uptimeObject



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

def sys_uptime
  rest("sysUpTime")
end

#uptime_strObject

Return the SNMP uptime



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

def uptime_str
  rest('uptimeStr')
end