[-]
[+]
|
Changed |
_service:set_version:ix-inventory-system.spec
|
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1694.tar.bz2/client/inventory-system.sh
^
|
@@ -1,8 +1,8 @@
#!/bin/bash
# Inventory System
# Author: Carsten Schoene
-# $LastChangedDate: 2012-07-22 16:26:37 +0200 (Sun, 22 Jul 2012) $
-# $Rev: 1627 $
+# $LastChangedDate: 2012-08-12 12:42:39 +0200 (Sun, 12 Aug 2012) $
+# $Rev: 1694 $
#
# Default options (can be changed by inventory-system.conf)
DEBUG="yes"
@@ -38,6 +38,7 @@
date
modprobe
ipmitool
+getopt
"
# clean old logfile
@@ -79,6 +80,87 @@
exit 1
fi
+# script usage
+function usage {
+ echo "Usage: $0 [--help|--uuid|--systemtype|--serial|--cpu|--mem|--product|--arch|--os|--kernel|--mgmtmac|--mgmtip]"
+ echo -e "\t--help\t\tShows this help"
+ echo -e "\t--uuid\t\tUUID of this system"
+ echo -e "\t--systemtype\tSystem image type"
+ echo -e "\t--serial\tSystem serial number (Service Tag)"
+ echo -e "\t--cpu\t\tCPU type"
+ echo -e "\t--mem\t\tAmount of memory installed in MB"
+ echo -e "\t--product\tSystem model"
+ echo -e "\t--arch\t\tSystem architecture"
+ echo -e "\t--os\t\tOS version installed"
+ echo -e "\t--kernel\tRunning kernel version"
+ echo -e "\t--mgmtmac\tIPMI management MAC address"
+ echo -e "\t--mgmtip\tIPMI management IP address"
+ exit
+}
+
+RUN_FUNCTIONS=""
+args=`${GETOPT} -a -o h -l help,uuid,systemtype,serial,cpu,mem,product,arch,os,kernel,mgmtmac,mgmtip -- "$@"`
+if [ $? != 0 ] ; then
+ usage
+fi
+
+eval set -- "$args"
+for opt ; do
+ case "$opt" in
+ -h|--help)
+ usage
+ ;;
+ -u|--uuid)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_uuid"
+ shift
+ ;;
+ -t|--systemtype)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_type"
+ shift
+ ;;
+ -s|--serial)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_serial"
+ shift
+ ;;
+ -c|--cpu)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_cpu"
+ shift
+ ;;
+ -m|--mem)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_memory"
+ shift
+ ;;
+ -p|--product)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_productname"
+ shift
+ ;;
+ -a|--arch)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_arch"
+ shift
+ ;;
+ -o|--os)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_os"
+ shift
+ ;;
+ -k|--kernel)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_kernelversion"
+ shift
+ ;;
+ -g|--mgmtmac)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_mgmt_mac"
+ shift
+ ;;
+ -i|--mgmtip)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_mgmt_ip"
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ esac
+done
+
# get unique system uuid
function get_system_uuid {
# newer systems have uuid integrated
@@ -394,13 +476,20 @@
}
###### now output system data ######
-if [ -n "`echo ${TARGETURL} | grep ^https`" ] ; then
- ${CURL} -s -k -d "`build_request`" ${TARGETURL} >/dev/null
+if [ -n "${RUN_FUNCTIONS}" ] ; then
+ for FUNC in ${RUN_FUNCTIONS} ; do
+ ${FUNC}
+ done
+ exit
else
- ${CURL} -s -d "`build_request`" ${TARGETURL} >/dev/null
-fi
-if [ $? != 0 ] ; then
- debug "Data upload failed!"
+ if [ -n "`echo ${TARGETURL} | grep ^https`" ] ; then
+ ${CURL} -s -k -d "`build_request`" ${TARGETURL} >/dev/null
+ else
+ ${CURL} -s -d "`build_request`" ${TARGETURL} >/dev/null
+ fi
+ if [ $? != 0 ] ; then
+ debug "Data upload failed!"
+ fi
+ mailalerts
fi
-mailalerts
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1694.tar.bz2/server/config-custom.inc.php
^
|
@@ -2,4 +2,12 @@
$config["isdf"]["custom_postvars"] = array();
+$config["isdf"]["dhcp"]["system"]["net4"] = "10.10.20.0/22";
+$config["isdf"]["dhcp"]["systemmgmt"]["net4"] = "10.10.24.0/22";
+$config["isdf"]["dhcp"]["systempxe"]["net4"] = "10.10.28.0/22";
+
+$config["isdf"]["dhcp"]["system"]["net6"] = "";
+$config["isdf"]["dhcp"]["systemmgmt"]["net6"] = "";
+$config["isdf"]["dhcp"]["systempxe"]["net6"] = "";
+
?>
|
[-]
[+]
|
Added |
_service:recompress:tar_scm:inventory-system-0.0.rev1694.tar.bz2/server/dhcpconf.class.php
^
|
@@ -0,0 +1,223 @@
+<?php
+// $LastChangedDate: 2012-08-11 16:27:06 +0200 (Sat, 11 Aug 2012) $
+// $Rev: 1692 $
+
+class dhcpconf {
+ var $dhcpdHosts;
+ var $hosts;
+ var $iterator;
+
+ public function __construct($filename){
+ $this->iterator = -1;
+ $this->dhcpdHosts = $filename;
+ }
+
+ public function addHost($name, $mac, $ip){
+ if(! $fh = fopen($this->dhcpdHosts, 'a')){
+ print("ERROR: ");
+ print(" Unable to open $this->dhcpdHosts for writing!\n");
+ exit;
+ }
+
+ $line = "host $name {\n\thardware ethernet $mac;\n\tfixed-address $ip;\n}\n";
+ fwrite($fh, $line);
+ fclose($fh);
+ }
+
+ public function removeHost($mac){
+ if(! $fh = fopen($this->dhcpdHosts, 'r')){
+ print("ERROR: ");
+ print(" Unable to open '$this->dhcpdHosts' for reading/writing!\n");
+ exit;
+ }
+
+ $found = false;
+
+ while(!feof($fh))
+ $file[] = fgets($fh, 1024);
+
+ for($i = 0; $i < sizeof($file); $i++){
+ if(isset($j) && $j < sizeof($file)){
+ $file[$i] = $file[$j];
+ $j++;
+ continue;
+ }
+ if(isset( $j ) && ( $j >= sizeof($file)) ){
+ unset($file[$i]);
+ $j++;
+ continue;
+ }
+
+ if(preg_match("/\#? host\s+ (?i)[a-z -]+ \s* \{/x", $file[$i])){
+ if(preg_match("/\#? \s+hardware\sethernet\s" . $mac . "\;/x", $file[$i+1])){
+ $found = true;
+ $j = $i + 4;
+ $file[$i] = $file[$j];
+ $j++;
+ } // End of Mac match
+ } // End of host entry
+ } // End of for loop
+
+
+ if($found){
+ fclose($fh);
+ $fh = fopen($this->dhcpdHosts, 'w');
+ for($i = 0; $i < sizeof($file); $i++){
+ if ( isset($file[$i])) {
+ fwrite($fh, $file[$i]);
+ }
+ } // End of writing
+ }
+
+ fclose($fh);
+ return $found;
+ }
+
+ public function readHosts(){
+
+ if(! $fh = fopen($this->dhcpdHosts, 'r')){
+ print("ERROR: ");
+ print(" Unable to open '$this->dhcpdHosts' for reading!\n");
+ exit;
+ }
+
+ while(!feof($fh)){
+ $line = fgets($fh, 1024);
+
+ if(preg_match("/^(\}|\#\})/", $line))
+ {
+ $this->hosts[] = $this->parseHost($entry);
+ unset($entry);
+ continue;
+ }
+
+ $entry[] = $line;
+ }
+
+ fclose($fh);
+ return;
+ }
+
+ private function parseHost($entry){
+ list(,$name) = explode(" ", $entry[0]);
+ list(,,$mac) = explode(" ", $entry[1]);
+
+ if(preg_match("/^(\#)/", $entry[0]))
+ $status = "disabled";
+ else
+ $status = "enabled";
+
+ return array("hostname" => $name, "mac" => substr($mac, 0, -2), "status" => $status);
+ }
+
+ public function nextHost(){
+ if($this->iterator >= sizeof($this->hosts) )
+ return false;
+ else
+ return $this->hosts[++$this->iterator];
+ }
+
+ public function rewindHosts(){
+ $this->iterator = -1;
+ }
+
+ public function disableHost($mac){
+ if(! $fh = fopen($this->dhcpdHosts, 'r')){
+ print("ERROR: ");
+ print(" Unable to open '$this->dhcpdHosts' for reading/writing!\n");
+ exit;
+ }
+
+ $found = false;
+
+ while(!feof($fh))
+ $file[] = fgets($fh, 1024);
+
+ for($i = 0; $i < sizeof($file); $i++){
+ if(preg_match("/^host\s+(?i)[a-z -]+\s*\{/", $file[$i])){
+ if(preg_match("/\s+hardware\sethernet\s" . $mac . "\;/", $file[$i+1])){
+ $found = true;
+ for($j = 0; $j < 4; $j++)
+ $file[$i + $j] = "#" . $file[$i + $j];
+ } // End of Mac match
+ } // End of host entry line
+ } // End of for loop
+
+
+ if($found){
+ fclose($fh);
+ $fh = fopen($this->dhcpdHosts, 'w');
+ for($i = 0; $i < sizeof($file); $i++){
+ fwrite($fh, $file[$i]);
+ } // End of writing
+ }
+
+ fclose($fh);
+ return $found;
+ }
+
+ /**
+ * @return bool
+ * @param string $mac
+ * @desc Enables host entry by uncommenting it in the host file if the mac address exists and is commented.
+ */
+ public function enableHost($mac){
+ if(! $fh = fopen($this->dhcpdHosts, 'r')){
+ print("ERROR: ");
+ print(" Unable to open '$this->dhcpdHosts' for reading/writing!\n");
+ exit;
+ }
+
+ $found = false;
+
+ while(!feof($fh))
+ $file[] = fgets($fh, 1024);
+
+ for($i = 0; $i < sizeof($file); $i++){
+ if(preg_match("/^\#host\s+(?i)[a-z -]+\s*\{/", $file[$i])){
+ if(preg_match("/\#\s+hardware\sethernet\s" . $mac . "\;/", $file[$i+1])){
+ $found = true;
+ for($j = 0; $j < 4; $j++)
+ $file[$i + $j] = substr($file[$i + $j], strpos($file[$i+$j], "#") + 1);
+ } // End of Mac match
+ } // End of host entry line
+ } // End of for loop
+
+
+ if($found){
+ fclose($fh);
+ $fh = fopen($this->dhcpdHosts, 'w');
+ for($i = 0; $i < sizeof($file); $i++){
+ fwrite($fh, $file[$i]);
+ } // End of writing
+ }
+
+ fclose($fh);
+ return $found;
+ }
+
+ public function hostExists($hostname, $mac){
+ $this->readHosts();
+ $match = false;
+ if ( isset($this->hosts) ) {
+ foreach($this->hosts as $host){
+ if(strtoupper($hostname) == strtoupper($host["hostname"])){
+ $match = true;
+ }
+ elseif(strtoupper($mac) == strtoupper($host["mac"])){
+ $match = true;
+ }
+
+ if($match)
+ break;
+ }
+
+ return $match;
+ } else {
+ return false;
+ }
+ }
+
+}
+
+?>
|
[-]
[+]
|
Changed |
_service:recompress:tar_scm:inventory-system-0.0.rev1694.tar.bz2/server/isdf.php
^
|
@@ -3,8 +3,8 @@
// isdf - inventory system deployment feed
// Author: Carsten Schoene
//
-// $LastChangedDate: 2012-07-20 21:09:25 +0200 (Fri, 20 Jul 2012) $
-// $Rev: 1619 $
+// $LastChangedDate: 2012-08-11 16:22:17 +0200 (Sat, 11 Aug 2012) $
+// $Rev: 1690 $
*/
// define our name
@@ -31,6 +31,25 @@
$request_complete=1;
$data=array();
+// function valid_uuid
+function valid_uuid ( $uuid ) {
+ $uuid = trim($uuid);
+ $regex = '/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/';
+ if ( strlen($uuid) == 36 && preg_match($regex,$uuid) ) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+function run_insert_tasks($systemid, $key, $value) {
+
+}
+
+function run_update_tasks($systemid, $key, $value) {
+
+}
+
// check if all post fields are set and save them to data array
if ( isset($_POST) ) {
foreach ( $config["isdf"]["postvars"] as $POSTVAR ) {
@@ -63,7 +82,9 @@
$dbh =& MDB2::singleton($config['isdf']['db'], $config['mdb2']['options'] );
$uuidkey = $data['get_system_uuid'];
-if ( strlen($uuidkey) == 36 ) {
+
+
+if ( valid_uuid($uuidkey) ) {
// check for existing uuid entry
$uuidchecksql = "SELECT id FROM inv_system WHERE system_uuid = '$uuidkey'";
$res = $dbh->query($uuidchecksql);
@@ -87,6 +108,8 @@
$updres = $dbh->exec($updatesql);
if (PEAR::isError($updres) ){
syslog(LOG_ERR,"MDB2: UPDATE of inv_system_properties failed with " . $updres->getMessage());
+ } else {
+ run_update_tasks($systemid, $key, $value);
}
} elseif ( $sysidkeyres->numRows() == 0 ) {
@@ -95,8 +118,9 @@
$insres = $dbh->exec($insertsql);
if (PEAR::isError($insres) ){
syslog(LOG_ERR,"MDB2: INSERT into inv_system_properties failed with " . $insres->getMessage());
+ } else {
+ run_insert_tasks($systemid, $key, $value);
}
-
} else {
// this should never happen, but in case log the numRows result
syslog(LOG_ERR,"MDB2: systemid/key pair query resulted in unsupported result " . $sysidkeyres->numRows());
@@ -125,6 +149,8 @@
$updres = $dbh->exec($updatesql);
if (PEAR::isError($updres) ){
syslog(LOG_ERR,"MDB2: UPDATE of inv_system_properties failed with " . $updres->getMessage());
+ } else {
+ run_update_tasks($systemid, $key, $value);
}
} elseif ( $sysidkeyres->numRows() == 0 ) {
// if systemid / key pair does not exist, create it - happens on feature update
@@ -132,6 +158,8 @@
$insres = $dbh->exec($insertsql);
if (PEAR::isError($insres) ){
syslog(LOG_ERR,"MDB2: INSERT into inv_system_properties failed with " . $insres->getMessage());
+ } else {
+ run_insert_tasks($systemid, $key, $value);
}
} else {
// this should never happen, but in case log the numRows result
|