blob: 71aabd5c83b54686b02266fcf1bafc521608e532 [file] [log] [blame]
Simran Basie0479af2014-12-02 17:09:49 -08001#!/bin/bash
2
3SCRIPT_DIR=$(dirname $(readlink -f $0))
4RUNDATE=$(date +%Y-%m-%d.%H)
5DUT_DATA_DIR=$SCRIPT_DIR/../logs/dut-data
6RUNFILE=$DUT_DATA_DIR/inventory-$RUNDATE.txt
Fang Deng1443d9e2015-03-19 00:54:40 -07007GMAIL_SCRIPT=$SCRIPT_DIR/../site_utils/gmail_lib.py
Simran Basie0479af2014-12-02 17:09:49 -08008
J. Richard Barnette3d6877c2015-02-27 13:34:26 -08009# By default, we're invoked without arguments. This is used by
10# the cron job, and means we should generate output and mail it to
11# the default mail alias.
12#
13# Invoking with arguments is for testing: It allows running through
14# the full logic and output generation, without spamming the alert
15# aliases.
16
17cd $SCRIPT_DIR
18if [ $# -eq 0 ]; then
19 # TODO(jrbarnette): Really, this feels like a hack. The cron job
20 # that invokes this script is installed and enabled on both a
21 # primary and backup server, meaning the e-mail will be generated
22 # twice. We don't want that, so unless this is the primary server,
23 # quash this job.
24 if ! ../cli/atest server list $(hostname) 2>&1 |
25 grep -q '^Status *: *primary'; then
26 exit 0
27 fi
28
29 INTEREST=(
J. Richard Barnette7fd04502015-04-02 12:29:02 -070030 chromeos-infra-eng@grotations.appspotmail.com
J. Richard Barnette3d6877c2015-02-27 13:34:26 -080031 chromeos-lab-alerts@google.com
32 )
33else
34 INTEREST=( "$@" )
35fi
36
Simran Basie0479af2014-12-02 17:09:49 -080037mkdir -p $DUT_DATA_DIR
38SEP=
Fang Dengf3024f02015-02-17 16:41:12 -080039for pool in bvt cq
Simran Basie0479af2014-12-02 17:09:49 -080040do
41 echo -n "$SEP"
42 STATUS=$DUT_DATA_DIR/full.$RUNDATE.$pool.txt
J. Richard Barnette3d6877c2015-02-27 13:34:26 -080043 ./full_status $pool >$STATUS
44 ./report_status $STATUS
Simran Basie0479af2014-12-02 17:09:49 -080045 SEP="
46
47"
48done >$RUNFILE
49
Fang Deng1443d9e2015-03-19 00:54:40 -070050$GMAIL_SCRIPT -s "DUT pool inventories $RUNDATE" "${INTEREST[@]}" <$RUNFILE