Module: Zenoss::JSONAPI::DeviceRouter

Included in:
Connection
Defined in:
lib/zenoss/jsonapi/device_router.rb

Instance Method Summary collapse

Instance Method Details

#find_devices_by_ip(ip, opts = {}) ⇒ Array

This method will find a device for the given IP Address or all matching devices

given a partial IP.

Parameters:

  • ip (String)

    the ip address of the device to search for

  • opts (Hash) (defaults to: {})

    options to help limit device search

Options Hash (opts):

  • :deviceClass (String)

    the device class to limit the search to

  • :productionState (String)

    the production state to limit the search to

Returns:

  • (Array)

    an array of devices found or an empty array if nothing is matched



114
115
116
117
# File 'lib/zenoss/jsonapi/device_router.rb', line 114

def find_devices_by_ip(ip, opts={})
  opts[:ipAddress] = ip
  get_devices('/zport/dmd/Devices', :params => opts)
end

#find_devices_by_name(name, opts = {}) ⇒ Array

This method will allow you to search for devices by name. If you put a partial name

it will return all matching entries. For example:
find_devices_by_name 'mydev' will return all devices that start with mydev

Parameters:

  • name (String)

    the name of the device to search for

  • opts (Hash) (defaults to: {})

    options to help limit device search

Options Hash (opts):

  • :deviceClass (String)

    the device class to limit the search to

  • :productionState (String)

    the production state to limit the search to

Returns:

  • (Array)

    an array of devices found or an empty array if nothing is matched



102
103
104
105
# File 'lib/zenoss/jsonapi/device_router.rb', line 102

def find_devices_by_name(name, opts={})
  opts[:name] = name
  get_devices('/zport/dmd/Devices', :params => opts)
end

#get_devices(uid = '/zport/dmd/Devices', opts = {}) ⇒ Object

Parameters:

  • uid (String) (defaults to: '/zport/dmd/Devices')

    The organizer path to fetch devices from. This can be a devclass, group, system, or location.

  • opts (Hash) (defaults to: {})

    optional arguments to pass to getDevices

  • :params (Hash)

    a customizable set of options

Options Hash (opts):

  • :start (Fixnum)

    Offset to return the results from; used in pagination (default: 0)

  • :limit (Fixnum)

    Number of items to return; used in pagination (default: 50)

  • :sort_key (String)

    Key on which to sort the return results (default: ‘name’)

  • :sort_ord (String)

    Sort order; can be either ‘ASC’ or ‘DESC’ (default: ‘ASC’)

  • :params (Hash)

    Key-value pair of filters for this search. Can be one of the following: (default: {})



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/zenoss/jsonapi/device_router.rb', line 36

def get_devices(uid = '/zport/dmd/Devices', opts = {})
  uid = "/zport/dmd#{uid}" unless uid.start_with?('/zport/dmd')
  data = { :uid => uid }
  data[:start]  = opts[:start] if opts.has_key? :start
  data[:limit]  = opts[:limit] if opts.has_key? :limit
  data[:sort]   = opts[:sort_key] if opts.has_key? :sort_key
  data[:dir]    = opts[:sort_ord] if opts.has_key? :sort_ord
  data[:params] = opts[:params] || {}
  resp = json_request('DeviceRouter', 'getDevices', [data])

  devs = []
  resp['devices'] && resp['devices'].each do |dev|
    devs << Model::Device.new(self, dev)
  end
  devs
end

#get_info(device_id, keys = nil) ⇒ Object



57
58
59
60
61
62
# File 'lib/zenoss/jsonapi/device_router.rb', line 57

def get_info(device_id, keys = nil)
  data = {}
  data[:uid]  = device_id
  data[:keys] = keys if keys
  json_request('DeviceRouter', 'getInfo', [data])
end

#get_templates(device_id) ⇒ Object



53
54
55
# File 'lib/zenoss/jsonapi/device_router.rb', line 53

def get_templates(device_id)
  json_request('DeviceRouter', 'getTemplates', [{:id => device_id}])
end

#remodel(uid, plugins = nil, background = false) ⇒ Object

plugin such as cisco.snmp.Interfaces

Parameters:

  • uid (String)

    required; device id in Zenoss

  • plugins (String) (defaults to: nil)

    takes a string. A plugin respresents a Modeler

  • background (Boolean) (defaults to: false)

    whether to schedule a job in background



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/zenoss/jsonapi/device_router.rb', line 79

def remodel(uid, plugins = nil, background = false)
  if @zenoss_version && @zenoss_version > '6'
    data = {}
    data[:deviceUid] = uid
    data[:collectPlugins] = plugins || ''
    data[:background] = background
    json_request('DeviceRouter', 'remodel', [data])
  else
    raise ZenossError, 'remodel method on DeviceRouter is only allowed '\
                       'for version 6 and above'
  end
end

#set_info(opts = {}) ⇒ Object

Parameters:

  • opts (Hash) (defaults to: {})

    arguments to pass to setInfo

Options Hash (opts):

  • :uid (String)

    required; device id in Zenoss



66
67
68
69
70
71
72
73
# File 'lib/zenoss/jsonapi/device_router.rb', line 66

def set_info(opts = {})
  if @zenoss_version && @zenoss_version > '6'
    json_request('DeviceRouter', 'setInfo', [opts])
  else
    raise ZenossError, 'setInfo method on DeviceRouter is only allowed '\
                       'for version 6 and above'
  end
end