Line 15... |
Line 15... |
15 |
*
|
15 |
*
|
16 |
* V0.9.2 20160217 RWR
|
16 |
* V0.9.2 20160217 RWR
|
17 |
* Fixed issue where if a device was marked as part of a Xen machine, it
|
17 |
* Fixed issue where if a device was marked as part of a Xen machine, it
|
18 |
* was being deleted by pci updates.
|
18 |
* was being deleted by pci updates.
|
19 |
* Fixed issue where serial number was not being updated
|
19 |
* Fixed issue where serial number was not being updated
|
- |
|
20 |
*
|
- |
|
21 |
* v0.9.3 20200218 RWR
|
- |
|
22 |
* Fixed invalid table name (attrib_device vs device_attrib) and set up to read a new section, attributes
|
20 |
*
|
23 |
*
|
21 |
*/
|
24 |
*/
|
22 |
|
25 |
|
23 |
require 'library.php';
|
26 |
require 'library.php';
|
24 |
$VERSION='0.9.2';
|
27 |
$VERSION='0.9.3';
|
25 |
|
28 |
|
26 |
|
29 |
|
27 |
class sysinfo {
|
30 |
class sysinfo {
|
28 |
private $report; // this will hold an entire report
|
31 |
private $report; // this will hold an entire report
|
29 |
private $messages = array();
|
32 |
private $messages = array();
|
Line 77... |
Line 80... |
77 |
$this->updateBootTime();
|
80 |
$this->updateBootTime();
|
78 |
$this->doIPAddresses();
|
81 |
$this->doIPAddresses();
|
79 |
$this->processPCI();
|
82 |
$this->processPCI();
|
80 |
$this->processSoftwarePackages();
|
83 |
$this->processSoftwarePackages();
|
81 |
$this->processXen();
|
84 |
$this->processXen();
|
- |
|
85 |
$this->processAttributes();
|
82 |
// at this point, we don't really need the report title information
|
86 |
// at this point, we don't really need the report title information
|
83 |
// so we will remove it before recordReport has a chance to put it
|
87 |
// so we will remove it before recordReport has a chance to put it
|
84 |
// in database
|
88 |
// in database
|
85 |
array_shift( $this->messages );
|
89 |
array_shift( $this->messages );
|
86 |
// now record the report
|
90 |
// now record the report
|
Line 287... |
Line 291... |
287 |
$this->returnCode = 6;
|
291 |
$this->returnCode = 6;
|
288 |
return "New entry detected, but entry already made. You must update Camp before this can be processed";
|
292 |
return "New entry detected, but entry already made. You must update Camp before this can be processed";
|
289 |
}
|
293 |
}
|
290 |
}
|
294 |
}
|
291 |
|
295 |
|
292 |
// simply used to get an attrib_id. If it does not exit, will create it
|
296 |
// simply used to get an attrib_id. If it does not exist, will create it
|
293 |
|
297 |
|
294 |
private function getAttributeID ( $attributeName, $reportDate ) {
|
298 |
private function getAttributeID ( $attributeName, $reportDate ) {
|
295 |
$attributeName = makeSafeSQLValue( $attributeName );
|
299 |
$attributeName = makeSafeSQLValue( $attributeName );
|
296 |
$result = getOneDBValue( "select attrib_id from attrib where name = $attributeName and removed_date is null" );
|
300 |
$result = getOneDBValue( "select attrib_id from attrib where name = $attributeName and removed_date is null" );
|
297 |
if ( !isset( $result) ) {
|
301 |
if ( !isset( $result) ) {
|
Line 319... |
Line 323... |
319 |
$value1 == $value2;
|
323 |
$value1 == $value2;
|
320 |
}
|
324 |
}
|
321 |
|
325 |
|
322 |
|
326 |
|
323 |
/*
|
327 |
/*
|
324 |
* Checks an attribute from the device_attriburtes table. If the value has
|
328 |
* Checks an attribute from the attrib_deviceurtes table. If the value has
|
325 |
* changed, sets the old one's removed_date to this report date, then adds
|
329 |
* changed, sets the old one's removed_date to this report date, then adds
|
326 |
* new record for new value.
|
330 |
* new record for new value.
|
327 |
* If value is not off by more than $slop, will not update. Useful for memory and speed on
|
331 |
* If value is not off by more than $slop, will not update. Useful for memory and speed on
|
328 |
* virtual devices where the values may be slightly different at different readings
|
332 |
* virtual devices where the values may be slightly different at different readings
|
329 |
* If the record does not exist, simply creates it
|
333 |
* If the record does not exist, simply creates it
|
Line 332... |
Line 336... |
332 |
if ( !isset($attribute) || !isset($value ) ) {
|
336 |
if ( !isset($attribute) || !isset($value ) ) {
|
333 |
$this->messages[] = "Error: attempt to use null value for [$attribute], value [$value] for ID $this->machineID in checkAndUPdateAttribute";
|
337 |
$this->messages[] = "Error: attempt to use null value for [$attribute], value [$value] for ID $this->machineID in checkAndUPdateAttribute";
|
334 |
return false;
|
338 |
return false;
|
335 |
}
|
339 |
}
|
336 |
$attrib_id = $this->getAttributeID( $attribute, $this->reportDateSQL );
|
340 |
$attrib_id = $this->getAttributeID( $attribute, $this->reportDateSQL );
|
337 |
$result = getOneDBValue( "select device_attrib.value
|
341 |
$result = getOneDBValue( "select attrib_device.value
|
338 |
from device_attrib join attrib using (attrib_id)
|
342 |
from attrib_device join attrib using (attrib_id)
|
339 |
where device_attrib.device_id = $this->machineID
|
343 |
where attrib_device.device_id = $this->machineID
|
340 |
and device_attrib.removed_date is null
|
344 |
and attrib_device.removed_date is null
|
341 |
and attrib.attrib_id = $attrib_id
|
345 |
and attrib.attrib_id = $attrib_id
|
342 |
");
|
346 |
");
|
343 |
if ( isset( $result ) && ! $this->sloppyEqual( $value, $result, $slop ) ) { # got it, now see if it compares ok
|
347 |
if ( isset( $result ) && ! $this->sloppyEqual( $value, $result, $slop ) ) { # got it, now see if it compares ok
|
344 |
$this->messages[] = "New value [$value] for $attribute for device $this->machineID, voiding previous";
|
348 |
$this->messages[] = "New value [$value] for $attribute for device $this->machineID, voiding previous";
|
345 |
$value = makeSafeSQLValue($value); # we want to always quote the value on this particular one
|
349 |
$value = makeSafeSQLValue($value); # we want to always quote the value on this particular one
|
346 |
queryDatabaseExtended( "update device_attrib
|
350 |
queryDatabaseExtended( "update attrib_device
|
347 |
set removed_date = '$this->reportDateSQL'
|
351 |
set removed_date = '$this->reportDateSQL'
|
348 |
where device_id = $this->machineID
|
352 |
where device_id = $this->machineID
|
349 |
and attrib_id = $attrib_id
|
353 |
and attrib_id = $attrib_id
|
350 |
and removed_date is null");
|
354 |
and removed_date is null");
|
351 |
unset( $result ); # this will force the insert in the next block of code
|
355 |
unset( $result ); # this will force the insert in the next block of code
|
352 |
} # if ($result)
|
356 |
} # if ($result)
|
353 |
if ( ! isset( $result ) ) { # we have no valid entry for this attribute
|
357 |
if ( ! isset( $result ) ) { # we have no valid entry for this attribute
|
354 |
//$this->messages[] = "In checkAndUpdateAttribute, adding new record with insert into device_attrib(device_id,attrib_id,value,added_date) values ($this->machineID,$attrib_id,$value,$this->reportDateSQL)";
|
358 |
//$this->messages[] = "In checkAndUpdateAttribute, adding new record with insert into attrib_device(device_id,attrib_id,value,added_date) values ($this->machineID,$attrib_id,$value,$this->reportDateSQL)";
|
355 |
queryDatabaseExtended( "insert into device_attrib(device_id,attrib_id,value,added_date)
|
359 |
queryDatabaseExtended( "insert into attrib_device(device_id,attrib_id,value,added_date)
|
356 |
values ($this->machineID,$attrib_id,$value,'$this->reportDateSQL')");
|
360 |
values ($this->machineID,$attrib_id,$value,'$this->reportDateSQL')");
|
357 |
return true;
|
361 |
return true;
|
358 |
}
|
362 |
}
|
359 |
return false;
|
363 |
return false;
|
360 |
} // checkAndUpdateAttribute
|
364 |
} // checkAndUpdateAttribute
|
Line 374... |
Line 378... |
374 |
queryDatabaseExtended( "update device set serial = '$this->serialNumber' where device_id = $this->machineID" );
|
378 |
queryDatabaseExtended( "update device set serial = '$this->serialNumber' where device_id = $this->machineID" );
|
375 |
}
|
379 |
}
|
376 |
}
|
380 |
}
|
377 |
} // updateComputerMakeup
|
381 |
} // updateComputerMakeup
|
378 |
|
382 |
|
- |
|
383 |
/* several report entries are simply designed to add/update the attributes table (attrib_device), so we'll just go through them
|
- |
|
384 |
* one by one
|
- |
|
385 |
*/
|
- |
|
386 |
private function processAttributes() {
|
- |
|
387 |
foreach ( $this->report['attributes'] as $key => $value ) {
|
- |
|
388 |
$this->checkAndUpdateAttribute( $key, $value );
|
- |
|
389 |
}
|
- |
|
390 |
} // processAttributes
|
379 |
|
391 |
|
380 |
|
392 |
|
381 |
// This is kind of funky, because column = null does not work, it must be column is null, so we have to look for it.
|
393 |
// This is kind of funky, because column = null does not work, it must be column is null, so we have to look for it.
|
382 |
function makeSQLEquals ( $field, $value ) {
|
394 |
function makeSQLEquals ( $field, $value ) {
|
383 |
return "$field " . ( $value == 'null' ? 'is null' : '=' . $value );
|
395 |
return "$field " . ( $value == 'null' ? 'is null' : '=' . $value );
|