2 ################################################################################
5 # Description: Checks the log files for errors and notifies the appropriate
7 # Author: zran@salira.com - modified by Andrew@DeFaria.com
8 # Created: Fri Jun 27 12:42:28 PDT 2003
12 # (c) Copyright 2001-2003, Salira Optical Network Systems, all rights reserved.
14 ################################################################################
15 # Set me to command name
18 # Source /etc/site_parms
19 if [ -f /etc/site_parms ]; then
22 echo "$me: WARNING: /etc/site_parms does not exist!"
26 adm_base="$SITE_TOOLS_PATH/adm"
29 adm_fpath=${adm_fpath:-$adm_base/functions}
34 owner_list="$SITE_TOOLS_PATH/adm/data/owner_list"
37 # Get cards definition
38 . $SITE_TOOLS_PATH/adm/etc/cards
41 if [ ! -z "$1" ]; then
44 display "Usage: $me <cards to check>"
46 display "Where <cards to check> are a list of cards to check (default: all cards)"
50 notify_cc="$SITE_ADMIN_EMAIL"
52 # This function composes the email header and then appends the portion
53 # of the logfile as the body.
60 # Determine who owns this component
61 grep -qi "^$component" $owner_list
64 warning "Unknown component $component"
67 if [ "$SITE_NAME" = "US" ]; then
68 owner_email=$(grep -i "^$component " $owner_list | awk '{print $2}')"@salira.com"
70 owner_email=$(grep -i "^$component " $owner_list | awk '{print $3}')"@salira.com"
72 notify_to=$owner_email
76 echo "From: ccadmin" > /tmp/$me.msg
77 echo "To: $notify_to" >> /tmp/$me.msg
78 echo "cc: $notify_cc" >> /tmp/$me.msg
79 echo "Subject: $subject" >> /tmp/$me.msg
81 # Append section of logfile
82 tail -$err_lines $logfile >> /tmp/$me.msg
85 cat /tmp/$me.msg | $ssmtp -t
88 verbose "Sent email To: $notify_to Cc: $notify_cc"
89 verbose "Re: $subject"
92 echo "Unable to send email. Message left in /tmp/$me.msg"
97 # This function returns the number of lines from the end of the logfile
98 # that must be output to show the error. Input is the logfile name and
99 # the search line which denotes the area to start.
100 function error_lines {
104 # Determine the line number of the start of the error lines
105 startline=$(grep -n "$search_line" $logfile | cut -f1 -d':')
107 # Determine the number of lines in logfile
108 endline=$(wc -l $logfile | awk '{print $1}')
110 # Calculate the error lines
111 err_lines=$(($endline-$startline+1))
113 # Trim area to no more than 50 lines
114 if (( $err_lines > 50 )); then
121 function check_error {
125 logfile=$card.build.log
127 # If logfile doesn't exist then no error so simply return
128 if [ ! -f $logfile ]; then
129 verbose "Unable to find logfile for card $card"
133 # Check for successful build
134 grep -q "^Packing.*superfile" $logfile
136 if [ $? -eq 0 ]; then
137 verbose "$card built successfully!"
141 grep -q "Timestamp & Version" $logfile
143 if [ $? -ne 0 ]; then
144 verbose "$card compile failure"
145 # Loop through the logfile scanning for the "----" line which
146 # denotes a component. If there is an error then we are interested
147 # in the last component so save that.
148 while read line dir component; do
149 if [ "$line" = "--------------------------------------" ]; then
150 hitline="$dir $component"
152 hitcomponent=$component
154 # Not sure why we are trying bsp special...
155 if [ "$hitdir" = "(neopon/src/bsp)" ]; then
161 error_lines $logfile "$hitline"
164 send_email "Build of view: $view_tag Card: $card Component $hitcomponent failed to compile" $hitcomponent $logfile $err_lines
166 verbose "$card link failure"
167 error_lines $logfile "Timestamp & Version"
170 send_email "Build of view: $view_tag Card: $card failed to link" link $logfile $err_lines
175 while [ $# -ge 1 ]; do
190 cards_to_check="$cards_to_check $1"
195 # What view are we in?
196 view_tag=$(cleartool pwv -short)
198 if [ ! -z "$cards_to_check" ]; then
199 for card in $cards_to_check; do
200 card=$(echo $card | tr [:lower:] [:upper:])
201 verbose "Checking card $card..."
205 for card in $cards; do
206 card=$(echo $card | tr [:lower:] [:upper:])
207 verbose "Checking card $card..."