[-]
[+]
|
Changed |
_service:set_version:inventory-system.spec
|
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1499.tar.bz2/client/inventory-system.sh
^
|
@@ -33,6 +33,7 @@
virtwhat
hostname
ip
+rpm
"
# mail alerts / debug messages
@@ -250,6 +251,12 @@
get_system_default_interface_ip_from_int `get_system_default_interface`
}
+# get rpm package list
+function get_system_software {
+ PACKAGES=`${RPM} -qa --queryformat '%{name}-%{version}-%{release}.%{arch} '`
+ debug "SYSTEM-SOFTWARE: ${PACKAGES}"
+ echo ${PACKAGEs}
+}
# encode url parameters
rawurlencode() {
local string="${1}"
@@ -296,7 +303,8 @@
get_system_type \
get_system_kernelversion \
get_system_arch \
- get_system_os ; do
+ get_system_os \
+ get_system_software ; do
request="${request}${VAR}="`rawurlencode "\`${VAR}\`"`
request="${request}&"
done
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1499.tar.bz2/server/config.inc.php
^
|
@@ -1,8 +1,19 @@
<?php
-$config["isdf"]["postvars"] = array("get_system_uuid","get_system_serial","get_system_cpu","get_system_memory","get_system_manufacturer","get_system_productname","get_system_biosversion","get_system_net_info","get_system_default_ip","get_system_ipv4","get_system_ipv6","get_system_hostname","get_system_type","get_system_kernelversion","get_system_arch","get_system_os");
+$config["isdf"]["postvars"] = array("get_system_uuid","get_system_serial","get_system_cpu","get_system_memory","get_system_manufacturer","get_system_productname","get_system_biosversion","get_system_net_info","get_system_default_ip","get_system_ipv4","get_system_ipv6","get_system_hostname","get_system_type","get_system_kernelversion","get_system_arch","get_system_os","get_system_software");
$config["isdf"]["get_system_ipv4"]["action"] = "serialize";
$config["isdf"]["get_system_ipv6"]["action"] = "serialize";
+$config["isdf"]["get_system_software"]["action"] = "serialize";
+
+$config["isdf"}["db"]['phptype'] = "mysql";
+$config["isdf"}["db"]['protocol'] = "tcp";
+$config["isdf"}["db"]['hostspec'] = "";
+$config["isdf"}["db"]['database'] = "";
+$config["isdf"}["db"]['username'] = "";
+$config["isdf"}["db"]['password'] = "";
+$config["isdf"}["db"]['new_link'] = true;
+$config['mdb2']['options'] = array();
+
?>
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1499.tar.bz2/server/isdf.php
^
|
@@ -7,8 +7,12 @@
// $Rev$
*/
-define('MYNAME', "isdf");
+// define our name
+define('MYNAME', "isdf");
+// open syslog connection
openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
+
+// check for required extensions
if ( ! extension_loaded("mysql") ) {
if ( ! dl("mysql") ) {
syslog(LOG_ERR,"mysql extension not loaded!");
@@ -16,17 +20,118 @@
}
}
+// load additional files
define('BASE',dirname(__FILE__));
require_once("MDB2.php");
require_once(BASE . "/config.inc.php");
+// initialize variables
+$request_complete=1;
+$data=array();
+
+// check if all post fields are set and save them to data array
if ( isset($_POST) ) {
foreach ( $config["isdf"]["postvars"] as $POSTVAR ) {
if ( isset($_POST[$POSTVAR]) ) {
$value = urldecode($_POST[$POSTVAR]);
+ $data[$POSTVAR] = $value;
syslog(LOG_INFO, $POSTVAR . ": ". $value);
- }
+ } else {
+ $request_complete=0;
+ }
}
}
+// create database connection
+$dbh =& MDB2::singleton($config['isdf']['db'], $config['mdb2']['options'] );
+
+$uuidkey = $data['get_system_uuid'];
+if ( strlen($uuidkey) == 36 ) {
+ // check for existing uuid entry
+ $uuidchecksql = "SELECT id FROM inv_system WHERE system_uuid = '$uuidkey'";
+ $res = $dbh->query($uuidchecksql);
+ if (PEAR::isError($res)) {
+ syslog(LOG_ERROR, "MDB2: " . $res->getMessage());
+ } elseif ( $res->numRows() == 1 ) {
+ // uuid already exists, just update data for this host
+ $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
+ $systemid = $row['id'];
+
+ 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'";
+ $sysidkeyres = $dbh->query($sysidkeysql);
+
+ if (PEAR::isError($sysidkeyres)) {
+ syslog(LOG_ERROR, "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'";
+ $updres = $dbh->exec($updatesql);
+ if (PEAR::isError($updres) ){
+ syslog(LOG_ERROR,"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]')";
+ $insres = $dbh->exec($insertsql);
+ if (PEAR::isError($insres) ){
+ syslog(LOG_ERROR,"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());
+ }
+
+ }
+ } elseif ( $res->numRows() == 0 ) {
+ // uuid does not exist, insert uuid and data
+ $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());
+ } 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'";
+ $sysidkeyres = $dbh->query($sysidkeysql);
+ if (PEAR::isError($sysidkeyres)) {
+ syslog(LOG_ERROR, "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'";
+ $updres = $dbh->exec($updatesql);
+ if (PEAR::isError($updres) ){
+ syslog(LOG_ERROR,"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]')";
+ $insres = $dbh->exec($insertsql);
+ if (PEAR::isError($insres) ){
+ syslog(LOG_ERROR,"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());
+ }
+
+ }
+ }
+ } else {
+ // this should never happen, but in case log the numRows result
+ syslog(LOG_ERROR, "MDB2: uuid query resulted in unsupported result " . $res->numRows());
+ }
+} else {
+ syslog(LOG_ERR, "Invalid uuid found: " . $uuidkey);
+}
+// close database connection
+$dbh->disconnect();
+
+// close syslog connection
closelog();
?>
|