Skip to content

Commit

Permalink
Merge pull request #2 from 1resu/ssl
Browse files Browse the repository at this point in the history
Added curl's --ssl argument
  • Loading branch information
ozzi- committed Nov 25, 2019
2 parents aee9a8f + 6b11390 commit 1145c5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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

0 comments on commit 1145c5b

Please sign in to comment.