Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 121 lines (103 sloc) 3.62 KB
#!/usr/bin/python
""" Nagios plugin to check the Dell warranty status from Dell's website"""
from datetime import datetime
import argparse
import netsnmp
from suds.client import Client
import sys
import uuid
# parse parameters and options
parser = argparse.ArgumentParser(description='Look up Dell warranty status')
parser.add_argument('-H',
dest='host',
help='host name',
required=True)
parser.add_argument('-s',
dest='service_tag',
help='service tag or snmp lookup',
required=True)
parser.add_argument('-C',
dest='community',
help='snmp community string')
parser.add_argument('-w',
dest='warning',
help='warning days',
required=True,
type=int)
parser.add_argument('-c',
dest='critical',
help='critical days',
required=True,
type=int)
args = parser.parse_args()
# set variables based on parameters
community = args.community
dayswarn = args.warning
dayscrit = args.critical
host = args.host
if dayswarn <= dayscrit:
print "error: warn time must be greater than critical time"
sys.exit(3)
svctag = args.service_tag
if svctag == 'snmp':
if community is None:
print "error: SNMP community not defined with -C"
print parser.print_help()
sys.exit(3)
var = netsnmp.Varbind('.1.3.6.1.4.1.674.10892.1.300.10.1.11.1')
res = netsnmp.snmpget(var, Version=1, DestHost=host, Community=community)
svctag = res[0]
if svctag is None:
print 'error: SNMP communication error'
sys.exit(3)
uuid = uuid.uuid4()
# get warranty
def get_asset_info(svctag):
""" look up and return system info"""
url = 'http://xserv.dell.com/services/assetservice.asmx?WSDL'
client = Client(url, location=url)
res = client.service.GetAssetInformation(uuid,
'check_dell_warranty',
svctag)
if res == '':
print 'error: error retrieving system information from Dell'
sys.exit(3)
hdrdata = res['Asset'][0]['AssetHeaderData']
ent = res['Asset'][0]['Entitlements'][0]
systype = hdrdata['SystemType']
sysmodel = hdrdata['SystemModel']
warrs = []
for i in ent:
if i is None:
continue
warrs.append(i['EndDate'])
warrs.sort()
endwarranty = warrs[-1]
return systype, sysmodel, svctag, endwarranty.strftime('%m/%d/%Y')
# main
if __name__ == "__main__":
(systype, sysmodel, svctag, endw) = get_asset_info(svctag)
# calculate days between now and warranty expiration
now = datetime.now()
endwtime = datetime.strptime(endw, '%m/%d/%Y')
daysend = int((endwtime - now).days)
# expired
if daysend <= 0:
print 'The warranty for', systype, sysmodel, 'with service tag', \
svctag, 'expired', abs(daysend), 'days ago on', endw
sys.exit(2)
# about to expire
elif daysend <= dayscrit:
print 'The warranty for', systype, sysmodel, 'with service tag', \
svctag, 'expires in', daysend, 'days on', endw
sys.exit(2)
# expires soon
elif daysend <= dayswarn:
print 'The warranty for', systype, sysmodel, 'with service tag', \
svctag, 'expires in', daysend, 'days on', endw
sys.exit(1)
# gravy
else:
print 'The warranty for', systype, sysmodel, 'with service tag', \
svctag, 'expires in', daysend, 'days on', endw
sys.exit(0)