Class: JSS::ComputerExtensionAttribute
- Inherits:
-
ExtensionAttribute
- Object
- APIObject
- ExtensionAttribute
- JSS::ComputerExtensionAttribute
- 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"
- 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
-
#need_to_update ⇒ Boolean
included
from Updatable
readonly
Do we have unsaved changes?.
-
#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”.
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.
Constructor Details
#initialize(args = {}) ⇒ ComputerExtensionAttribute
Returns a new instance of ComputerExtensionAttribute.
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 142 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_update ⇒ Boolean (readonly) Originally defined in module Updatable
Returns do we have unsaved changes?.
#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.
120 121 122 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 120 def platform @platform end |
#recon_display ⇒ String
Returns In which part of the Recon App does the data appear?.
133 134 135 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 133 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”,.
123 124 125 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 123 def script @script end |
#scripting_language ⇒ String
The scripting language of the @script when @input_type is “script”, and the @platform is “Windows”
130 131 132 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 130 def scripting_language @scripting_language end |
Instance Method Details
#create ⇒ Integer
Returns the JSS id of the newly created object.
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 165 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
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 326 327 328 329 330 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 291 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(api: @api) computer when *JSS::Computer.all_names(api: @api) JSS::Computer.map_all_ids_to(:name, api: @api).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
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 195 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
217 218 219 220 221 222 |
# File 'lib/jss/api_object/extension_attribute/computer_extension_attribute.rb', line 217 def popup_choices= (new_val) super @script = nil @scripting_language = nil @platform = nil end |