@@ -41,6 +41,13 @@
}
}
}
+
+// last check before connecting to database
+if (!isset($data['get_system_uuid']) ) {
+ syslog(LOG_ERR,"DATA: get_system_uuid not found");
+ die();
+}
+
// create database connection
$dbh =& MDB2::singleton($config['isdf']['db'], $config['mdb2']['options'] );
@@ -50,7 +57,7 @@
$uuidchecksql = "SELECT id FROM inv_system WHERE system_uuid = '$uuidkey'";
$res = $dbh->query($uuidchecksql);
if (PEAR::isError($res)) {
- syslog(LOG_ERROR, "MDB2: " . $res->getMessage());
+ syslog(LOG_ERR, "MDB2: " . $res->getMessage());
} elseif ( $res->numRows() == 1 ) {
// uuid already exists, just update data for this host
$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
@@ -58,30 +65,30 @@
foreach ( $data as $key ) {
// check if systemid/key pair exists
- $sysidkeysql = "SELECT inv_system_id,key FROM inv_system_properties WHERE inv_system_id='$systemid' AND key='$key'";
+ $sysidkeysql = "SELECT inv_system_id, datakey FROM inv_system_properties WHERE inv_system_id='$systemid' AND datakey='$key'";
$sysidkeyres = $dbh->query($sysidkeysql);
if (PEAR::isError($sysidkeyres)) {
- syslog(LOG_ERROR, "MDB2: " . $sysidkeyres->getMessage());
+ syslog(LOG_ERR, "MDB2: " . $sysidkeyres->getMessage());
} elseif ( $sysidkeyres->numRows() == 1 ) {
// define update query
- $updatesql = "UPDATE inv_system_properties SET value='$data[$key]', WHERE inv_system_id='$systemid' AND key='$key'";
+ $updatesql = "UPDATE inv_system_properties SET value='$data[$key]', WHERE inv_system_id='$systemid' AND datakey='$key'";
$updres = $dbh->exec($updatesql);
if (PEAR::isError($updres) ){
- syslog(LOG_ERROR,"MDB2: UPDATE of inv_system_properties failed with " . $updres->getMessage());
+ syslog(LOG_ERR,"MDB2: UPDATE of inv_system_properties failed with " . $updres->getMessage());
}
} elseif ( $sysidkeyres->numRows() == 0 ) {
// if systemid / key pair does not exist, create it - happens on feature update
- $insertsql = "INSERT INTO inv_system_properties (inv_system_id,key,value) VALUES ('$systemid','$key','$data[$key]')";
+ $insertsql = "INSERT INTO inv_system_properties (inv_system_id,datakey,value) VALUES ('$systemid','$key','$data[$key]')";
$insres = $dbh->exec($insertsql);
if (PEAR::isError($insres) ){
- syslog(LOG_ERROR,"MDB2: INSERT into inv_system_properties failed with " . $insres->getMessage());
+ syslog(LOG_ERR,"MDB2: INSERT into inv_system_properties failed with " . $insres->getMessage());
}
} else {
// this should never happen, but in case log the numRows result
- syslog(LOG_ERROR,"MDB2: systemid/key pair query resulted in unsupported result " . $sysidkeyres->numRows());
+ syslog(LOG_ERR,"MDB2: systemid/key pair query resulted in unsupported result " . $sysidkeyres->numRows());
}
}
@@ -90,41 +97,41 @@
$newinssql = "INSERT INTO inv_system (system_uuid) VALUES ('$uuidkey')";
$newinsres = $dbh->exec($newinssql);
if (PEAR::isError($newinsres) ) {
- syslog(LOG_ERROR,"MDB2: INSERT into inv_system failed with " . $newinsres->getMessage());
+ syslog(LOG_ERR,"MDB2: INSERT into inv_system failed with " . $newinsres->getMessage());
} else {
$systemid = $dbh->lastInsertId('inv_system', 'id');
syslog(LOG_INFO, "MDB2: INSERT into inv_system successfull with id " . $systemid);
foreach ( $data as $key ) {
// check if systemid/key pair exists
- $sysidkeysql = "SELECT inv_system_id,key FROM inv_system_properties WHERE inv_system_id='$systemid' AND key='$key'";
+ $sysidkeysql = "SELECT inv_system_id, datakey FROM inv_system_properties WHERE inv_system_id='$systemid' AND datakey='$key'";
$sysidkeyres = $dbh->query($sysidkeysql);
if (PEAR::isError($sysidkeyres)) {
- syslog(LOG_ERROR, "MDB2: " . $sysidkeyres->getMessage());
+ syslog(LOG_ERR, "MDB2: " . $sysidkeyres->getMessage());
} elseif ( $sysidkeyres->numRows() == 1 ) {
// define update query
- $updatesql = "UPDATE inv_system_properties SET value='$data[$key]', WHERE inv_system_id='$systemid' AND key='$key'";
+ $updatesql = "UPDATE inv_system_properties SET value='$data[$key]', WHERE inv_system_id='$systemid' AND datakey='$key'";
$updres = $dbh->exec($updatesql);
if (PEAR::isError($updres) ){
- syslog(LOG_ERROR,"MDB2: UPDATE of inv_system_properties failed with " . $updres->getMessage());
+ syslog(LOG_ERR,"MDB2: UPDATE of inv_system_properties failed with " . $updres->getMessage());
}
} elseif ( $sysidkeyres->numRows() == 0 ) {
// if systemid / key pair does not exist, create it - happens on feature update
- $insertsql = "INSERT INTO inv_system_properties (inv_system_id,key,value) VALUES ('$systemid','$key','$data[$key]')";
+ $insertsql = "INSERT INTO inv_system_properties (inv_system_id,datakey,value) VALUES ('$systemid','$key','$data[$key]')";
$insres = $dbh->exec($insertsql);
if (PEAR::isError($insres) ){
- syslog(LOG_ERROR,"MDB2: INSERT into inv_system_properties failed with " . $insres->getMessage());
+ syslog(LOG_ERR,"MDB2: INSERT into inv_system_properties failed with " . $insres->getMessage());
}
} else {
// this should never happen, but in case log the numRows result
- syslog(LOG_ERROR,"MDB2: systemid/key pair query resulted in unsupported result " . $sysidkeyres->numRows());
+ syslog(LOG_ERR,"MDB2: systemid/key pair query resulted in unsupported result " . $sysidkeyres->numRows());
}
}
}
} else {
// this should never happen, but in case log the numRows result
- syslog(LOG_ERROR, "MDB2: uuid query resulted in unsupported result " . $res->numRows());
+ syslog(LOG_ERR, "MDB2: uuid query resulted in unsupported result " . $res->numRows());
}
} else {
syslog(LOG_ERR, "Invalid uuid found: " . $uuidkey);
|