Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | SCRIPT_DIR=$(dirname $(readlink -f $0)) |
Simran Basi | e0479af | 2014-12-02 17:09:49 -0800 | [diff] [blame] | 4 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame^] | 5 | # By default, we're invoked without arguments. This is how the cron |
| 6 | # job does it, and means we should generate output and mail it to |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 7 | # the default mail alias. |
| 8 | # |
| 9 | # Invoking with arguments is for testing: It allows running through |
| 10 | # the full logic and output generation, without spamming the alert |
| 11 | # aliases. |
| 12 | |
| 13 | cd $SCRIPT_DIR |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame^] | 14 | OPTIONS="" |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 15 | if [ $# -eq 0 ]; then |
| 16 | # TODO(jrbarnette): Really, this feels like a hack. The cron job |
| 17 | # that invokes this script is installed and enabled on both a |
| 18 | # primary and backup server, meaning the e-mail will be generated |
| 19 | # twice. We don't want that, so unless this is the primary server, |
| 20 | # quash this job. |
| 21 | if ! ../cli/atest server list $(hostname) 2>&1 | |
| 22 | grep -q '^Status *: *primary'; then |
| 23 | exit 0 |
| 24 | fi |
| 25 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame^] | 26 | POOL_INTEREST=( |
J. Richard Barnette | 7fd0450 | 2015-04-02 12:29:02 -0700 | [diff] [blame] | 27 | chromeos-infra-eng@grotations.appspotmail.com |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 28 | chromeos-lab-alerts@google.com |
| 29 | ) |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame^] | 30 | BOARD_INTEREST=( |
| 31 | skc-fireteam@google.com |
| 32 | "${POOL_INTEREST[@]}" |
| 33 | ) |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 34 | else |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame^] | 35 | BOARD_INTEREST=( "$@" ) |
| 36 | POOL_INTEREST=( "$@" ) |
| 37 | OPTIONS=--print |
J. Richard Barnette | 3d6877c | 2015-02-27 13:34:26 -0800 | [diff] [blame] | 38 | fi |
| 39 | |
J. Richard Barnette | 96db349 | 2015-03-27 17:23:52 -0700 | [diff] [blame^] | 40 | cd .. |
| 41 | BOARD_NOTIFY=( |
| 42 | --board-notify |
| 43 | $(echo "${BOARD_INTEREST[@]}" | sed 's/ /,/g') |
| 44 | ) |
| 45 | POOL_NOTIFY=( |
| 46 | --pool-notify |
| 47 | $(echo "${POOL_INTEREST[@]}" | sed 's/ /,/g') |
| 48 | ) |
| 49 | site_utils/lab_inventory.py $OPTIONS "${BOARD_NOTIFY[@]}" "${POOL_NOTIFY[@]}" |