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.
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 .
*/
error_reporting('E_NONE');
function show_help(){
echo "
Nagios plugin - Dell warranty lookup
Copyright (C)2012 Jan Lachman
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.
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 .
Usage:
php dell_warranty_lookup.php [options] [param]
Example:
php dell_warranty_lookup.php --tag ABCDEFG -w 30 -c 10 -t 15
Options:
-h Show this help message :)
-S Dell Serial Tag
-t Set cURL timeout for connection (default is 10s)
-w Warning threshold
-c Critical threshold
-H Reserved (currently not used)
-v Verbose output level
Parameters:
-S SerialTag Specify your Dell Serial Tag
-t number Set cURL timeout for connection (default is 10 second)
-w number Number of days before warning threshold (default 30)
-c number Number of days before critical threshold (default 7)
-v 0 or 1 Level 0 will show only OK etc. Level 1 (default) will show some details
";
exit(0);
}
// function for getting informations from dell sites
function get_warranty($ServiceTag,$curl_timeout,$debug=false)
{
// this is hyperlink pointing to dell warranty lookup page - working from 3/2012
$dell_warranty_status_page ="http://www.dell.com"
."/support/troubleshooting/us/en/04/TroubleShooting"
."/Display_Warranty_Tab?name=TroubleShooting_WarrantyTab";
// dell sites needs to have cookie for lookup warranty status
$strCookie = "name=OLRProduct; OLRProduct=".$ServiceTag."|;";
// now, we construct cURL definition for connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $dell_warranty_status_page);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');
curl_setopt($ch, CURLOPT_COOKIE, $strCookie );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $curl_timeout);
/*
// if you need proxy feature for cURL, maybe you need lines below :)
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port); // $proxy_port = your proxy port (eq.: 3128 or 8080)
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip); // $proxy_ip = your proxy ip address
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw); // $loginpassw = your username and password (eq.: my_username:my_password)
*/
// for debug purpose only
if ($debug != false){
curl_setopt($ch, CURLOPT_VERBOSE, true);
}
// at this point, we have html result
$curl_html_output = curl_exec ($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
// if something wrong with cURL
if ($httpCode != 200){
echo "Unknown (cURL Response code: ".$httpCode.")";
exit(3);
}
// now we must remove href tag from cURL output
$curl_output = preg_replace('/(.*?)<\/a>/', "\\2", $curl_html_output);
// find the table from cURL output for creation the array
preg_match("/.*?<\/[\s]*table>/s", $curl_output, $table_html);
// get title for each row from cURL output for row headers
preg_match_all("/(.*?)<\/[\s]*th>/", $table_html[0], $matches);
$row_headers = $matches[0];
// separate each row form cURL output
preg_match_all("/(.*?)<\/[\s]*tr>/s", $table_html[0], $matches);
// array with result without htlm tags, that we must fill up with values
$dell_warranty_table = array();
// find html rows, remove html tags from row and fill up the array
foreach($matches[1] as $row_html)
{
preg_match_all("/(.*?)<\/[\s]*td>/", $row_html, $td_matches);
$row = array();
for($i=0; $i 0)
$dell_warranty_array[] = $row;
}
// like output we got array with html-clean keys and values like that:
/*
array
0 =>
array
'Services' => string '4 Hour Pro Support IT' (length=21)
'Provider' => string 'Dell' (length=4)
'Start Date' => string '5/28/2008' (length=9)
'End Date' => string '5/28/2013' (length=9)
'Days Remaining' => string '432' (length=3)
1 =>
array
'Services' => string 'Next Business Day' (length=17)
'Provider' => string 'Dell' (length=4)
'Start Date' => string '5/28/2008' (length=9)
'End Date' => string '5/28/2009' (length=9)
'Days Remaining' => string '0' (length=1)
*/
return $dell_warranty_array;
}
// Parse command line arguments
for($i=0;$i= $warning_level ){
if ($verbose_level==1){
echo "OK (".$ServiceTag.": ".max($days_remaining)." days)";
} else {
echo "OK";
}
exit(0);
}
?>