monitors:dell-warranty

Error loading plugin struct
ParseError: syntax error, unexpected 'fn' (T_STRING), expecting :: (T_PAAMAYIM_NEKUDOTAYIM)
More info is available in the error log.

My Monitor (CHANGEME)

Author Butch Deal
Compatibility Xymon 4.2
Requirements Linux, python, dmidecode
Download None
Last Update 2009-06-02

Check the Dell service tag against the Dell website to see how many days are remaining of warranty.

returns this information:

Warranty start date: 12/8/2008
End Date: 1/17/2010
Days Left : 229 green
Serial Number: C2T8L61

Client side

Configure sudo so that dmidecode can be run. add these lines to the clientlaunch.cfg file:

[warranty]
	ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg
	CMD $HOBBITCLIENTHOME/ext/check_dell_warranty.py
	LOGFILE $HOBBITCLIENTHOME/logs/check-warranty.log
	INTERVAL 1d

Server side

Show Code ⇲

Hide Code ⇱

#!/usr/bin/env python

#=============================================================================
# Nagios plugin to pull the Dell service tag and check it 
# against Dell's website to see how many days remain. By default it 
# issues a warning when there is less than thirty days remaining and critical when 
# there is less than ten days remaining. These values can be adjusted using
# the command line, see --help.                                                 
# Version: 1.1                                                                
# Created: 2009-02-12                                                         
# Author: Erinn Looney-Triggs                                                 
# Revised: 2009-05-27                                                                
# Revised by: Erinn Looney-Triggs                                                                 
# Revision history:
# 1.1 Fixed string conversions to do int comparisons properly. Remove import
# csv as I am not using that yet. Add a license to the file.  
# License:
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
#  Ported to Xymon by Butch Deal of GreenIT Corp.
# needs sudo dmidecode capabilities for serial number
#  sudo dmidecode -s system-serial-number
#
# add these lines to  etc/clientlaunch.cfg
#  [warranty]
#        ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg
#        CMD $HOBBITCLIENTHOME/ext/check_dell_warranty.py
#        LOGFILE $HOBBITCLIENTHOME/logs/check-warranty.log
#        INTERVAL 1d
#
#                                       
#=============================================================================

import re
import subprocess
import sys
import urllib2

# converted to Xymon
LINE = ""

def extract_serial_number():
    '''Extracts the serial number from the localhost using dmidecode.
    
    This function takes no arguments but expects dmidecode to exist and
    also expects dmidecode to accept -s system-serial-number
    
    '''
    
    #Gather the information from dmidecode
    try:
        p = subprocess.Popen(["sudo", "dmidecode", "-s",
                               "system-serial-number"], 
                               stdout=subprocess.PIPE, 
                               stderr=subprocess.PIPE)
    except OSError:
        print 'Error:', sys.exc_value, 'exiting!'
        sys.exit(1)
    
    #Strip the newline off of result
    serial_number = p.stdout.read()
    
    #Basic check of the serial number, can they be longer, maybe
    if len( serial_number.strip() ) != 7:
        print 'Invalid serial number:%s exiting!' % (serial_number)
        sys.exit(WARNING)
    
    return serial_number.strip()

def get_warranty(serial_number):
    global LINE
    #The URL to Dell's site
#    dell_url='http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&l=en&s=gen&ServiceTag='
    dell_url='http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?ServiceTag='

    #Regex to pull the information from Dell's site
    pattern=r""".*>                          #Match anything up to >
                (\d{1,2}/\d{1,2}/\d{4})<     #Match North American style date
                .*>(\d{1,2}/\d{1,2}/\d{4})<  #Match date, good for 8000 years
                .*>                          #Match anything up to >
                (\d+)                        #Match number of days
                <.*                          #Match <and the rest of the line
                """
    
    #Build the full
    full_url = dell_url + serial_number
    LINE = LINE + full_url
    
    #Try to open the page, exit on failure
    try:
        response = urllib2.urlopen(full_url)
    except URLError:
        print 'Unable to open URL: %s exiting!' % (full_url)
        sys.exit(UNKNOWN)
    
    #Build our regex
    regex = re.compile(pattern, re.X)

    #Gather the results returns a list of tuples
    result = regex.findall(response.read())
    
    return result

def parse_exit(result):
    global LINE
    if len(result) == 0:
        print "Dell's database appears to be down for this system."
        sys.exit(WARNING)
    
    start_date, end_date, days_left = result[0]
    COLOR = "green"
    
    if int(days_left) < options.critical_days:
	COLOR = "red"
    elif int(days_left) < options.warning_days:
	COLOR = "yellow"
    else:
	COLOR = "green"
    LINE = LINE + "\nWarranty start date: " + start_date + "\nEnd Date: " + end_date + "\nDays Left : " + days_left + " &" + COLOR
    return COLOR
        
def sigalarm_handler(signum, frame):
    print '%s timed out after %d seconds' % (sys.argv[0], options.timeout)
    sys.exit(CRITICAL)
    
if __name__ == '__main__':
    import optparse
    import signal
    import os
    from datetime import date, datetime, timedelta

    BB = os.environ["BB"]
    BBDISP = os.environ["BBDISP"]
    MACHINE = os.environ["MACHINE"]

    parser = optparse.OptionParser(version="%prog 1.1")
    parser.add_option('-c', '--critical', dest='critical_days', default=10,
                     help='Number of days under which to return critical \
                     (Default: 10)', type='int')
    parser.add_option('-t', '--timeout', dest='timeout', default=10,
                      help='Set the timeout for the program to run \
                      (Default: 10 seconds)', type='int')
    parser.add_option('-w', '--warning', dest='warning_days', default=30,
                      help='Number of days under which to return a warning \
                      (Default: 30)', type='int' )
    
    (options, args) = parser.parse_args()
    
    signal.signal(signal.SIGALRM, sigalarm_handler)
    signal.alarm(options.timeout)
    
    serial_number = extract_serial_number()
    
    result = get_warranty(serial_number)
    
    signal.alarm(0)
    
    COLOR = parse_exit(result)

#    d = datetime.now() + timedelta(hours=24)
    d = datetime.now()
    P1 = "\"status+25h " + MACHINE + ".support " + COLOR + d.strftime(" %a %b %d %H:%M:%S %Z %Y") + " - \n" + LINE + "\nSerial Num
ber: " + serial_number + "\""
    LL = BB + " " + BBDISP + " " + P1
#    print '%s' % (LL)
    os.system(LL)

some servers have multiple lines of support on the dell site. the script only uses the bottom line though occasionally one of the other lines has longer support.

Someone that knows python could really clean this up and probably easily add some features. (please do).

  • Original Nagios author: Erinn Looney-Triggs
  • port to Xymon: Butch Deal
  • YYYY-MM-DD
    • Initial release
  • monitors/dell-warranty.txt
  • Last modified: 2009/11/23 05:43
  • by 127.0.0.1