4 /* This script produces a plain-text version of the expirations report and
5 * emails it to the specified address unless the report contains no objects.
6 * It is intended to be run from command line as daily or weekly cron job.
8 * Tested to work with RackTables 0.20.8.
11 $mail_to = 'Admin <admin@example.com>';
12 $mail_from = 'RackTables <racktables@example.com>';
13 $mail_subject = 'RackTables expirations report';
17 require '/usr/local/racktables/wwwroot/inc/init.php';
19 $mail_text = getExpirationsText();
21 mail ($mail_to, $mail_subject, $mail_text, "From: ${mail_from}");
24 function getExpirationsText()
26 $row_format = "%3s|%-30s|%-15s|%-15s|%s\r\n";
29 $breakdown[21] = array
31 array ('from' => -365, 'to' => 0, 'title' => 'has expired within last year'),
32 array ('from' => 0, 'to' => 30, 'title' => 'expires within 30 days'),
33 // array ('from' => 30, 'to' => 60, 'title' => 'expires within 60 days'),
34 // array ('from' => 60, 'to' => 90, 'title' => 'expires within 90 days'),
36 $breakdown[22] = $breakdown[21];
37 $breakdown[24] = $breakdown[21];
38 $attrmap = getAttrMap();
39 foreach ($breakdown as $attr_id => $sections)
41 $ret .= $attrmap[$attr_id]['name'] . "\r\n";
42 $ret .= "===========================================\r\n";
43 foreach ($sections as $section)
46 $result = scanAttrRelativeDays ($attr_id, $section['from'], $section['to']);
47 if (! count ($result))
50 $ret .= $section['title'] . "\r\n";
51 $ret .= "-----------------------------------------------------------------------------------\r\n";
52 $ret .= sprintf ($row_format, '#', 'Name', 'Asset Tag', 'OEM S/N 1', 'Date Warranty Expires');
53 $ret .= "-----------------------------------------------------------------------------------\r\n";
54 foreach ($result as $row)
56 $object = spotEntity ('object', $row['object_id']);
57 $attributes = getAttrValues ($object['id']);
64 array_key_exists (1, $attributes) ?
$attributes[1]['a_value'] : '',
65 datetimestrFromTimestamp ($row['uint_value'])
69 $ret .= "-----------------------------------------------------------------------------------\r\n";