Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing cloudbackup_mon.sh #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions cloudbackup_mon.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env bash
#
# cloudbackup_mon.sh
# Rackspace Cloud Monitoring Plugin to help detect if there are
# problems with Cloud Backups.
#
Expand Down Expand Up @@ -54,9 +51,6 @@
# if (metric['agent_running'] == 0) {
# return new AlarmStatus(CRITICAL, 'Agent is not running.');
# }
#
# return new AlarmStatus(OK, 'Cloud Backups Successful.');

function help {

cat <<HELP
Expand All @@ -74,27 +68,35 @@ fi
api_key=$1

if [ -z "$2" ]; then
this_backup_conf_id=
this_backup_conf_id=
else
this_backup_conf_id=$2
this_backup_conf_id=$2
fi


# Get username and agentid
username=`cat /etc/driveclient/bootstrap.json | grep Username | awk '{print $3}' | sed -e 's/"//g' -e 's/,//g'`
agentid=`cat /etc/driveclient/bootstrap.json | grep AgentId | awk '{print $3}' | sed -e 's/,//g'`
ddi=`cat /etc/driveclient/bootstrap.json | grep AccountId | awk '{print $3}' | sed -e 's/"//g' -e 's/,//g'`
api_hostname=`cat /etc/driveclient/bootstrap.json | grep ApiHostName | awk '{print $3}' | sed -e 's/"//g' -e 's/,//g'`


token=`curl -s https://identity.api.rackspacecloud.com/v2.0/tokens \
-X POST \
-d '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"'"$username"'","apiKey":"'"$api_key"'"}}}' \
-H "Content-type: application/json" | python -m json.tool | grep -A5 token | grep id | cut -d '"' -f4`

# Get token
token=`curl -s -I -H "X-Auth-Key: $api_key" -H "X-Auth-User: $username" https://auth.api.rackspacecloud.com/v1.0 | grep -vi 'vary:' | grep -i X-Auth-Token |awk {'print $2'}`
#token=curl -s -I -H "X-Auth-Key: $api_key" -H "X-Auth-User: $username" https://auth.api.rackspacecloud.com/v1.0 | grep -vi 'vary:' | grep -i X-Auth-Token |awk {'print $2'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either leave this command untouched (including backticks ````) or remove the comment entirely.


# Get latest backup IDs
backup_ids=`curl -s -H "X-Auth-Token: $token" https://backup.api.rackspacecloud.com/v1.0/backup-configuration/system/$agentid | python -m json.tool |grep LastRunBackupReportId | awk '{print $2}' | sed -e 's/,//g'`
backup_ids=`curl -s -H "X-Auth-Token: $token" https://$api_hostname/v1.0/$ddi/backup-configuration/system/$agentid | python -m json.tool |grep LastRunBackupReportId | awk '{print $2}' | sed -e 's/,//g'`

tmpfile=`mktemp`
for backup_id in $backup_ids; do

# Run report to see if backup was successful:
curl -s -H "X-Auth-Token: $token " https://backup.api.rackspacecloud.com/v1.0/backup/report/$backup_id | python -m json.tool > $tmpfile
curl -s -H "X-Auth-Token: $token" https://$api_hostname/v1.0/$ddi/backup/report/$backup_id | python -m json.tool > $tmpfile

conf_id=`grep BackupConfigurationId < $tmpfile | sed -e 's/"BackupConfigurationId": //g' -e 's/,//g' -e 's/[ \t]*//g'`
if [ "X$this_backup_conf_id" != "X" -a "X$conf_id" != "X$this_backup_conf_id" ]; then
Expand Down