forked from erjosito/azcli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage_logs.azcli
58 lines (58 loc) · 3.09 KB
/
storage_logs.azcli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
storage_account=myobjects
container_name=templates
key=$(az storage account keys list -n myobjects --query '[0].value' -o tsv)
log_container_name=$(az storage container show -n '$logs' --account-name $storage_account --account-key $key --query name -o tsv)
if [[ -z ${log_container_name} ]]
then
echo "Are you sure that you have activated audit trail logs for the storage account ${storage_account}?"
else
echo "Container with audit logs found, retrieving log list..."
# Use this line for all logs
full_blob_list=$(az storage blob list -c '$logs' --account-name $storage_account --account-key $key --query '[].name' -o tsv)
echo "Found these log files:"
az storage blob list -c '$logs' --account-name $storage_account --account-key $key -o table
# Use this line for only the last log file
filtered_blob_list=$(az storage blob list -c '$logs' --account-name $storage_account --account-key $key --query '[-1].name' -o tsv)
# Process the retrieved logs one by one
echo "Printing only the last log file:"
temp_filename=/tmp/blog.log
echo $full_blob_list | while read blob_name ; do
if [[ -n "${blob_name}" ]]
then
az storage blob download -n $blob_name -c '$logs' --account-name $storage_account --account-key $key --no-progress -f $temp_filename >/dev/null
cat $temp_filename | while read line ; do
version=$(echo $line | cut -d';' -f 1)
# Only v2.0
if [[ ${version} == "2.0" ]]
then
timestamp=$(echo $line | cut -d';' -f 2)
operation=$(echo $line | cut -d';' -f 3)
accessed_blob_url=$(echo $line | cut -d';' -f 12)
accessed_blob_name=$(echo $line | cut -d';' -f 13)
accessed_container=$(echo $blob_url | cut -d'/' -f 4)
accessed_container=$(echo $accessed_container | cut -d'?' -f 1)
agent=$(echo $line | cut -d';' -f 30)
else
timestamp=$(echo $line | cut -d';' -f 2)
operation=$(echo $line | cut -d';' -f 3)
accessed_blob_url=$(echo $line | cut -d';' -f 12)
accessed_blob_name=$(echo $line | cut -d';' -f 13)
accessed_container=$(echo $blob_url | cut -d'/' -f 4)
accessed_container=$(echo $accessed_container | cut -d'?' -f 1)
agent=$(echo $line | cut -d';' -f 30)
fi
# Only print certain operations
if [[ ${operation} == 'PutBlob' ]] || [[ ${operation} == 'GetBlob' ]]
then
# Do not print access to the logs (this tool for example)
if [[ ${container} != '$logs' ]]
then
# echo $line # Uncommnet for debugging
printf "** %.25s %4s %.10s %.40s %.15s %.60s\n" $timestamp $version $operation $agent $accessed_container $accessed_blob_name
fi
fi
done
rm $temp_filename
fi
done
fi