Method: JSS::ComputerExtensionAttribute#history
- Defined in:
- lib/jss/api_object/extension_attribute/computer_extension_attribute.rb
#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
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 = " SELECT eav.value_on_client AS value, r.date_entered_epoch AS timestamp_epoch\n FROM extension_attribute_values eav JOIN reports r ON eav.report_id = r.report_id\n WHERE r.computer_id = \#{computer_id}\n AND eav.extension_attribute_id = \#{@id}\n ORDER BY timestamp_epoch\n END_Q\n\n qrez = JSS::DB_CNX.db.query the_query\n history = []\n\n qrez.each_hash do |entry|\n value =\n case @data_type\n when 'String' then entry['value']\n when 'Integer' then entry['value'].to_i\n when 'Date' then JSS.parse_datetime(entry['value'])\n end # case\n newhash = { value: value, timestamp: JSS.epoch_to_time(entry['timestamp_epoch']) }\n history << newhash\n end # each hash\n\n history\nend\n" |