cvs: pear /Net_Monitor Monitor.php /Net_Monitor/Monitor Alert.php Service.php /Net_Monitor/Monitor/Alert SMS.php SMTP.php
/Net_Monitor/Monitor/Service DNS.php FTP.php HTTP.php HTTPS.php SMTP.php

From: Date: Tue, 29 Mar 2005 00:33:49 +0000
Subject: cvs: pear /Net_Monitor Monitor.php /Net_Monitor/Monitor Alert.php Service.php /Net_Monitor/Monitor/Alert SMS.php SMTP.php
/Net_Monitor/Monitor/Service DNS.php FTP.php HTTP.php HTTPS.php SMTP.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-30749@lists.php.net to get a copy of this message
cyberscribe Mon Mar 28 19:33:49 2005 EDT Modified files: /pear/Net_Monitor Monitor.php /pear/Net_Monitor/Monitor Alert.php Service.php /pear/Net_Monitor/Monitor/Alert SMS.php SMTP.php /pear/Net_Monitor/Monitor/Service DNS.php FTP.php HTTP.php HTTPS.php SMTP.php Log: Net_SMTP has been completely rewritten to use the Mail class and accept additional server parameters

http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor.php diff -u pear/Net_Monitor/Monitor.php:1.3 pear/Net_Monitor/Monitor.php:1.4 --- pear/Net_Monitor/Monitor.php:1.3 Mon Mar 28 19:31:12 2005 +++ pear/Net_Monitor/Monitor.php Mon Mar 28 19:33:49 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Monitor.php,v 1.3 2005/03/29 00:31:12 cyberscribe Exp $ +// $Id: Monitor.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -29,7 +29,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 * */ /** http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Alert.php diff -u pear/Net_Monitor/Monitor/Alert.php:1.3 pear/Net_Monitor/Monitor/Alert.php:1.4 --- pear/Net_Monitor/Monitor/Alert.php:1.3 Mon Mar 28 19:31:12 2005 +++ pear/Net_Monitor/Monitor/Alert.php Mon Mar 28 19:33:49 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Alert.php,v 1.3 2005/03/29 00:31:12 cyberscribe Exp $ +// $Id: Alert.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -23,7 +23,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** * class Net_Monitor_Alert http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Service.php diff -u pear/Net_Monitor/Monitor/Service.php:1.3 pear/Net_Monitor/Monitor/Service.php:1.4 --- pear/Net_Monitor/Monitor/Service.php:1.3 Mon Mar 28 19:31:12 2005 +++ pear/Net_Monitor/Monitor/Service.php Mon Mar 28 19:33:49 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Service.php,v 1.3 2005/03/29 00:31:12 cyberscribe Exp $ +// $Id: Service.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -24,7 +24,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** * class Net_Monitor_Service http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert/SMS.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Alert/SMS.php diff -u pear/Net_Monitor/Monitor/Alert/SMS.php:1.3 pear/Net_Monitor/Monitor/Alert/SMS.php:1.4 --- pear/Net_Monitor/Monitor/Alert/SMS.php:1.3 Mon Mar 28 19:31:12 2005 +++ pear/Net_Monitor/Monitor/Alert/SMS.php Mon Mar 28 19:33:49 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMS.php,v 1.3 2005/03/29 00:31:12 cyberscribe Exp $ +// $Id: SMS.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -24,7 +24,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** * requires and extends the Net_Monitor_Alert class http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert/SMTP.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Alert/SMTP.php diff -u pear/Net_Monitor/Monitor/Alert/SMTP.php:1.3 pear/Net_Monitor/Monitor/Alert/SMTP.php:1.4 --- pear/Net_Monitor/Monitor/Alert/SMTP.php:1.3 Mon Mar 28 19:31:12 2005 +++ pear/Net_Monitor/Monitor/Alert/SMTP.php Mon Mar 28 19:33:49 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.3 2005/03/29 00:31:12 cyberscribe Exp $ +// $Id: SMTP.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -24,16 +24,16 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** * requires and extends the Net_Monitor_Alert class */ require_once 'Net/Monitor/Alert.php'; /** - * requires and uses the Net_SMTP class to send SMTP alerts + * requires and uses the Mail class to send SMTP alerts */ -require_once 'Net/SMTP.php'; +require_once 'Mail.php'; /** * class Net_Monitor_Alert_SMTP * @@ -67,14 +67,23 @@ function Net_Monitor_Alert_SMTP() { - $this->_alert = new Net_SMTP(); + } /** * function alert * * Sends the specified results to the specified SMTP server * <ul> - * <li> $server is the SMTP server + * <li> $server is the SMTP server as either an array or string. + * A string should be a fully qualified email address + * An array must contain an 'email' key and, optionally: + * <ul> + * <li> host - The server to connect. Default is localhost + * <li> port - The port to connect. Default is 25 + * <li> auth - Whether or not to use SMTP authentication. Default is FALSE + * <li> username - The username to use for SMTP authentication. + * <li> password - The password to use for SMTP authentication. + * </ul> * <li> $results is the array of results to send * </ul> * Returns true on success, PEAR_Error object on failure @@ -87,21 +96,56 @@ function alert($server,$result_array,$options=array()) { + $email = ''; $email_message = ''; + $headers = array(); + + //construct subject if ($options['subject_line']) { $subject = $options['subject_line']; } else { PEAR::raiseError('Using default subject', null, PEAR_ERROR_EXCEPTION, E_USER_WARNING); $subject = 'Net_Monitor Alert'; } - $server_array = explode('@',$server); - $rcpt = $server_array[0]; - $server_addr = $server_array[1]; - $this->_client = new Net_SMTP($server_addr); - $smtp_client = $this->_client; - if ($options['smtp_debug']) { - $smtp_client->setDebug(true); + $headers['Subject'] = $subject; + + //parse $server into $email and $params and + //set $this->_alert to the new Mail::factory() object + if (is_string($server)) { + $email = $server; + $this->_alert =& Mail::factory('smtp'); + } else if (is_array($server)) { + $params = array(); + $email = $server['email']; + if (is_string($server['host'])) { + $params['host'] = $server['host']; + } + if (is_int($server['port'])) { + $params['port'] = $server['port']; + } + if ($server['auth']) { + $params['auth'] = $server['auth']; + if (is_string($server['username'])) { + $params['username'] = $server['username']; + } + if (is_string($server['password'])) { + $params['password'] = $server['password']; + } + } + if (sizeof($params) > 0) { + $this->_alert =& Mail::factory('smtp',$params); + } else { + $this->_alert =& Mail::factory('smtp'); + } + } else { + PEAR::raiseEror('$server is not a string or array -- unable to send alert'); + return false; } + $headers['To'] = $email; + $headers['From'] = $email; + $smtp_client =& $this->_alert; + + //construct $email_message from $result_array $sizeof_result_array = sizeof($result_array); for ($i=0;$i<$sizeof_result_array;$i++) { $result = $result_array[$i]; @@ -120,14 +164,9 @@ $alert_line = str_replace('%c',$code,$alert_line); $email_message .= $alert_line."\r\n"; } - $smtp_client->quotedata($email_message); - $e = $smtp_client->connect(); - if (!PEAR::isError($e)) { - $e = $smtp_client->mailFrom($server); - $e = $smtp_client->rcptTo($server); - $e = $smtp_client->data('Subject: '.$subject."\r\n\r\n".$email_message); - $smtp_client->disconnect(); - } + + //send message and retun result + $e = $smtp_client->send($email, $headers, $email_message); if (PEAR::isError($e)) { return $e; } else { http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/DNS.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Service/DNS.php diff -u pear/Net_Monitor/Monitor/Service/DNS.php:1.3 pear/Net_Monitor/Monitor/Service/DNS.php:1.4 --- pear/Net_Monitor/Monitor/Service/DNS.php:1.3 Mon Mar 28 19:31:13 2005 +++ pear/Net_Monitor/Monitor/Service/DNS.php Mon Mar 28 19:33:49 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: DNS.php,v 1.3 2005/03/29 00:31:13 cyberscribe Exp $ +// $Id: DNS.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -23,7 +23,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/FTP.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Service/FTP.php diff -u pear/Net_Monitor/Monitor/Service/FTP.php:1.3 pear/Net_Monitor/Monitor/Service/FTP.php:1.4 --- pear/Net_Monitor/Monitor/Service/FTP.php:1.3 Mon Mar 28 19:31:13 2005 +++ pear/Net_Monitor/Monitor/Service/FTP.php Mon Mar 28 19:33:49 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: FTP.php,v 1.3 2005/03/29 00:31:13 cyberscribe Exp $ +// $Id: FTP.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -23,7 +23,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/HTTP.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Service/HTTP.php diff -u pear/Net_Monitor/Monitor/Service/HTTP.php:1.3 pear/Net_Monitor/Monitor/Service/HTTP.php:1.4 --- pear/Net_Monitor/Monitor/Service/HTTP.php:1.3 Mon Mar 28 19:31:13 2005 +++ pear/Net_Monitor/Monitor/Service/HTTP.php Mon Mar 28 19:33:49 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: HTTP.php,v 1.3 2005/03/29 00:31:13 cyberscribe Exp $ +// $Id: HTTP.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -23,7 +23,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** * require and extend the Net_Monitor_Service class http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/HTTPS.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Service/HTTPS.php diff -u pear/Net_Monitor/Monitor/Service/HTTPS.php:1.3 pear/Net_Monitor/Monitor/Service/HTTPS.php:1.4 --- pear/Net_Monitor/Monitor/Service/HTTPS.php:1.3 Mon Mar 28 19:31:13 2005 +++ pear/Net_Monitor/Monitor/Service/HTTPS.php Mon Mar 28 19:33:49 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: HTTPS.php,v 1.3 2005/03/29 00:31:13 cyberscribe Exp $ +// $Id: HTTPS.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -23,7 +23,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** * require and extend the Net_Monitor_Service_HTTP class by re-implementing the prepare() method http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/SMTP.php?r1=1.3&r2=1.4&ty=u Index: pear/Net_Monitor/Monitor/Service/SMTP.php diff -u pear/Net_Monitor/Monitor/Service/SMTP.php:1.3 pear/Net_Monitor/Monitor/Service/SMTP.php:1.4 --- pear/Net_Monitor/Monitor/Service/SMTP.php:1.3 Mon Mar 28 19:31:13 2005 +++ pear/Net_Monitor/Monitor/Service/SMTP.php Mon Mar 28 19:33:49 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.3 2005/03/29 00:31:13 cyberscribe Exp $ +// $Id: SMTP.php,v 1.4 2005/03/29 00:33:49 cyberscribe Exp $ // // Remote service monitor /** @@ -23,7 +23,7 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.7 + * @version 0.1.0 */ /** * require and extend the Net_Monitor_Service class
« previous php.pear.cvs (#30749) next »