Class: JSS::ComputerExtensionAttribute
- Inherits:
-
ExtensionAttribute
- Object
- APIObject
- ExtensionAttribute
- JSS::ComputerExtensionAttribute
- Defined in:
- lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb,
lib/jss-api.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"
Constants inherited from ExtensionAttribute
ExtensionAttribute::DATA_TYPES, ExtensionAttribute::DEFAULT_DATA_TYPE, ExtensionAttribute::DEFAULT_INPUT_TYPE, ExtensionAttribute::DEFAULT_WEB_DISPLAY_CHOICE, ExtensionAttribute::EDITABLE_INPUT_TYPES, ExtensionAttribute::INPUT_TYPES, ExtensionAttribute::WEB_DISPLAY_CHOICES
Constants included from Updatable
Constants included from Creatable
Constants inherited from APIObject
APIObject::DEFAULT_LOOKUP_KEYS, APIObject::REQUIRED_DATA_KEYS
Instance Attribute Summary collapse
-
#platform ⇒ String
When the @input_type is “script”, The platform on which a script will run.
-
#recon_display ⇒ String
In which part of the Recon App does the data appear?.
-
#script ⇒ String
(also: #code)
The script code that will be executed when the @input_type is “script”,.
-
#scripting_language ⇒ String
The scripting language of the @script when @input_type is “script”, and the @platform is “Windows”.
Attributes inherited from ExtensionAttribute
#data_type, #description, #input_type, #popup_choices, #web_display
Attributes included from Updatable
Attributes inherited from APIObject
#id, #in_jss, #name, #rest_rsrc
Instance Method Summary collapse
-
#create ⇒ Integer
The JSS id of the newly created object.
-
#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.
-
#initialize(args = {}) ⇒ ComputerExtensionAttribute
constructor
A new instance of ComputerExtensionAttribute.
-
#input_type=(new_val) ⇒ void
Change the input type of this EA.
-
#popup_choices=(new_val) ⇒ void
This unsets any script-related attributes.
Methods inherited from ExtensionAttribute
#all_with_result, #delete, #latest_values, #update
Methods included from Updatable
Methods inherited from APIObject
all, all_ids, all_names, #delete, get_name, map_all_ids_to, #save, xml_list
Constructor Details
#initialize(args = {}) ⇒ ComputerExtensionAttribute
Returns a new instance of ComputerExtensionAttribute.
136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 136 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
#platform ⇒ String
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.
114 115 116 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 114 def platform @platform end |
#recon_display ⇒ String
Returns In which part of the Recon App does the data appear?.
127 128 129 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 127 def recon_display @recon_display end |
#script ⇒ String Also known as: code
Returns the script code that will be executed when the @input_type is “script”,.
117 118 119 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 117 def script @script end |
#scripting_language ⇒ String
The scripting language of the @script when @input_type is “script”, and the @platform is “Windows”
124 125 126 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 124 def scripting_language @scripting_language end |
Instance Method Details
#create ⇒ Integer
Returns the JSS id of the newly created object.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 159 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
285 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 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 285 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
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 189 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 |
#popup_choices=(new_val) ⇒ void
This method returns an undefined value.
This unsets any script-related attributes
211 212 213 214 215 216 |
# File 'lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb', line 211 def popup_choices= (new_val) super @script = nil @scripting_language = nil @platform = nil end |