#!/bin/ksh
#
#
LOGS_DIR="/tmp"
#
function extract_text
{
# Starting string = ${START_STRING}
# Finishing string = ${FINISH_STRING}
# Name of File = ${1}
# Minimum number of lines = ${2}
ext_output_flag="OFF"
ext_lines_count=0
if [[ ! -e ${1} ]]; then return 1; fi
cat ${1} | while read ext_line
do
ext_string_found=`echo "${ext_line}" | grep -c "${START_STRING}"`
if [[ ext_string_found -gt 0 ]]
then
ext_output_flag="ON"
ext_lines_count=0
fi
if [[ "${ext_output_flag}" = "ON" ]]
then
echo "${ext_line}"
((ext_lines_count=ext_lines_count + 1))
ext_string_found=`echo "${ext_line}" | grep -c "${FINISH_STRING}"`
if [[ ext_string_found -gt 0 ]]
then
if [[ ext_lines_count -gt ${2} ]]; then ext_output_flag="OFF"; fi
fi
fi
done
}
#
#
HARDWARE_TYPE=`uname -i | awk -F, '{print $2}'`
ENVMON_FILE="${LOGS_DIR}/unixmon_envmon.$$"
PRTDIAG_FILE="${LOGS_DIR}/unixmon_prtdiag.$$"
echo "Environmental Monitoring on: $(date)" > ${ENVMON_FILE}
/usr/platform/`uname -i`/sbin/prtdiag -v > ${PRTDIAG_FILE}
START_STRING="== Environmental Status =="
FINISH_STRING="== HW Revisions =="
grep_start=`grep -n "${START_STRING}" ${PRTDIAG_FILE} | cut -d':' -f1`
grep_end=`grep -n "${FINISH_STRING}" ${PRTDIAG_FILE} | cut -d':' -f1`
head -$((grep_end-1)) ${PRTDIAG_FILE} | tail -$((grep_end-grep_start)) >> ${ENVMON_FILE}
rm ${PRTDIAG_FILE}
high_temp_threshold=40 # would normally get this from "Threshold values" file
current_temperature=20
count=0
number=0
if [[ "${HARDWARE_TYPE}" = "Ultra-250" ]]
then
START_STRING="System Temperatures"
FINISH_STRING="\============"
extract_text ${ENVMON_FILE} 3 > ${LOGS_DIR}/unixmon_temperature.$$
cat ${LOGS_DIR}/unixmon_temperature.$$ | sed "1,2 d" | while read line
do
field1=`echo "${line}" | awk '{print $1}' | cut -c 1-3`
field2=`echo "${line}" | awk '{print $2}'`
if [[ "${field1}" != "CPU" && -n ${field2} ]]
then
((number=number + field2))
((count=count + 1))
fi
done
fi
if [[ "${HARDWARE_TYPE}" = "Netra-T12" ]]
then
START_STRING="Temperature sensors:"
FINISH_STRING="\------------"
extract_text ${ENVMON_FILE} 5 > ${LOGS_DIR}/unixmon_temperature.$$
cat ${LOGS_DIR}/unixmon_temperature.$$ | grep -i ambient | while read line
do
field3=`echo "${line}" | awk '{print $3}' | sed "s/C//"`
if [[ -n ${field3} ]]
then
((number=number + field3))
((count=count + 1))
fi
done
fi
if [[ number -gt 0 && ${number} = [0-9]* && count -gt 0 ]]
then
((current_temperature=number / count))
fi
rm ${LOGS_DIR}/unixmon_temperature.$$
echo "current_temperature = ${current_temperature} (${number} / ${count})"
internal_fan_status=0
count=0
if [[ "${HARDWARE_TYPE}" = "Ultra-250" ]]
then
START_STRING="Fan Bank"
FINISH_STRING="\============"
extract_text ${ENVMON_FILE} 3 > ${LOGS_DIR}/unixmon_fanstatus.$$
cat ${LOGS_DIR}/unixmon_fanstatus.$$ | sed "1,6 d" | while read line
do
echo "${line}"
field3=`echo "${line}" | awk '{print $3}' | tr '[a-z]' '[A-Z]'`
if [[ -n ${field3} ]]
then
if [[ "$(echo ${field3} | cut -c 1-2)" != "OK" ]]
then
((count=count + 1))
fi
fi
done
fi
if [[ "${HARDWARE_TYPE}" = "Netra-T12" ]]
then
START_STRING="Board Status:"
FINISH_STRING="\------------"
extract_text ${ENVMON_FILE} 5 > ${LOGS_DIR}/unixmon_fanstatus.$$
cat ${LOGS_DIR}/unixmon_fanstatus.$$ | grep -i fan | while read line
do
echo "${line}"
field2=`echo "${line}" | awk '{print $2}' | tr '[a-z]' '[A-Z]'`
if [[ -n ${field2} ]]
then
if [[ "$(echo ${field2} | cut -c 1-2)" != "OK" ]]
then
((count=count + 1))
fi
fi
done
fi
internal_fan_status=${count}
rm ${LOGS_DIR}/unixmon_fanstatus.$$
echo "internal_fan_status = ${internal_fan_status}"
power_supply_status=0
count=0
if [[ "${HARDWARE_TYPE}" = "Ultra-250" ]]
then
START_STRING="Power Supplies"
FINISH_STRING="\============"
extract_text ${ENVMON_FILE} 3 > ${LOGS_DIR}/unixmon_powerstatus.$$
cat ${LOGS_DIR}/unixmon_powerstatus.$$ | sed "1,5 d" | while read line
do
echo "${line}"
field2=`echo "${line}" | awk '{print $2}' | tr '[a-z]' '[A-Z]'`
if [[ -n ${field2} ]]
then
if [[ "$(echo ${field2} | cut -c 1-2)" != "OK" ]]
then
((count=count + 1))
fi
fi
done
fi
if [[ "${HARDWARE_TYPE}" = "Netra-T12" ]]
then
START_STRING="Voltage sensors:"
FINISH_STRING="\------------"
extract_text ${ENVMON_FILE} 5 > ${LOGS_DIR}/unixmon_powerstatus.$$
cat ${LOGS_DIR}/unixmon_powerstatus.$$ | grep -i ps | while read line
do
echo "${line}"
field3=`echo "${line}" | awk '{print $NF}' | tr '[a-z]' '[A-Z]'`
if [[ -n ${field3} ]]
then
if [[ "$(echo ${field3} | cut -c 1-2)" != "OK" ]]
then
((count=count + 1))
fi
fi
done
fi
power_supply_status=${count}
rm ${LOGS_DIR}/unixmon_powerstatus.$$
echo "power_supply_status = ${power_supply_status}"
mv ${ENVMON_FILE} ${LOGS_DIR}/unixmon_envmon.history
exit 0