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'.freeze
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
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: '')
PLATFORM_MAC =

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

'Mac'.freeze
PLATFORM_WINDOWS =
'Windows'.freeze
PLATFORMS =
[PLATFORM_MAC, PLATFORM_WINDOWS].freeze
LANGUAGE_VBS =

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

'VBScript'.freeze
LANGUAGE_BAT =
'Batch File'.freeze
LANGUAGE_PSH =
'PowerShell'.freeze
WINDOWS_SCRIPTING_LANGUAGES =
[LANGUAGE_VBS, LANGUAGE_BAT, LANGUAGE_PSH].freeze
RECON_DISPLAY_CHOICES =

Where can it be displayed in the Recon App?

[
  'Computer',
  'User and Location',
  'Purchasing',
  'Extension Attributes'
].freeze
DEFAULT_RECON_DISPLAY_CHOICE =
'Extension Attributes'.freeze
OBJECT_HISTORY_OBJECT_TYPE =

the object type for this object in the object history table. See APIObject#add_object_history_entry

73

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from JSS::ExtensionAttribute

Instance Attribute Details

#enabledBoolean (readonly) Also known as: enabled?

Returns if the input type is 'script', is this EA enabled?.

Returns:

  • (Boolean)

    if the input type is 'script', is this EA enabled?


90
91
92
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 90

def enabled
  @enabled
end

#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. DEPRECATED: windows EAs are no longer supported

Returns:


101
102
103
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 101

def platform
  @platform
end

#recon_displayString

DEPRECATED: this is no longer separate from the web_display.

Returns:

  • (String)

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


112
113
114
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 112

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”,


86
87
88
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 86

def script
  @script
end

#scripting_languageString

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

DEPRECATED: windows EAs are no longer supported

Returns:


108
109
110
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 108

def scripting_language
  @scripting_language
end

Instance Method Details

#disablevoid

This method returns an undefined value.

disable this script ea


143
144
145
146
147
148
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 143

def disable
  return unless enabled?

  @enabled = false
  @need_to_update = true
end

#enablevoid

This method returns an undefined value.

enable this script ea


132
133
134
135
136
137
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 132

def enable
  return if enabled?

  @enabled = true
  @need_to_update = true
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:


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 222

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 = JSS::Computer.valid_id computer, api: @api
  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}
  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