blob: 3a36d2e61b9225d8e9bc6275003594f0d0210d00 [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=(
30 chromeos-lab-alerts@google.com
31 )
32else
33 INTEREST=( "$@" )
34fi
35
Simran Basie0479af2014-12-02 17:09:49 -080036mkdir -p $DUT_DATA_DIR
37SEP=
Fang Dengf3024f02015-02-17 16:41:12 -080038for pool in bvt cq
Simran Basie0479af2014-12-02 17:09:49 -080039do
40 echo -n "$SEP"
41 STATUS=$DUT_DATA_DIR/full.$RUNDATE.$pool.txt
J. Richard Barnette3d6877c2015-02-27 13:34:26 -080042 ./full_status $pool >$STATUS
43 ./report_status $STATUS
Simran Basie0479af2014-12-02 17:09:49 -080044 SEP="
45
46"
47done >$RUNFILE
48
Fang Deng1443d9e2015-03-19 00:54:40 -070049$GMAIL_SCRIPT -s "DUT pool inventories $RUNDATE" "${INTEREST[@]}" <$RUNFILE