Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | SCRIPT_DIR=$(dirname $(readlink -f $0)) |
| 4 | RUNDATE=$(date +%Y-%m-%d.%H) |
| 5 | DUT_DATA_DIR=$SCRIPT_DIR/../logs/dut-data |
| 6 | RUNFILE=$DUT_DATA_DIR/inventory-$RUNDATE.txt |
Fang Deng | 1443d9e | 2015-03-19 00:54:40 -0700 | [diff] [blame] | 7 | GMAIL_SCRIPT=$SCRIPT_DIR/../site_utils/gmail_lib.py |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 8 | |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 9 | # 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 | |
| 17 | cd $SCRIPT_DIR |
| 18 | if [ $# -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 Barnette | 7fd0450 | 2015-04-02 12:29:02 -0700 | [diff] [blame] | 30 | chromeos-infra-eng@grotations.appspotmail.com |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 31 | chromeos-lab-alerts@google.com |
| 32 | ) |
| 33 | else |
| 34 | INTEREST=( "$@" ) |
| 35 | fi |
| 36 | |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 37 | mkdir -p $DUT_DATA_DIR |
| 38 | SEP= |
Fang Deng | f3024f0 | 2015-02-17 16:41:12 -0800 | [diff] [blame] | 39 | for pool in bvt cq |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 40 | do |
| 41 | echo -n "$SEP" |
| 42 | STATUS=$DUT_DATA_DIR/full.$RUNDATE.$pool.txt |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 43 | ./full_status $pool >$STATUS |
| 44 | ./report_status $STATUS |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 45 | SEP=" |
| 46 | |
| 47 | " |
| 48 | done >$RUNFILE |
| 49 | |
Fang Deng | 1443d9e | 2015-03-19 00:54:40 -0700 | [diff] [blame] | 50 | $GMAIL_SCRIPT -s "DUT pool inventories $RUNDATE" "${INTEREST[@]}" <$RUNFILE |