blob: 666c1ddb67dd2391db62fbaf27f2ce1c0540d9d7 [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
7
J. Richard Barnette3d6877c2015-02-27 13:34:26 -08008# By default, we're invoked without arguments. This is used by
9# the cron job, and means we should generate output and mail it to
10# the default mail alias.
11#
12# Invoking with arguments is for testing: It allows running through
13# the full logic and output generation, without spamming the alert
14# aliases.
15
16cd $SCRIPT_DIR
17if [ $# -eq 0 ]; then
18 # TODO(jrbarnette): Really, this feels like a hack. The cron job
19 # that invokes this script is installed and enabled on both a
20 # primary and backup server, meaning the e-mail will be generated
21 # twice. We don't want that, so unless this is the primary server,
22 # quash this job.
23 if ! ../cli/atest server list $(hostname) 2>&1 |
24 grep -q '^Status *: *primary'; then
25 exit 0
26 fi
27
28 INTEREST=(
29 chromeos-lab-alerts@google.com
30 )
31else
32 INTEREST=( "$@" )
33fi
34
Simran Basie0479af2014-12-02 17:09:49 -080035mkdir -p $DUT_DATA_DIR
36SEP=
Fang Dengf3024f02015-02-17 16:41:12 -080037for pool in bvt cq
Simran Basie0479af2014-12-02 17:09:49 -080038do
39 echo -n "$SEP"
40 STATUS=$DUT_DATA_DIR/full.$RUNDATE.$pool.txt
J. Richard Barnette3d6877c2015-02-27 13:34:26 -080041 ./full_status $pool >$STATUS
42 ./report_status $STATUS
Simran Basie0479af2014-12-02 17:09:49 -080043 SEP="
44
45"
46done >$RUNFILE
47
Simran Basi604b61d2014-12-17 11:52:38 -080048mailx -s "DUT pool inventories $RUNDATE" "${INTEREST[@]}" <$RUNFILE