Class: JSS::ComputerExtensionAttribute

Inherits:
ExtensionAttribute show all
Defined in:
lib/jss/api_object/extension_attribute/computer_extension_attribute.rb,
lib/jss.rb

Overview

The definition of a Computer extension attribute in the JSS

Constant Summary collapse

RSRC_BASE =

The base for REST resources of this class

"computerextensionattributes"
RSRC_LIST_KEY =

the hash key used for the JSON list output of all objects in the JSS

:computer_extension_attributes
RSRC_OBJECT_KEY =

The hash key used for the JSON object output. It’s also used in various error messages

:computer_extension_attribute
VALID_DATA_KEYS =

these keys, as well as :id and :name, are present in valid API JSON data for this class

[:description, :inventory_display, :recon_display]
TARGET_CLASS =

these ext attribs are related to these kinds of objects

JSS::Computer
ALL_TARGETS_CRITERION =

A criterion that will return all members of the TARGET_CLASS

JSS::Criteriable::Criterion.new(:and_or => "and", :name => "Username", :search_type => "like", :value => '')
PLATFORMS =

When the intput type is script, what platforms can they run on?

["Mac","Windows"]
WINDOWS_SCRIPTING_LANGUAGES =

When the platform is Windows, what languages can be user?

["VBScript", "Batch File", "PowerShell"]
RECON_DISPLAY_CHOICES =

Where can it be displayed in the Recon App?

[
  "Computer",
  "User and Location",
  "Purchasing",
  "Extension Attributes"
]
DEFAULT_RECON_DISPLAY_CHOICE =
"Extension Attributes"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ComputerExtensionAttribute

Returns a new instance of ComputerExtensionAttribute.



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 137

def initialize(args = {})

  super args

  @recon_display = @init_data[:recon_display] || DEFAULT_RECON_DISPLAY_CHOICE

  if @init_data[:input_type]
    @platform = @init_data[:input_type][:platform]
    @script = @init_data[:input_type][:script]
    @scripting_language = @init_data[:input_type][:scripting_language]
  end
end

Instance Attribute Details

#need_to_updateBoolean (readonly) Originally defined in module Updatable

Returns do we have unsaved changes?.

Returns:

  • (Boolean)

    do we have unsaved changes?

#platformString

When the @input_type is “script”, The platform on which a script will run.

NOTE: The web app seems to let you have both Mac and Windows scripts defined when the type is “script”, however the API will only return the Mac script info if both are defined.

Returns:



115
116
117
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 115

def platform
  @platform
end

#recon_displayString

Returns In which part of the Recon App does the data appear?.

Returns:

  • (String)

    In which part of the Recon App does the data appear?



128
129
130
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 128

def recon_display
  @recon_display
end

#scriptString Also known as: code

Returns the script code that will be executed when the @input_type is “script”,.

Returns:

  • (String)

    the script code that will be executed when the @input_type is “script”,



118
119
120
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 118

def script
  @script
end

#scripting_languageString

The scripting language of the @script when @input_type is “script”, and the @platform is “Windows”

Returns:



125
126
127
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 125

def scripting_language
  @scripting_language
end

Instance Method Details

#createInteger

Returns the JSS id of the newly created object.

Returns:

  • (Integer)

    the JSS id of the newly created object

See Also:



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 160

def create
  if @input_type ==  "script"
      raise MissingDataError, "No platform set for script input_type." unless @platform
      raise MissingDataError, "No script set for script input_type." unless @script
      if @platform == "Windows"
        raise MissingDataError, "No scripting_language set for Windows script input_type." unless @scripting_language
      end
  end # case

  super
end

#history(computer) ⇒ Array<Hash{:timestamp=>Time,:value=>String,Integer,Time}>

Return an Array of Hashes showing the history of reported values for this EA on one computer.

Each hash contains these 2 keys:

  • :value - String, Integer, or Time, depending on @data_type

  • :timestamp - Time

This method requires a MySQL database connection established via JSS::DB_CNX.connect

Parameters:

  • computer (Integer, String)

    the id or name of the Computer.

Returns:

Raises:

See Also:



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 286

def history(computer)
  raise JSS::NoSuchItemError, "EA Not In JSS! Use #create to create this #{RSRC_OBJECT_KEY}." unless @in_jss
  raise JSS::InvalidConnectionError, "Database connection required for 'history' query." unless JSS::DB_CNX.connected?

  computer_id = case computer
    when *JSS::Computer.all_ids
      computer
    when *JSS::Computer.all_names
      JSS::Computer.map_all_ids_to(:name).invert[computer]
    else nil
  end # case

  raise JSS::NoSuchItemError, "No computer found matching '#{computer}'" unless computer_id

  the_query = <<-END_Q
  SELECT eav.value_on_client AS value, r.date_entered_epoch AS timestamp_epoch
  FROM extension_attribute_values eav JOIN reports r ON eav.report_id = r.report_id
  WHERE r.computer_id = #{computer_id}
    AND eav.extension_attribute_id = #{@id}
    AND eav.value_on_client != ''
    AND eav.value_on_client IS NOT NULL
    AND eav.value_on_client != '(null)'
  ORDER BY timestamp_epoch
  END_Q

  qrez = JSS::DB_CNX.db.query the_query
  history = []

  qrez.each_hash do |entry|
    value = case @data_type
      when 'String' then entry['value']
      when 'Integer' then entry['value'].to_i
      when 'Date' then JSS.parse_datetime(entry['value'])
    end # case
    newhash = {:value => value, :timestamp => JSS.epoch_to_time(entry['timestamp_epoch']) }
    history << newhash
  end # each hash

  history
end

#input_type=(new_val) ⇒ void

This method returns an undefined value.

Change the input type of this EA



190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 190

def input_type= (new_val)
  raise JSS::InvalidDataError, "ComputerExtensionAttribute input_types cannot be 'LDAP Attribute Mapping'" if new_val == 'LDAP Attribute Mapping'

  super

  case @input_type
    when *["Text Field","Pop-up Menu"]
      @script = nil
      @scripting_language = nil
      @platform = nil
    when "script"
      @popup_choices = nil
  end # case
end

This method returns an undefined value.

This unsets any script-related attributes

Parameters:



212
213
214
215
216
217
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 212

def popup_choices= (new_val)
  super
  @script = nil
  @scripting_language = nil
  @platform = nil
end