Thursday 25 October 2012

Finding CA eHealth Missing Elements

I had an issue lately that we were unable to identify elements in our ehealth that are still being polled but no longer are valid. ehealth doesn't flag in the database whether elements are missing or not and in some cases sub -elements can still be polling data even thought they are invalid. So you can have elements that still have data but are no longer found on the target devices.

For example if someone changes the volumes on a solaris box with a systemedge agent the old disk names are still discovered and polled (and if the snmp index is the same as  anew disk it will still have a value). Say we used to have a diskX with index 12 and now have diskY with index 12 you get two disk elements with the same metrics being read per poll but one is valid and one 'missing'.

I wrote this script this week to identify all the 'missing' elements in ehealth and export them to a single file. Then you can action investigating / cleaning them up with nhDeleteElement or whatever.

The script scans all the autodiscvoery log files looking for the 'missing elements' section and spits out the line containing the element name.

#!/bin/ksh
# /appl/ehealth/missingelements.ksh
# THIS SCRIPT WILL GENERATE A FILE CONTAINING ALL THE MISSING EHEALTH ELEMENTS FROM SCHEDULED AUTO DISCVOERY LOGS
host=`hostname`
# this is the final list of all missing files
masterlistfile="/var/tmp/ehealthreport/MissingElementList.$host"

#this is temp directory for working files
ehtemp="/appl/ehealth/tmp"
temp1="$ehtemp/missingelements1"
temp2="$ehtemp/missingelements2"
temp3="$ehtemp/missingelements3"

# configure this to directory where your ehealth logs are
logpath="/appl/ehealth/log"

# days of files to search.
goback=7

################# MAIN STARTS HERE #################
rm $masterlistfile
rm $temp1 $temp2 $temp3

files=`find $logpath/discoverScheduled* -mtime -$goback`

for file in $files; do
    grep "Missing Elements" $file
    if [ $? -eq 0 ] ; then
        echo $file
        missingstart=`grep -n "Missing Elements" $file | sed 's/:  Missing Elements//'`
        missingstart=$((missingstart + 1))
        echo "from $missingstart"
        tail +$missingstart $file > $ehtemp/missingelements1

        missingend=`grep -n "GROUP ASSIGNMENT DETAILS" $temp1 | sed 's/:GROUP ASSIGNMENT DETAILS//'`
        missingend=$((missingend -1))
        echo "to $missingend"

        head -$missingend $temp1 > $temp2
        grep \( $temp2 > $temp3

        cat $temp3 >> $masterlistfile

    else
         echo "$file has no missing elements!"
    fi

done

echo " MISSING ELEMENT REPORT WRITTEN TO: $masterlistfile"
#cat $masterlistfile

No comments:

Post a Comment