@@ -1,8 +1,8 @@
#!/bin/bash
# Inventory System
# Author: Carsten Schoene
-# $LastChangedDate: 2012-09-09 18:53:04 +0200 (Sun, 09 Sep 2012) $
-# $Rev: 1753 $
+# $LastChangedDate: 2012-09-10 17:01:13 +0200 (Mon, 10 Sep 2012) $
+# $Rev: 1757 $
#
# Default options (can be changed by inventory-system.conf)
DEBUG="yes"
@@ -35,12 +35,14 @@
ip
rpm
ls
+df
date
modprobe
ipmitool
getopt
readlink
fdisk
+dmsetup
"
# clean old logfile
@@ -84,10 +86,11 @@
# script usage
function usage {
- echo "Usage: $0 [--help|--uuid|--disk|--systemtype|--serial|--cpu|--mem|--product|--arch|--os|--kernel|--mgmtmac|--mgmtip]"
+ echo "Usage: $0 [--help|--uuid|--disk|--disks|--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--disk\t\tRoot disk size of this system"
+ echo -e "\t--disks\t\tAll disk devices with size"
echo -e "\t--systemtype\tSystem image type"
echo -e "\t--serial\tSystem serial number (Service Tag)"
echo -e "\t--cpu\t\tCPU type"
@@ -118,7 +121,11 @@
shift
;;
-d|--disk)
- RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_disk_size_root"
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_disk_size_bootdev"
+ shift
+ ;;
+ --disks)
+ RUN_FUNCTIONS="${RUN_FUNCTIONS} get_system_disk_sizes"
shift
;;
-t|--systemtype)
@@ -184,28 +191,6 @@
echo ${UUID}
}
-# get the disk size of boot device
-function get_system_disk_size_bootdev {
- ROOTDEV=`${READLINK} -f /dev/root`
- # HP
- HP_ROOTDISK=`echo ${ROOTDEV} | ${GREP} "/dev/cciss" | ${SED} -r 's@(/dev/cciss/c[0-9]d[0-9]).*@\1@'`
- if [ -z "${HP_ROOTDISK}" ] ; then
- # Software Raid
- MD_ROOTDISK=`echo ${ROOTDEV} | ${GREP} "/dev/md" | ${SED} -r 's@(/dev/md[0-9]).*@\1@'`
- RD=${MD_ROOTDISK}
- elif [ -z "${MD_ROOTDISK}" ] ; then
- # normale block devices
- BL_ROOTDISK=`echo ${ROOTDEV} | ${SED} -r 's@(/dev/x?[hsv]d[a-z]).*@\1@'`
- RD=${BL_ROOTDISK}
- else
- RD=${HP_ROOTDISK}
- fi
- SIZE=`LANG=C ${FDISK} -l ${RD} | ${GREP} "^Disk /" | ${AWK} '{print $(NF-1)/1024 }'`
- debug "SYSTEM-ROOT-DEV: ${RD}"
- debug "SYSTEM-ROOTDEV-SIZE: ${SIZE}"
- echo ${SIZE}
-}
-
# read serialnumber / service tag with dmidecode
function get_system_serial {
SYSSERIAL=`${DMIDECODE} -s system-serial-number`
@@ -273,6 +258,90 @@
echo ${INSTMEM}
}
+# get the disk size of boot device
+function get_system_disk_size_bootdev {
+ case `get_system_type` in
+ openvz)
+ SIZE=`LANG=C ${DF} / | ${GREP} -v ^Filesystem| ${AWK} '{print $2 / 1024}'`
+ debug "SYSTEM-ROOTDEV-SIZE: ${SIZE}"
+ echo ${SIZE}
+ ;;
+ kvm)
+ ROOTDEV=`${READLINK} -f /dev/root`
+ if [ "${ROOTDEV}" == "/dev/root" ] ; then
+ # on kvm /dev/root is not always a symlink - ugly hack
+ MAJOR=`${DMSETUP} deps /dev/root | ${AWK} -F": " '{print $2}' | ${AWK} -F, '{print $1}' | ${SED} -e 's@(@@'`
+ DEV=`${LS} -al /dev/ | ${GREP} -E '(disk\s*${MAJOR},\s*0)' | ${AWK} '{print $NF}' | ${HEAD} -n1`
+ if [ -b /dev/${DEV} ] ; then
+ RD=/dev/${DEV}
+ else
+ # fallback to partition
+ RD=/dev/root
+ fi
+ else
+ RD=`echo ${ROOTDEV} | ${SED} -r 's@(/dev/x?[hsv]d[a-z]).*@\1@'`
+ fi
+ # / 1000 nicht / 1024 bei physikalischen Festplatten
+ SIZE=`LANG=C ${FDISK} -l ${RD} 2>/dev/null | ${GREP} "^Disk /" | ${AWK} '{print $(NF-1)/1000/1000 }'`
+ debug "SYSTEM-ROOT-DEV: ${RD}"
+ debug "SYSTEM-ROOTDEV-SIZE: ${SIZE}"
+ echo ${SIZE}
+ ;;
+ *)
+ ROOTDEV=`${READLINK} -f /dev/root`
+ # HP
+ HP_ROOTDISK=`echo ${ROOTDEV} | ${GREP} "/dev/cciss" | ${SED} -r 's@(/dev/cciss/c[0-9]d[0-9]).*@\1@'`
+ # linux software raid
+ MD_ROOTDISK=`echo ${ROOTDEV} | ${GREP} "/dev/md" | ${SED} -r 's@(/dev/md[0-9]).*@\1@'`
+ # linux lvm
+ LV_ROOTDISK=`echo ${ROOTDEV} | ${GREP} "/dev/dm-" | ${SED} -r 's@(/dev/dm-[0-9]).*@\1@'`
+ # block device
+ BL_ROOTDISK=`echo ${ROOTDEV} | ${SED} -r 's@(/dev/x?[hsv]d[a-z]).*@\1@'`
+ if [ -n "${HP_ROOTDISK}" ] ; then
+ # hp Raid
+ RD=${HD_ROOTDISK}
+ elif [ -n "${MD_ROOTDISK}" ] ; then
+ # linux software raid
+ RD=${MD_ROOTDISK}
+ elif [ -n "${LV_ROOTDISK}" ] ; then
+ # linux lvm
+ # on HP
+ HP_RD=`${LS} -1A /sys/block/${LV_ROOTDISK}/slaves/ 2>/dev/null | ${GREP} "/dev/cciss" | ${SED} -r 's@(/dev/cciss/c[0-9]d[0-9]).*@\1@'`
+ # on linux softraid
+ MD_RD=`${LS} -1A /sys/block/${LV_ROOTDISK}/slaves/ 2>/dev/null | ${GREP} "/dev/md" | ${SED} -r 's@(/dev/md[0-9]).*@\1@'`
+ # on block device
+ B_RD=`${LS} -1A /sys/block/${LV_ROOTDISK}/slaves/ 2>/dev/null | ${SED} -r 's@(/dev/x?[hsv]d[a-z]).*@\1@'`
+
+ if [ -n "${HP_RD}" ] ; then
+ # hp raid
+ RD=${HP_RD}
+ elif [ -n "${MD_RD}" ] ; then
+ # linux software raid
+ RD=${MD_RD}
+ else
+ # block device
+ RD=${B_RD}
+ fi
+ else
+ # linux block device
+ RD=${BL_ROOTDISK}
+ fi
+ # / 1000 nicht / 1024 bei physikalischen Festplatten
+ SIZE=`LANG=C ${FDISK} -l ${RD} 2>/dev/null | ${GREP} "^Disk /" | ${AWK} '{print $(NF-1)/1000/1000 }'`
+ debug "SYSTEM-ROOT-DEV: ${RD}"
+ debug "SYSTEM-ROOTDEV-SIZE: ${SIZE}"
+ echo ${SIZE}
+ ;;
+ esac
+}
+
+# get all (v)disks with sizes
+function get_system_disk_sizes {
+ DEV_SIZES=`LANG=C ${FDISK} -l 2>/dev/null | ${GREP} "^Disk /" | ${AWK} '{print $2","int($(NF-1)/1000/1000)}' | ${SED} -e 's@:,@,@' | ${GREP} -E '(/dev/x?[hsv]d[a-z],[0-9]{1,9})'`
+ debug "SYSTEM-DEVS-SIZES: ${DEV_SIZES}"
+ echo ${DEV_SIZES}
+}
+
# get product name
function get_system_productname {
PRODNAME=`${DMIDECODE} -s system-product-name`
|
@@ -1,6 +1,6 @@
<?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_mgmt_mac","get_system_mgmt_ip","get_system_type","get_system_kernelversion","get_system_arch","get_system_os","get_system_software","get_system_date","get_system_disk_size_bootdev");
+$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_mgmt_mac","get_system_mgmt_ip","get_system_type","get_system_kernelversion","get_system_arch","get_system_os","get_system_software","get_system_date","get_system_disk_size_bootdev","get_system_disk_sizes");
$config["isdf"]["dhcp"]["macblacklist"] = array("00:00:00:00:00:00","ff:ff:ff:ff:ff:ff");
?>
|