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 |
| 7 | |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame^] | 8 | # 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 | |
| 16 | cd $SCRIPT_DIR |
| 17 | if [ $# -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 | ) |
| 31 | else |
| 32 | INTEREST=( "$@" ) |
| 33 | fi |
| 34 | |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 35 | mkdir -p $DUT_DATA_DIR |
| 36 | SEP= |
Fang Deng | f3024f0 | 2015-02-17 16:41:12 -0800 | [diff] [blame] | 37 | for pool in bvt cq |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 38 | do |
| 39 | echo -n "$SEP" |
| 40 | STATUS=$DUT_DATA_DIR/full.$RUNDATE.$pool.txt |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame^] | 41 | ./full_status $pool >$STATUS |
| 42 | ./report_status $STATUS |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 43 | SEP=" |
| 44 | |
| 45 | " |
| 46 | done >$RUNFILE |
| 47 | |
Simran Basi | 604b61d | 2014-12-17 11:52:38 -0800 | [diff] [blame] | 48 | mailx -s "DUT pool inventories $RUNDATE" "${INTEREST[@]}" <$RUNFILE |