Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
WSO2_Healthcheck_Shell_Script
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kaczan
WSO2_Healthcheck_Shell_Script
Commits
0242b3a5
Commit
0242b3a5
authored
Apr 02, 2019
by
kaczan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shell Script
parent
6d524fda
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
206 additions
and
0 deletions
+206
-0
HealthCheck.sh
HealthCheck.sh
+206
-0
No files found.
HealthCheck.sh
0 → 100644
View file @
0242b3a5
#Add Sites to monitor here
SITES
=(
\
"https://aws.amazon.com"
\
"https://www.facebook.com"
\
"https://www.google.com/"
\
"https://localhost:9443/console/"
\
"https://localhost:9543/console/"
\
)
SITES_STATUS_FILE
=
"/tmp/wso2SiteMonitor.status"
#Add Admin Services to monitor server status here
SERVICES
=(
\
"https://localhost:9443/services/ServerAdmin"
\
"https://localhost:9543/services/ServerAdmin"
\
)
SERVICES_STATUS_FILE
=
"/tmp/wso2ServiceMonitor.status"
SLOW_THRESHOLD_SERVICE
=
4
# Slow threshold for services in Seconds
SLOW_THRESHOLD_SITE
=
10
# Slow threshold for consoles in Seconds
CURL_TIMEOUT
=
15
# Curl timeout in seconds
SITE_OK_STATUS
=(
"200"
)
SERCVICE_OK_XML_RESPONSE
=
'<ns:return>RUNNING</ns:return>'
#Base64 encoded string for wso2 user:pwd
AUTH_HEADER
=
"Authorization: Basic YWRtaW46YWRtaW4="
#Note: Configure mail commands in lines 102 and 182 as per your environments mail server configuration
#Email users
#NOTIFY_FROM_EMAIL='monitoring@xyz.com'
#NOTIFY_TO_EMAIL='mymail@xyz.com'
######### NO USER MOD BELOW THIS LINE ############
echo
"* * * Start of Health Check * * *"
echo
" "
#--------- Begin: Sites Health Check ------------
for
SITE
in
"
${
SITES
[@]
}
"
do
START
=
$(
date +%s
)
RESPONSE
=
`
wget
$SITE
--no-check-certificate
-S
-q
-O
- 2>&1 |
\
awk
'/^ HTTP/{print \$2}'
`
END
=
$(
date +%s
)
DIFF
=
$((
$END
-
$START
))
if
[
-z
"
$RESPONSE
"
]
;
then
RESPONSE
=
"0"
fi
if
[[
$RESPONSE
=
*
$SITE_OK_STATUS
*
]]
then
RESPONSE
=
"200"
if
[
"
$DIFF
"
-lt
"
$SLOW_THRESHOLD_SITE
"
]
;
then
STATUS
=
"UP"
else
STATUS
=
"SLOW"
fi
else
STATUS
=
"DOWN"
fi
echo
"Site:
$SITE
is
$STATUS
"
echo
"Latency is
$DIFF
seconds"
echo
" "
touch
$SITES_STATUS_FILE
STATUS_LINE
=
`
grep
$SITE
$SITES_STATUS_FILE
`
STATUS_PARTS
=(
$(
echo
$STATUS_LINE
| tr
" "
"
\n
"
)
)
CHANGED
=
${
STATUS_PARTS
[2]
}
if
[
"
$STATUS
"
!=
"
${
STATUS_PARTS
[5]
}
"
]
;
then
#if [ -e "${STATUS_PARTS[5]}" ] || [ "$STATUS" != "UP" ]; then
if
[
-z
"
${
STATUS_PARTS
[5]
}
"
]
;
then
STATUS_PARTS[5]
=
"No record"
fi
#TIME=`date -d @$END` # Linux format
TIME
=
`
date
-r
"
$END
"
"+%Y-%m-%d %H:%M:%S"
`
#Mac Format
echo
"Time:
$TIME
"
>
/tmp/SiteMonitor.email.tmp
echo
"Site:
$SITE
"
>>
/tmp/SiteMonitor.email.tmp
echo
"Status:
$STATUS
"
>>
/tmp/SiteMonitor.email.tmp
echo
"Latency:
$DIFF
sec"
>>
/tmp/SiteMonitor.email.tmp
echo
"Previous status:
${
STATUS_PARTS
[5]
}
"
>>
/tmp/SiteMonitor.email.tmp
if
[
-z
"
${
STATUS_PARTS
[2]
}
"
]
;
then
TIME
=
"No record"
else
#TIME=`date -d @${STATUS_PARTS[2]}` - Linux format
TIME
=
`
date
-r
${
STATUS_PARTS
[2]
}
"+%Y-%m-%d %H:%M:%S"
`
# Mac Format
fi
echo
"Previous change:
$TIME
"
>>
/tmp/SiteMonitor.email.tmp
# Replace below email snippet with your Script for Email notification
echo
"-----Begin: Sending Email Content for Site status--------"
cat
/tmp/SiteMonitor.email.tmp
# `mail -a "From: $NOTIFY_FROM_EMAIL" \
# -s "SiteMonitor Notification: $HOST is $STATUS" \
# "$NOTIFY_TO_EMAIL" < /tmp/SiteMonitor.email.tmp`
echo
"----- End: Sending Email Content for Site status--------"
rm
-f
/tmp/SiteMonitor.email.tmp
#else
# first report, but host is up, so no need to notify
#fi
CHANGED
=
"
$END
"
fi
echo
$SITE
$RESPONSE
$CHANGED
$END
$DIFF
$STATUS
>>
/tmp/SiteMonitor.status.tmp
done
mv /tmp/SiteMonitor.status.tmp
$SITES_STATUS_FILE
#--------- End: Sites Health Check ------------
#--------- Begin: Services Health Check ------------
for
SERVICE
in
"
${
SERVICES
[@]
}
"
do
START
=
$(
date +%s
)
RAW
=
`
curl
-k
-sL
-H
"Content-Type: application/soap+xml;charset=UTF-8;"
-H
"
$AUTH_HEADER
"
-H
"SOAPAction:urn:getServerStatus"
--data
@getServerStatus.xml
--connect-timeout
$CURL_TIMEOUT
$SERVICE
`
END
=
$(
date +%s
)
DIFF
=
$((
$END
-
$START
))
if
[
-z
"
$RAW
"
]
;
then
RESPONSE
=
"NULL"
else
RESPONSE
=
"NOT_NULL"
fi
if
[[
$RAW
=
*
$SERCVICE_OK_XML_RESPONSE
*
]]
then
if
[
"
$DIFF
"
-lt
"
$SLOW_THRESHOLD_SERVICE
"
]
;
then
STATUS
=
"UP"
else
STATUS
=
"SLOW"
fi
else
STATUS
=
"DOWN"
fi
echo
"Service:
$SERVICE
is
$STATUS
"
echo
"Latency is
$DIFF
seconds"
echo
" "
touch
$SERVICES_STATUS_FILE
STATUS_LINE
=
`
grep
$SERVICE
$SERVICES_STATUS_FILE
`
STATUS_PARTS
=(
$(
echo
$STATUS_LINE
| tr
" "
"
\n
"
)
)
CHANGED
=
${
STATUS_PARTS
[2]
}
if
[
"
$STATUS
"
!=
"
${
STATUS_PARTS
[5]
}
"
]
;
then
#if [ -e "${STATUS_PARTS[5]}" ] || [ "$STATUS" != "UP" ]; then
if
[
-z
"
${
STATUS_PARTS
[5]
}
"
]
;
then
STATUS_PARTS[5]
=
"No record"
fi
#TIME=`date -d @$END` # Linux format
TIME
=
`
date
-r
"
$END
"
"+%Y-%m-%d %H:%M:%S"
`
#Mac Format
echo
"Time:
$TIME
"
>
/tmp/ServiceMonitor.email.tmp
echo
"Service:
$SERVICE
"
>>
/tmp/ServiceMonitor.email.tmp
echo
"Status:
$STATUS
"
>>
/tmp/ServiceMonitor.email.tmp
echo
"Latency:
$DIFF
sec"
>>
/tmp/ServiceMonitor.email.tmp
echo
"Previous status:
${
STATUS_PARTS
[5]
}
"
>>
/tmp/ServiceMonitor.email.tmp
if
[
-z
"
${
STATUS_PARTS
[2]
}
"
]
;
then
TIME
=
"No record"
else
#TIME=`date -d @${STATUS_PARTS[2]}` - Linux format
TIME
=
`
date
-r
${
STATUS_PARTS
[2]
}
"+%Y-%m-%d %H:%M:%S"
`
# Mac Format
fi
echo
"Previous change:
$TIME
"
>>
/tmp/ServiceMonitor.email.tmp
# Replace below email snippet with your Script for Email notification
echo
"-----Begin: Sending Email Content for Service status--------"
cat
/tmp/ServiceMonitor.email.tmp
# `mail -a "From: $NOTIFY_FROM_EMAIL" \
# -s "ServiceMonitor Notification: $HOST is $STATUS" \
# "$NOTIFY_TO_EMAIL" < /tmp/ServiceMonitor.email.tmp`
echo
"----- End: Sending Email Content for Service status--------"
rm
-f
/tmp/ServiceMonitor.email.tmp
#else
# first report, but host is up, so no need to notify
#fi
CHANGED
=
"
$END
"
fi
echo
$SERVICE
$RESPONSE
$CHANGED
$END
$DIFF
$STATUS
>>
/tmp/ServiceMonitor.status.tmp
done
mv /tmp/ServiceMonitor.status.tmp
$SERVICES_STATUS_FILE
#--------- End: Services Health Check ------------
echo
"* * * End of Health Check * * *"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment