Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
v1.0.0 tested
  • Loading branch information
FoUStep authored Jun 14, 2023
1 parent 942f9a1 commit 3687de4
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions check_mijn.host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
# Nagios Check - 2023 MIJN.HOST API CHECK EXPIRY DOMAIN
# 20230614 v1.0 - Step (debian 11.x tested)

#
# API key is required, ask [email protected] for an API key.
# WARNING: SCRIPT NEEDS TO BE TESTED IF MULTIPLE DOMAINS!
#

# Main Vars
OK=0
WARNING=1
CRITICAL=2
ERROR=4

crit=30
warn=60

domain=$1
apikey=$2

# Check for curl & dateutils
if ! [ -x "$(command -v curl)" ]; then
echo 'Error: curl is not installed.' >&2
exit $ERROR
fi

if ! [ -x "$(command -v dateutils.ddiff)" ]; then
echo 'Error: dateutils is not installed.' >&2
exit $ERROR
fi

if [ -z "$domain" ] || [ -z "$apikey" ]
# $domain is required but is not used except for display in output.
then
echo Usage: "$0 <domain> <apikey> (requires dateutils and curl)"
exit $ERROR
fi

# Check date today
today=$(date "+%Y-%m-%d")

# Run complete check for domain expiry
expiredate=$(curl -s --location --request POST 'https://mijn.host/api/v1/domain/domains/' --header 'API-Key: '$apikey'' --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' | jq -r '.data."domains" | .[] | .renewal_date')
remainingdays=$(( ($(date --date="$expiredate UTC" +%s) - $(date --date="$today UTC" +%s) )/(60*60*24) ))
output=$(dateutils.ddiff -f '%Y years, %m months, %d days' today "$(dateutils.dadd now $remainingdays)")

if [ "$remainingdays" -lt "$crit" ];
then
echo "CRITICAL - Renew domain $1. It expires in: $output | Remaining(Days)=$remainingdays"
exit $CRITICAL
else
if [ "$remainingdays" -lt "$warn" ];
then
echo "WARNING - Renew domain $1. It expires in: $output | Remaining(Days)=$remainingdays"
exit $WARNING
else
echo "DOMAIN OK - Domain $1 expires in: $output | Remaining(Days)=$remainingdays"
exit $OK
fi
fi

0 comments on commit 3687de4

Please sign in to comment.