From 6a2efe3c035409b48ddda37633c9bd5e73b37e19 Mon Sep 17 00:00:00 2001 From: "tommaso.piccioli" Date: Fri, 22 Jul 2016 14:23:00 +0200 Subject: [PATCH] New self-made script to check warranty on xen and san Dell hosts --- nagios/defaults/main.yml | 3 +- nagios/files/dell_warranty_lifetime.sh | 52 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100755 nagios/files/dell_warranty_lifetime.sh diff --git a/nagios/defaults/main.yml b/nagios/defaults/main.yml index 9a7ec64..7f16134 100644 --- a/nagios/defaults/main.yml +++ b/nagios/defaults/main.yml @@ -65,7 +65,8 @@ nagios_dell_omsa_pkgs: # We need a more recent version of the check_openmanage executable nagios_dell_standalone_checks: - - check_dell_warranty.py +# - check_dell_warranty.py + - dell_warranty_lifetime.sh - check_openmanage nagios_openmanage_additional_opts: '' diff --git a/nagios/files/dell_warranty_lifetime.sh b/nagios/files/dell_warranty_lifetime.sh new file mode 100755 index 0000000..13ce9d8 --- /dev/null +++ b/nagios/files/dell_warranty_lifetime.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +#Nagios plug-in to check Dell Warranty and Support Service Level + +#Version: 1.0 +#Created: 2016-07-22 +#Author: Tommaso piccioli + +apikey=849e027f476027a394edd656eaef4842 +baseurl='https://apidp.dell.com/support/assetinfo/v4/getassetwarranty/' + +ServiceTag=`dmidecode -t system | grep -m 1 'Serial Number' | awk '{print $3}'` + +requrl="${baseurl}${ServiceTag}?apikey=${apikey}" + +#echo $requrl + +reqresp=`wget -q -O - $requrl | sed 's/}/\n/g' | grep -m 1 AssetEntitlementData` + +ServiceLevelDescription=`echo $reqresp | sed 's/{/\n/g' | sed 's/,/\n/g' | grep ServiceLevelDescription | awk -F '"' '{print $4}'` +StartDate=`echo $reqresp | sed 's/{/\n/g' | sed 's/,/\n/g' | grep StartDate | awk -F '"' '{print $4}'` +EndDate=`echo $reqresp | sed 's/{/\n/g' | sed 's/,/\n/g' | grep EndDate | awk -F '"' '{print $4}'` + +EndDay=`echo $EndDate | awk -F 'T' '{print $1}'` +#TodayDate=`date +'%Y-%m-%d'` + +SecsLeft=$(( `date -d $EndDay +%s`-`date +%s`)) +DaysLeft=$(( $SecsLeft/86400 )) + +#echo $DaysLeft + +##output="OK: Service Tag: FNV4H92, Warranty: Next Business Day, Start: 01/03/2016, End: 01/04/2019, Days left: 905" +output="Service Tag: $ServiceTag, Warranty: $ServiceLevelDescription, Start: $StartDate, End: $EndDate, Days left: $DaysLeft" + +#echo $output + +if [ $DaysLeft -gt 60 ] +then + echo "OK - $output" + exit 0 +elif [ $DaysLeft -gt 30 ] +then + echo "WARNING - $output" + exit 1 +elif [ $DaysLeft -gt 15 ] +then + echo "CRITICAL - $output" + exit 2 +else +echo "UNKNOWN - $output" +exit 3 +fi