no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | monitors:dell-warranty [2009/11/23 05:43] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== My Monitor (CHANGEME) ====== | ||
| + | |||
| + | ^ Author | [[ butchdeal@yahoo.com | Butch Deal ]] | | ||
| + | ^ Compatibility | Xymon 4.2 | | ||
| + | ^ Requirements | Linux, python, dmidecode | | ||
| + | ^ Download | None | | ||
| + | ^ Last Update | 2009-06-02 | | ||
| + | |||
| + | ===== Description ===== | ||
| + | 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 | ||
| + | </ | ||
| + | |||
| + | ===== Installation ===== | ||
| + | === Client side === | ||
| + | Configure sudo so that dmidecode can be run. | ||
| + | add these lines to the clientlaunch.cfg file: | ||
| + | < | ||
| + | [warranty] | ||
| + | ENVFILE $HOBBITCLIENTHOME/ | ||
| + | CMD $HOBBITCLIENTHOME/ | ||
| + | LOGFILE $HOBBITCLIENTHOME/ | ||
| + | INTERVAL 1d | ||
| + | </ | ||
| + | === Server side === | ||
| + | |||
| + | ===== Source ===== | ||
| + | ==== check_dell_warranty.py ==== | ||
| + | <hidden onHidden=" | ||
| + | < | ||
| + | # | ||
| + | |||
| + | # | ||
| + | # 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. | ||
| + | # GNU General Public License for more details. | ||
| + | # | ||
| + | # You should have received a copy of the GNU General Public License | ||
| + | # along with this program. | ||
| + | # | ||
| + | # | ||
| + | # 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/ | ||
| + | # [warranty] | ||
| + | # ENVFILE $HOBBITCLIENTHOME/ | ||
| + | # CMD $HOBBITCLIENTHOME/ | ||
| + | # LOGFILE $HOBBITCLIENTHOME/ | ||
| + | # INTERVAL 1d | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | import re | ||
| + | import subprocess | ||
| + | import sys | ||
| + | import urllib2 | ||
| + | |||
| + | # converted to Xymon | ||
| + | LINE = "" | ||
| + | |||
| + | def extract_serial_number(): | ||
| + | ''' | ||
| + | | ||
| + | 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([" | ||
| + | " | ||
| + | | ||
| + | | ||
| + | except OSError: | ||
| + | print ' | ||
| + | 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 ' | ||
| + | sys.exit(WARNING) | ||
| + | | ||
| + | return serial_number.strip() | ||
| + | |||
| + | def get_warranty(serial_number): | ||
| + | global LINE | ||
| + | #The URL to Dell's site | ||
| + | # dell_url=' | ||
| + | dell_url=' | ||
| + | |||
| + | #Regex to pull the information from Dell's site | ||
| + | pattern=r""" | ||
| + | (\d{1, | ||
| + | .*> | ||
| + | .*> | ||
| + | (\d+) #Match number of days | ||
| + | < | ||
| + | """ | ||
| + | | ||
| + | #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 ' | ||
| + | sys.exit(UNKNOWN) | ||
| + | | ||
| + | #Build our regex | ||
| + | regex = re.compile(pattern, | ||
| + | |||
| + | #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 " | ||
| + | sys.exit(WARNING) | ||
| + | | ||
| + | start_date, end_date, days_left = result[0] | ||
| + | COLOR = " | ||
| + | | ||
| + | if int(days_left) < options.critical_days: | ||
| + | COLOR = " | ||
| + | elif int(days_left) < options.warning_days: | ||
| + | COLOR = " | ||
| + | else: | ||
| + | COLOR = " | ||
| + | LINE = LINE + " | ||
| + | return COLOR | ||
| + | | ||
| + | def sigalarm_handler(signum, | ||
| + | print '%s timed out after %d seconds' | ||
| + | sys.exit(CRITICAL) | ||
| + | | ||
| + | if __name__ == ' | ||
| + | import optparse | ||
| + | import signal | ||
| + | import os | ||
| + | from datetime import date, datetime, timedelta | ||
| + | |||
| + | BB = os.environ[" | ||
| + | BBDISP = os.environ[" | ||
| + | MACHINE = os.environ[" | ||
| + | |||
| + | parser = optparse.OptionParser(version=" | ||
| + | parser.add_option(' | ||
| + | | ||
| + | | ||
| + | parser.add_option(' | ||
| + | help=' | ||
| + | (Default: 10 seconds)', | ||
| + | parser.add_option(' | ||
| + | help=' | ||
| + | (Default: 30)', type=' | ||
| + | | ||
| + | (options, args) = parser.parse_args() | ||
| + | | ||
| + | signal.signal(signal.SIGALRM, | ||
| + | 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 = " | ||
| + | ber: " + serial_number + " | ||
| + | LL = BB + " " + BBDISP + " " + P1 | ||
| + | # print ' | ||
| + | os.system(LL) | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Known Bugs and Issues ===== | ||
| + | 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. | ||
| + | ===== To Do ===== | ||
| + | Someone that knows python could really clean this up and probably easily add some features. (please do). | ||
| + | ===== Credits ===== | ||
| + | * Original Nagios author: Erinn Looney-Triggs | ||
| + | * port to Xymon: Butch Deal | ||
| + | ===== Changelog ===== | ||
| + | |||
| + | * **YYYY-MM-DD** | ||
| + | * Initial release | ||