Setting the file. One moment.
Appservice Diagnostics · Azure Diagnostics · microsoft/azure-skills · Skills Docs
ContentsBack to the top of the page ·
scripts/appservice-diagnostics.sh
scripts/ appservice-diagnostics.sh
Shell · 83 lines · 3 KB
15
16 set -euo pipefail
17
18 APP = ""
19 RG = ""
20 SUBSCRIPTION = ""
21
22 usage () {
23 echo "Usage: $0 --name <app> --resource-group <rg> [--subscription <id>]" >&2
24 }
25
26 # Requires a value to follow the given flag; errors out otherwise.
27 require_value () {
28 if [ " $2 " -lt 2 ]; then
29 echo "Error: option ' $1 ' requires a value." >&2
30 usage
31 exit 1
32 fi
33 }
34
35 # Support both --flag and positional styles.
36 POSITIONAL = ()
37 while [ $# -gt 0 ]; do
38 case " $1 " in
39 --name | -n ) require_value " $1 " " $# " ; APP = " $2 " ; shift 2 ;;
40 --resource-group | -g ) require_value " $1 " " $# " ; RG = " $2 " ; shift 2 ;;
41 --subscription | -s ) require_value " $1 " " $# " ; SUBSCRIPTION = " $2 " ; shift 2 ;;
42 -- *| - ? ) echo "Error: unknown option ' $1 '." >&2 ; usage ; exit 1 ;;
43 *) POSITIONAL += ( " $1 " ); shift ;;
44 esac
45 done
46
47 if [ -z " $APP " ] && [ "${ # POSITIONAL [ @ ]}" -ge 1 ]; then APP = "${ POSITIONAL [0]}" ; fi
48 if [ -z " $RG " ] && [ "${ # POSITIONAL [ @ ]}" -ge 2 ]; then RG = "${ POSITIONAL [1]}" ; fi
49 if [ -z " $SUBSCRIPTION " ] && [ "${ # POSITIONAL [ @ ]}" -ge 3 ]; then SUBSCRIPTION = "${ POSITIONAL [2]}" ; fi
50
51 if [ -z " $APP " ] || [ -z " $RG " ]; then
52 usage
53 exit 1
54 fi
55
56 SUB_ARGS = ()
57 if [ -n " $SUBSCRIPTION " ]; then SUB_ARGS = ( --subscription " $SUBSCRIPTION " ); fi
58
59 echo "=== App Service Diagnostics: $APP (resource group: $RG ) ==="
60 echo "Collecting app config, recent deployments, app settings, and custom domains."
61 echo ""
62
63 echo "--- App Config ---"
64 az webapp show -n " $APP " -g " $RG " "${ SUB_ARGS [ @ ]}" \
65 --query "{state:state, runtime:siteConfig.linuxFxVersion, healthCheck:siteConfig.healthCheckPath, alwaysOn:siteConfig.alwaysOn}" \
66 -o table || echo "(failed to read app config)"
67 echo ""
68
69 echo "--- Recent Deployments (last 3) ---"
70 az webapp deployment list -n " $APP " -g " $RG " "${ SUB_ARGS [ @ ]}" \
71 --query "[:3].{id:id, status:status, time:end_time}" -o table || echo "(failed to list deployments)"
72 echo ""
73
74 echo "--- App Settings (names only) ---"
75 az webapp config appsettings list -n " $APP " -g " $RG " "${ SUB_ARGS [ @ ]}" \
76 --query "[].name" -o tsv || echo "(failed to list app settings)"
77 echo ""
78
79 echo "--- Custom Domains ---"
80 az webapp config hostname list -g " $RG " --webapp-name " $APP " "${ SUB_ARGS [ @ ]}" -o table || echo "(failed to list custom domains)"
81 echo ""
82
83 echo "=== Diagnostics collection complete for $APP ==="