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

Added curl's --ssl argument #2

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ check_imap [OPTIONS]
-C CREDENTIAL Username:Password, i.E. "user2:horsestaplebattery" (default: no auth)
-M MAILBOX Mailbox Name, needed for IMAP(s) only (default: INBOX)
-I INSECURE Allow insecure connections using IMAPs and POP3s (default: OFF)
-S SSL Try to use SSL/TLS for the connection (default: OFF)
-V VERBOSE Use verbose mode of CURL for debugging (default: OFF)
-c CRITICAL Critical threshold for execution in milliseconds (default: 3500)
-w WARNING Warning threshold for execution in milliseconds (default: 2000)
Expand Down Expand Up @@ -63,6 +64,9 @@ object CheckCommand "check-mailbox" {
"-H" = "$chm_host$"
"-C" = "user:password"
"-M" = "INBOX"
"-S" = {
set_if = "$ssl$"
}
"-w" = "1000"
"-c" = "2000"
}
Expand Down
15 changes: 12 additions & 3 deletions check_mailbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mailbox="INBOX"
credential=""
imap=1
insecure=0
ssl=0
verbose=0

# Usage Info
Expand All @@ -35,6 +36,7 @@ usage() {
-C CREDENTIAL Username:Password, i.E. "user2:horsestaplebattery" (default: no auth)
-M MAILBOX Mailbox Name, needed for IMAP(s) only (default: INBOX)
-I INSECURE Allow insecure connections using IMAPs and POP3s (default: OFF)
-S SSL Try to use SSL/TLS for the connection (default: OFF)
-V VERBOSE Use verbose mode of CURL for debugging (default: OFF)
-c CRITICAL Critical threshold for execution in milliseconds (default: 3500)
-w WARNING Warning threshold for execution in milliseconds (default: 2000)
Expand All @@ -43,7 +45,7 @@ usage() {

#main
#get options
while getopts "H:C:M:IVc:w:" opt; do
while getopts "H:C:M:ISVc:w:" opt; do
case $opt in
c)
critical=$OPTARG
Expand All @@ -63,6 +65,9 @@ while getopts "H:C:M:IVc:w:" opt; do
I)
insecure=1
;;
S)
ssl=1
;;
V)
verbose=1
;;
Expand Down Expand Up @@ -106,6 +111,10 @@ insecurearg=""
if [ $insecure -eq 1 ]; then
insecurearg=" --insecure "
fi
sslarg=""
if [ $ssl -eq 1 ]; then
sslarg=" --ssl "
fi
verbosearg=""
if [ $verbose -eq 1 ]; then
verbosearg=" --verbose "
Expand All @@ -123,11 +132,11 @@ fi
start=$(echo $(($(date +%s%N)/1000000)))

if [ $imap -eq 0 ]; then
body=$(eval curl --url "$fqhost" -X $commandarg $credentialarg -s --max-time $maxwait $insecurearg $verbosearg)
body=$(eval curl --url "$fqhost" -X $commandarg $credentialarg -s --max-time $maxwait $sslarg $insecurearg $verbosearg)
status=$?
body=$(echo "$body" | tail -1 | cut -d " " -f1)
else
body=$(eval curl --url "$fqhost" -X $commandarg $credentialarg -s --max-time $maxwait $insecurearg $verbosearg)
body=$(eval curl --url "$fqhost" -X $commandarg $credentialarg -s --max-time $maxwait $sslarg $insecurearg $verbosearg)
status=$?
body=$(echo "$body" | head -1 | cut -d " " -f2)
fi
Expand Down