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: | Robert Peake | Date: | Tue, 29 Mar 2005 00:28:34 +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-30747@lists.php.net to get a copy of this message | ||
cyberscribe Mon Mar 28 19:28:34 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:
Implements changes proposed by Justin Patrin in his conditional vote
(http://pear.php.net/pepr/pepr-vote-show.php?id=171&handle=justinpatrin). Also fixes bug #3102
and implements a test for HTTPS. Monitor now uses references instead of variable copying for
manipulation of alerter and client objects, thereby reducing memory overhead (thanks to Ian Eure for
this suggestion). Finally, all tests are now in phpt format.
http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor.php diff -u pear/Net_Monitor/Monitor.php:1.1 pear/Net_Monitor/Monitor.php:1.2 --- pear/Net_Monitor/Monitor.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor.php Mon Mar 28 19:28:33 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Monitor.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: Monitor.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 * */ /** @@ -45,12 +45,26 @@ */ class Net_Monitor { - /**#@+ + /** + * Array of services to check + * * @access private - * @var array + * @var array $_services */ var $_services = array(); + /** + * Array of alerts to be sent + * + * @access private + * @var array $_alerts + */ var $_alerts = array(); + /** + * Array of options to be used in the current monitoring session + * + * @access private + * @var array $_options + */ var $_options = array('state_directory' => '/tmp/', 'state_file' => 'Net_Monitor_State', 'subject_line' => 'Net_Monitor Alert', @@ -58,29 +72,53 @@ 'notify_change' => 1, 'notify_ok' => 1 ); + /** + * Array of client objects to be used when testing a service + * + * @access private + * @var array $_clients + */ var $_clients = array(); + /** + * Array of alerter objects to be used when sending alerts + * + * @access private + * @var array $_alerters + */ var $_alerters = array(); + /** + * Array of results from most recent service check + * + * @access private + * @var array $_results + */ var $_results = array(); + /** + * Array of differences in results between previous session and this session + * + * @access private + * @var array $_results_diff + */ var $_results_diff = array(); - /**#@-*/ - + /** * function Net_Monitor * * @access public - * @param array services - * @param array alerts + * @param array $services + * @param array $alerts * @return void */ function Net_Monitor($services=array(),$alerts=array(),$options=array()) + { - if ($options && sizeof($options) > 0) { + if (is_array($options) && sizeof($options) > 0) { $this->setOptions($options); } - if ($services && sizeof($services) > 0) { + if (is_array($services) && sizeof($services) > 0) { $this->setServices($services); } - if ($alerts && sizeof($alerts) > 0) { + if (is_array($alerts) && sizeof($alerts) > 0) { $this->setAlerts($alerts); } } @@ -88,13 +126,14 @@ * function setOptions * * <p>Sets additional options for the class</p> - * <p>Merges input array with $_options</p> + * <p>Merges input array ($options) with $this->_options</p> * * @access public - * @param array options + * @param array $options * @return void */ function setOptions($options) + { foreach($options as $key => $value) { $this->_options[$key] = $value; @@ -104,7 +143,7 @@ * function setServices * * <p>Sets the services to monitor for the class</p> - * <p>Overwrites $_services with input array</p> + * <p>Overwrites $_services with input array ($services)</p> * <p>Net_Monitor_Services are of the form: <br /> * <pre> * $services = array('foo.example.com'=>array('SMTP','DNS'), @@ -112,10 +151,11 @@ * </pre> * * @access public - * @param array services + * @param array $services * @return void */ function setServices($services) + { $this->_services = $services; } @@ -123,17 +163,18 @@ * function setAlerts * * <p>Sets the alerts for the class</p> - * <p>Overwrites $_alerts with input array</p> + * <p>Overwrites $_alerts with input array ($alerts)</p> * <p>Net_Monitor_Alerts are of the form: <br /> * <pre> * $alerts = array('User1' => array('SMTP'=>'user1@example.com'), * 'User2' => array('SMTP'=>'user2@example.com')); * </pre> * - * @param array alerts + * @param array $alerts * @return void */ function setAlerts($alerts) + { $this->_alerts = $alerts; } @@ -146,6 +187,7 @@ * @return void */ function checkAll() + { //initialize the _results and _results_diff arrays $this->_results = array(); @@ -204,19 +246,20 @@ /** * function check * - * Check a single service on a single server + * Check a single service ($service) on a single server ($server) * * @access public - * @param mixed server - * @param string service + * @param mixed $server + * @param string $service * @return mixed */ function check($server,$service) + { - $client = $this->_clients[$service]; + $client =& $this->_clients[$service]; if (!is_object($client)) { //if an client has not yet been created for this service, create one - $this->client[$service] = $this->getClient($service); - $client = $this->_clients[$service]; + $this->client[$service] =& $this->getClient($service); + $client =& $this->_clients[$service]; } return $client->check($server); } @@ -230,6 +273,7 @@ * @return void */ function loadClients() + { $services_array = array_values($this->_services); $types_array = array_keys($this->_clients); @@ -251,8 +295,10 @@ * is only used once. * * @access public + * @return void */ function loadAlerters() + { $alerts_array = array_values($this->_alerts); $current_alerters = array_keys($this->_alerters); @@ -269,15 +315,16 @@ /** * function getClient * - * Returns a client of the specificed type. <em>Note: + * Returns a client of the type specified in $type. <em>Note: * does not check to see if this client has already been * loaded into Net_Monitor::clients - that is handled elsewhere.</em> * * @access private - * @param string type - * @return void + * @param string $type + * @return object */ - function getClient($type) + function &getClient($type) + { require_once "Net/Monitor/Service/$type.php"; $service = "Net_Monitor_Service_$type"; @@ -286,16 +333,17 @@ /** * function getAlerter * - * Returns an alerter of the specificed type. <em>Note: + * Returns an alerter of the type specified by $type. <em>Note: * does not check to see if this alerter has already been * loaded into Net_Monitor::alerters - that is handled elsewhere.</em> * * @access private - * @param string type - * @return void + * @param string $type + * @return object * */ - function getAlerter($type) + function &getAlerter($type) + { require_once "Net/Monitor/Alert/$type.php"; $alerter = "Net_Monitor_Alert_$type"; @@ -304,45 +352,49 @@ /** * function alert * - * Send a single alert of the specified method to the specified server + * Send a single alert specified in $method to the server specified in $server * * @access private - * @param string method + * @param string $method * @param mixed $server * */ function alert($method,$server) + { - $alerter = $this->_alerters[$method]; + $alerter =& $this->_alerters[$method]; if (!is_object($alerter)) { //if an alerter for this method has not already been created, create one - $this->_alerters[$method] = $this->getAlerter($method); - $alerter = $this->_alerters[$method]; + $this->_alerters[$method] =& $this->getAlerter($method); + $alerter =& $this->_alerters[$method]; } return $alerter->alert($server,$this->_results_diff,$this->_options); } /** * function saveState * - * Saves the current _results array to the directory specified in - * _options['state_directory'] as a file named _options['state_file']. - * If an array is passed to the function, that array is saved as state, + * Saves the current $_results array to the directory specified in + * $_options['state_directory'] as a file named $_options['state_file']. + * + * If an array ($results) is passed to the function, that array is saved as state, * otherwise this function acts upon $_results. * * @access public - * @param array results + * @param array $results * @return void * */ - function saveState($results = NULL) { + function saveState($results = null) + + { $options = $this->_options; $path = $options['state_directory']; $file = $options['state_file']; if (!is_writable($path)) { - Pear::raiseError($path.' is not writeable'); + PEAR::raiseError($path.' is not writeable'); } if (file_exists($path.$file)) { if (!is_writable($path.$file)) { - Pear::raiseError($path.$file.' exists but is not writeable'); + PEAR::raiseError($path.$file.' exists but is not writeable'); } } $fp = @fopen($path.$file,'w'); @@ -357,20 +409,22 @@ * function getState * * Retrieves previous state information from the directory specified in - * _options['state_directory'] via a file named _options['state_file'] + * $_options['state_directory'] via a file named $_options['state_file'] * * @access public * @return array * */ - function getState() { + function getState() + + { $my_line = ""; $options = $this->_options; $path = $options['state_directory']; $file = $options['state_file']; if (file_exists($path.$file)) { if (!is_readable($path.$file)) { - Pear::raiseError($path.$file.' exists but is not readable'); + PEAR::raiseError($path.$file.' exists but is not readable'); } } else { return array(); @@ -386,8 +440,8 @@ /** * function stateDiff * - * Computes the difference between a primary and secondary - * array representing state, i.e. all values in primary that + * Computes the difference between the $primary and $secondary + * arrays representing state, i.e. all values in primary that * are not already in secondary. * * Also returns an OK status for values in secondary that are @@ -403,7 +457,9 @@ * @param array secondary * @return array */ - function stateDiff($primary,$secondary) { + function stateDiff($primary,$secondary) + + { $return_array = array(); $sizeof_primary = sizeof($primary); $sizeof_secondary = sizeof($secondary); @@ -475,7 +531,9 @@ * @access public * @return boolean */ - function resetState() { + function resetState() + + { $this->_results = array(); $this->_results_diff = array(); $options = $this->_options; @@ -483,31 +541,34 @@ $file = $options['state_file']; if (file_exists($path.$file)) { if (!is_writable($path.$file)) { - Pear::raiseError($path.$file.' exists but is not writeable'); + PEAR::raiseError($path.$file.' exists but is not writeable'); } return unlink($path.$file); } else { return true; } - } - /** - * function resetHostState - * - * Resets the state for a single host. Optionally take in a - * second parameter, service, whereby the function only - * resets the results for that particular host/service test. - * - * @param string host - * @return void - * @access public - */ - function resetHostState($host,$service = NULL) { + } + /** + * function resetHostState + * + * Resets the state for a single host ($host). Optionally takes in a + * second parameter, $service, whereby the function only + * resets the results for that particular host/service test. + * + * @param string $host + * @param string $service + * @return void + * @access public + */ + function resetHostState($host,$service = null) + + { $last_state = $this->getState(); $sizeof_last_state = sizeof($last_state); for($i=0; $i < $sizeof_last_state; $i++) { $working_state = $last_state[$i]; if ($working_state['host'] == $host) { - if ($service != NULL && $working_state['service'] != $service) { + if ($service != null && $working_state['service'] != $service) { //hosts match but services don't match? place in new array $new_array[] = $working_state; } @@ -521,14 +582,16 @@ /** * function printAlert * - * Prints the alert specified in the associative array + * Prints the alert specified in the associative array ($array) * to STDOUT. Formats the alert according to $_options['alert_line']. * * @param array array * @return void * @access public */ - function printAlert($array) { + function printAlert($array) + + { if ($this->_options['alert_line']) { $alert_line = $this->_options['alert_line']; } else { http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Alert.php diff -u pear/Net_Monitor/Monitor/Alert.php:1.1 pear/Net_Monitor/Monitor/Alert.php:1.2 --- pear/Net_Monitor/Monitor/Alert.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Alert.php Mon Mar 28 19:28:33 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Alert.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: Alert.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * class Net_Monitor_Alert @@ -36,12 +36,30 @@ */ class Net_Monitor_Alert { + /** + * Defines the name of the service + * + * @var string $_service + * @access private + */ var $_service = 'Generic'; - var $_alert = NULL; + /** + * The alert object used for sending alerts + * + * @var object $_alert + * @access private + */ + var $_alert = null; /** * function alert * * Sends the specified results to the specified server + * <ul> + * <li> $server is the server to alert + * <li> $result is the array of results + * <li> $options is the array of additional options + * </ul> + * Does not return a value. * * @access private * @param mixed server @@ -49,6 +67,7 @@ * @return mixed */ function alert($server,$results,$options=array()) + { print "ALERT: $server ".$this->_service." not yet implemented\n"; print_r($results); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service.php diff -u pear/Net_Monitor/Monitor/Service.php:1.1 pear/Net_Monitor/Monitor/Service.php:1.2 --- pear/Net_Monitor/Monitor/Service.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service.php Mon Mar 28 19:28:33 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Service.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: Service.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * class Net_Monitor_Service @@ -37,32 +37,39 @@ class Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'Generic'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; /** * function check * - * Checks the specified server for availability. + * Checks the specified server ($server) for availability. * Returns false on success, or a notification array on failure. * * @param mixed server * @return mixed */ function check($server) + { - return array('host' => $server, 'service' => $this->_service, 'message' => "not yet implemented", 'code' => -1); + return array('host' => $server, 'service' => $this->_service, 'message' => 'Not yet implemented.', 'code' => -1); } } ?> http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert/SMS.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Alert/SMS.php diff -u pear/Net_Monitor/Monitor/Alert/SMS.php:1.1 pear/Net_Monitor/Monitor/Alert/SMS.php:1.2 --- pear/Net_Monitor/Monitor/Alert/SMS.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Alert/SMS.php Mon Mar 28 19:28:33 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMS.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: SMS.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * requires and extends the Net_Monitor_Alert class @@ -44,21 +44,26 @@ class Net_Monitor_Alert_SMS extends Net_Monitor_Alert { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'SMS'; /** - * @var object _alert + * The alert object to be used + * + * @var object $_alert * @access private */ - var $_alert = NULL; + var $_alert = null; /** * function Net_Monitor_Alert_SMS * * @access public */ function Net_Monitor_Alert_SMS() + { $this->_alert = new Net_SMS(); } http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert/SMTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Alert/SMTP.php diff -u pear/Net_Monitor/Monitor/Alert/SMTP.php:1.1 pear/Net_Monitor/Monitor/Alert/SMTP.php:1.2 --- pear/Net_Monitor/Monitor/Alert/SMTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Alert/SMTP.php Mon Mar 28 19:28:33 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: SMTP.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * requires and extends the Net_Monitor_Alert class @@ -46,21 +46,26 @@ class Net_Monitor_Alert_SMTP extends Net_Monitor_Alert { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'SMTP'; /** - * @var object _alert + * The alert object to be used + * + * @var object $_alert * @access private */ - var $_alert = NULL; + var $_alert = null; /** * function Net_Monitor_Alert_SMTP * * @access public */ function Net_Monitor_Alert_SMTP() + { $this->_alert = new Net_SMTP(); } @@ -68,6 +73,11 @@ * function alert * * Sends the specified results to the specified SMTP server + * <ul> + * <li> $server is the SMTP server + * <li> $results is the array of results to send + * </ul> + * Returns true on success, PEAR_Error object on failure * * @access private * @param mixed server @@ -75,11 +85,12 @@ * @return mixed */ function alert($server,$result_array,$options=array()) + { if ($options['subject_line']) { $subject = $options['subject_line']; } else { - Pear::raiseError('Using default subject', NULL, PEAR_ERROR_EXCEPTION, E_USER_WARNING); + PEAR::raiseError('Using default subject', null, PEAR_ERROR_EXCEPTION, E_USER_WARNING); $subject = 'Net_Monitor Alert'; } $server_array = explode('@',$server); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/DNS.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/DNS.php diff -u pear/Net_Monitor/Monitor/Service/DNS.php:1.1 pear/Net_Monitor/Monitor/Service/DNS.php:1.2 --- pear/Net_Monitor/Monitor/Service/DNS.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/DNS.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: DNS.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: DNS.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** @@ -46,17 +46,23 @@ class Net_Monitor_Service_DNS extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'DNS'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -66,19 +72,21 @@ * @access public */ function Net_Monitor_Service_DNS() + { $this->_client = new Net_DNS_Resolver(); } /** * function check * - * Checks the specified DNS server for availability. + * Checks the specified DNS server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $c = $this->_client; $c->nameservers = array($host); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/FTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/FTP.php diff -u pear/Net_Monitor/Monitor/Service/FTP.php:1.1 pear/Net_Monitor/Monitor/Service/FTP.php:1.2 --- pear/Net_Monitor/Monitor/Service/FTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/FTP.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: FTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: FTP.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** @@ -46,17 +46,23 @@ class Net_Monitor_Service_FTP extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'FTP'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -66,23 +72,25 @@ * @access public */ function Net_Monitor_Service_FTP() + { $this->_client = new Net_FTP(); } /** * function check * - * Checks the specified FTP server for availability. + * Checks the specified FTP server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $c = $this->_client; $e = $c->connect($host); - if (!Pear::isError($e)) { + if (!PEAR::isError($e)) { $this->_last_code = '200'; return false; } else { http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/HTTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/HTTP.php diff -u pear/Net_Monitor/Monitor/Service/HTTP.php:1.1 pear/Net_Monitor/Monitor/Service/HTTP.php:1.2 --- pear/Net_Monitor/Monitor/Service/HTTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/HTTP.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: HTTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: HTTP.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** * require and extend the Net_Monitor_Service class @@ -45,17 +45,23 @@ class Net_Monitor_Service_HTTP extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'HTTP'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -70,19 +76,21 @@ * @access public */ function Net_Monitor_Service_HTTP() + { $this->_client = new HTTP_Request(); } /** * function check * - * Checks the specified HTTP (web) server for availability. + * Checks the specified HTTP server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $response = 0; $full_host = $this->_prefix.$host; http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/HTTPS.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/HTTPS.php diff -u pear/Net_Monitor/Monitor/Service/HTTPS.php:1.1 pear/Net_Monitor/Monitor/Service/HTTPS.php:1.2 --- pear/Net_Monitor/Monitor/Service/HTTPS.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/HTTPS.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: HTTPS.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: HTTPS.php,v 1.2 2005/03/29 00:28:34 cyberscribe Exp $ // // Remote service monitor /** @@ -23,12 +23,12 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.6 (proposal) + * @version 0.0.7 */ /** * require and extend the Net_Monitor_Service_HTTP class by re-implementing the prepare() method */ -require_once 'Net/Monitor/HTTP.php'; +require_once 'Net/Monitor/Service/HTTP.php'; /** * class Net_Monitor_Service_HTTPS * @@ -41,12 +41,16 @@ class Net_Monitor_Service_HTTPS extends Net_Monitor_Service_HTTP { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'HTTPS'; /** - * @var string _prefix + * The prefix used to form a fully-qualified URL + * + * @var string $_prefix * @access public */ var $_prefix = 'https://'; @@ -56,6 +60,7 @@ * @access public */ function Net_Monitor_Service_HTTPS() + { if (!extension_loaded('openssl')) { PEAR::raiseError('Net_Monitor_Service_HTTPS requires OpenSSL'); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/SMTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/SMTP.php diff -u pear/Net_Monitor/Monitor/Service/SMTP.php:1.1 pear/Net_Monitor/Monitor/Service/SMTP.php:1.2 --- pear/Net_Monitor/Monitor/Service/SMTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/SMTP.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: SMTP.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** * require and extend the Net_Monitor_Service class @@ -45,17 +45,23 @@ class Net_Monitor_Service_SMTP extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'SMTP'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -65,31 +71,35 @@ * @access public */ function Net_Monitor_Service_SMTP() + { $this->_client = new Net_SMTP(); } /** * function check * - * Checks the specified SMTP (email delivery) server for availability. + * Checks the specified SMTP server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $response = 0; $this->_client = new Net_SMTP($host); - $c = $this->_client; + $c = $this->_client; $e = $c->connect(); - if (!PEAR::isError($e)) { //everything is OK + if (PEAR::isError($e)) { + //return connection-specific error string + $this->_last_code = $response; + return array('host' => $host, 'service' => $this->_service, 'message' => $e->getMessage(), 'code' => $response); + } else { + //everything is OK $c->disconnect(); - $this->_last_code = 200; //set last code to 200 + $this->_last_code = 200; //set last code to 200 return false; //false signifies no problem - } else { //return connection-specific error string - $this->_last_code = $response; - return array('host' => $host, 'service' => $this->_service, 'message' => $e->getMessage(), 'code' => $response); } } }
http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor.php diff -u pear/Net_Monitor/Monitor.php:1.1 pear/Net_Monitor/Monitor.php:1.2 --- pear/Net_Monitor/Monitor.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor.php Mon Mar 28 19:28:33 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Monitor.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: Monitor.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 * */ /** @@ -45,12 +45,26 @@ */ class Net_Monitor { - /**#@+ + /** + * Array of services to check + * * @access private - * @var array + * @var array $_services */ var $_services = array(); + /** + * Array of alerts to be sent + * + * @access private + * @var array $_alerts + */ var $_alerts = array(); + /** + * Array of options to be used in the current monitoring session + * + * @access private + * @var array $_options + */ var $_options = array('state_directory' => '/tmp/', 'state_file' => 'Net_Monitor_State', 'subject_line' => 'Net_Monitor Alert', @@ -58,29 +72,53 @@ 'notify_change' => 1, 'notify_ok' => 1 ); + /** + * Array of client objects to be used when testing a service + * + * @access private + * @var array $_clients + */ var $_clients = array(); + /** + * Array of alerter objects to be used when sending alerts + * + * @access private + * @var array $_alerters + */ var $_alerters = array(); + /** + * Array of results from most recent service check + * + * @access private + * @var array $_results + */ var $_results = array(); + /** + * Array of differences in results between previous session and this session + * + * @access private + * @var array $_results_diff + */ var $_results_diff = array(); - /**#@-*/ - + /** * function Net_Monitor * * @access public - * @param array services - * @param array alerts + * @param array $services + * @param array $alerts * @return void */ function Net_Monitor($services=array(),$alerts=array(),$options=array()) + { - if ($options && sizeof($options) > 0) { + if (is_array($options) && sizeof($options) > 0) { $this->setOptions($options); } - if ($services && sizeof($services) > 0) { + if (is_array($services) && sizeof($services) > 0) { $this->setServices($services); } - if ($alerts && sizeof($alerts) > 0) { + if (is_array($alerts) && sizeof($alerts) > 0) { $this->setAlerts($alerts); } } @@ -88,13 +126,14 @@ * function setOptions * * <p>Sets additional options for the class</p> - * <p>Merges input array with $_options</p> + * <p>Merges input array ($options) with $this->_options</p> * * @access public - * @param array options + * @param array $options * @return void */ function setOptions($options) + { foreach($options as $key => $value) { $this->_options[$key] = $value; @@ -104,7 +143,7 @@ * function setServices * * <p>Sets the services to monitor for the class</p> - * <p>Overwrites $_services with input array</p> + * <p>Overwrites $_services with input array ($services)</p> * <p>Net_Monitor_Services are of the form: <br /> * <pre> * $services = array('foo.example.com'=>array('SMTP','DNS'), @@ -112,10 +151,11 @@ * </pre> * * @access public - * @param array services + * @param array $services * @return void */ function setServices($services) + { $this->_services = $services; } @@ -123,17 +163,18 @@ * function setAlerts * * <p>Sets the alerts for the class</p> - * <p>Overwrites $_alerts with input array</p> + * <p>Overwrites $_alerts with input array ($alerts)</p> * <p>Net_Monitor_Alerts are of the form: <br /> * <pre> * $alerts = array('User1' => array('SMTP'=>'user1@example.com'), * 'User2' => array('SMTP'=>'user2@example.com')); * </pre> * - * @param array alerts + * @param array $alerts * @return void */ function setAlerts($alerts) + { $this->_alerts = $alerts; } @@ -146,6 +187,7 @@ * @return void */ function checkAll() + { //initialize the _results and _results_diff arrays $this->_results = array(); @@ -204,19 +246,20 @@ /** * function check * - * Check a single service on a single server + * Check a single service ($service) on a single server ($server) * * @access public - * @param mixed server - * @param string service + * @param mixed $server + * @param string $service * @return mixed */ function check($server,$service) + { - $client = $this->_clients[$service]; + $client =& $this->_clients[$service]; if (!is_object($client)) { //if an client has not yet been created for this service, create one - $this->client[$service] = $this->getClient($service); - $client = $this->_clients[$service]; + $this->client[$service] =& $this->getClient($service); + $client =& $this->_clients[$service]; } return $client->check($server); } @@ -230,6 +273,7 @@ * @return void */ function loadClients() + { $services_array = array_values($this->_services); $types_array = array_keys($this->_clients); @@ -251,8 +295,10 @@ * is only used once. * * @access public + * @return void */ function loadAlerters() + { $alerts_array = array_values($this->_alerts); $current_alerters = array_keys($this->_alerters); @@ -269,15 +315,16 @@ /** * function getClient * - * Returns a client of the specificed type. <em>Note: + * Returns a client of the type specified in $type. <em>Note: * does not check to see if this client has already been * loaded into Net_Monitor::clients - that is handled elsewhere.</em> * * @access private - * @param string type - * @return void + * @param string $type + * @return object */ - function getClient($type) + function &getClient($type) + { require_once "Net/Monitor/Service/$type.php"; $service = "Net_Monitor_Service_$type"; @@ -286,16 +333,17 @@ /** * function getAlerter * - * Returns an alerter of the specificed type. <em>Note: + * Returns an alerter of the type specified by $type. <em>Note: * does not check to see if this alerter has already been * loaded into Net_Monitor::alerters - that is handled elsewhere.</em> * * @access private - * @param string type - * @return void + * @param string $type + * @return object * */ - function getAlerter($type) + function &getAlerter($type) + { require_once "Net/Monitor/Alert/$type.php"; $alerter = "Net_Monitor_Alert_$type"; @@ -304,45 +352,49 @@ /** * function alert * - * Send a single alert of the specified method to the specified server + * Send a single alert specified in $method to the server specified in $server * * @access private - * @param string method + * @param string $method * @param mixed $server * */ function alert($method,$server) + { - $alerter = $this->_alerters[$method]; + $alerter =& $this->_alerters[$method]; if (!is_object($alerter)) { //if an alerter for this method has not already been created, create one - $this->_alerters[$method] = $this->getAlerter($method); - $alerter = $this->_alerters[$method]; + $this->_alerters[$method] =& $this->getAlerter($method); + $alerter =& $this->_alerters[$method]; } return $alerter->alert($server,$this->_results_diff,$this->_options); } /** * function saveState * - * Saves the current _results array to the directory specified in - * _options['state_directory'] as a file named _options['state_file']. - * If an array is passed to the function, that array is saved as state, + * Saves the current $_results array to the directory specified in + * $_options['state_directory'] as a file named $_options['state_file']. + * + * If an array ($results) is passed to the function, that array is saved as state, * otherwise this function acts upon $_results. * * @access public - * @param array results + * @param array $results * @return void * */ - function saveState($results = NULL) { + function saveState($results = null) + + { $options = $this->_options; $path = $options['state_directory']; $file = $options['state_file']; if (!is_writable($path)) { - Pear::raiseError($path.' is not writeable'); + PEAR::raiseError($path.' is not writeable'); } if (file_exists($path.$file)) { if (!is_writable($path.$file)) { - Pear::raiseError($path.$file.' exists but is not writeable'); + PEAR::raiseError($path.$file.' exists but is not writeable'); } } $fp = @fopen($path.$file,'w'); @@ -357,20 +409,22 @@ * function getState * * Retrieves previous state information from the directory specified in - * _options['state_directory'] via a file named _options['state_file'] + * $_options['state_directory'] via a file named $_options['state_file'] * * @access public * @return array * */ - function getState() { + function getState() + + { $my_line = ""; $options = $this->_options; $path = $options['state_directory']; $file = $options['state_file']; if (file_exists($path.$file)) { if (!is_readable($path.$file)) { - Pear::raiseError($path.$file.' exists but is not readable'); + PEAR::raiseError($path.$file.' exists but is not readable'); } } else { return array(); @@ -386,8 +440,8 @@ /** * function stateDiff * - * Computes the difference between a primary and secondary - * array representing state, i.e. all values in primary that + * Computes the difference between the $primary and $secondary + * arrays representing state, i.e. all values in primary that * are not already in secondary. * * Also returns an OK status for values in secondary that are @@ -403,7 +457,9 @@ * @param array secondary * @return array */ - function stateDiff($primary,$secondary) { + function stateDiff($primary,$secondary) + + { $return_array = array(); $sizeof_primary = sizeof($primary); $sizeof_secondary = sizeof($secondary); @@ -475,7 +531,9 @@ * @access public * @return boolean */ - function resetState() { + function resetState() + + { $this->_results = array(); $this->_results_diff = array(); $options = $this->_options; @@ -483,31 +541,34 @@ $file = $options['state_file']; if (file_exists($path.$file)) { if (!is_writable($path.$file)) { - Pear::raiseError($path.$file.' exists but is not writeable'); + PEAR::raiseError($path.$file.' exists but is not writeable'); } return unlink($path.$file); } else { return true; } - } - /** - * function resetHostState - * - * Resets the state for a single host. Optionally take in a - * second parameter, service, whereby the function only - * resets the results for that particular host/service test. - * - * @param string host - * @return void - * @access public - */ - function resetHostState($host,$service = NULL) { + } + /** + * function resetHostState + * + * Resets the state for a single host ($host). Optionally takes in a + * second parameter, $service, whereby the function only + * resets the results for that particular host/service test. + * + * @param string $host + * @param string $service + * @return void + * @access public + */ + function resetHostState($host,$service = null) + + { $last_state = $this->getState(); $sizeof_last_state = sizeof($last_state); for($i=0; $i < $sizeof_last_state; $i++) { $working_state = $last_state[$i]; if ($working_state['host'] == $host) { - if ($service != NULL && $working_state['service'] != $service) { + if ($service != null && $working_state['service'] != $service) { //hosts match but services don't match? place in new array $new_array[] = $working_state; } @@ -521,14 +582,16 @@ /** * function printAlert * - * Prints the alert specified in the associative array + * Prints the alert specified in the associative array ($array) * to STDOUT. Formats the alert according to $_options['alert_line']. * * @param array array * @return void * @access public */ - function printAlert($array) { + function printAlert($array) + + { if ($this->_options['alert_line']) { $alert_line = $this->_options['alert_line']; } else { http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Alert.php diff -u pear/Net_Monitor/Monitor/Alert.php:1.1 pear/Net_Monitor/Monitor/Alert.php:1.2 --- pear/Net_Monitor/Monitor/Alert.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Alert.php Mon Mar 28 19:28:33 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Alert.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: Alert.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * class Net_Monitor_Alert @@ -36,12 +36,30 @@ */ class Net_Monitor_Alert { + /** + * Defines the name of the service + * + * @var string $_service + * @access private + */ var $_service = 'Generic'; - var $_alert = NULL; + /** + * The alert object used for sending alerts + * + * @var object $_alert + * @access private + */ + var $_alert = null; /** * function alert * * Sends the specified results to the specified server + * <ul> + * <li> $server is the server to alert + * <li> $result is the array of results + * <li> $options is the array of additional options + * </ul> + * Does not return a value. * * @access private * @param mixed server @@ -49,6 +67,7 @@ * @return mixed */ function alert($server,$results,$options=array()) + { print "ALERT: $server ".$this->_service." not yet implemented\n"; print_r($results); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service.php diff -u pear/Net_Monitor/Monitor/Service.php:1.1 pear/Net_Monitor/Monitor/Service.php:1.2 --- pear/Net_Monitor/Monitor/Service.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service.php Mon Mar 28 19:28:33 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: Service.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: Service.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * class Net_Monitor_Service @@ -37,32 +37,39 @@ class Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'Generic'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; /** * function check * - * Checks the specified server for availability. + * Checks the specified server ($server) for availability. * Returns false on success, or a notification array on failure. * * @param mixed server * @return mixed */ function check($server) + { - return array('host' => $server, 'service' => $this->_service, 'message' => "not yet implemented", 'code' => -1); + return array('host' => $server, 'service' => $this->_service, 'message' => 'Not yet implemented.', 'code' => -1); } } ?> http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert/SMS.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Alert/SMS.php diff -u pear/Net_Monitor/Monitor/Alert/SMS.php:1.1 pear/Net_Monitor/Monitor/Alert/SMS.php:1.2 --- pear/Net_Monitor/Monitor/Alert/SMS.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Alert/SMS.php Mon Mar 28 19:28:33 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMS.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: SMS.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * requires and extends the Net_Monitor_Alert class @@ -44,21 +44,26 @@ class Net_Monitor_Alert_SMS extends Net_Monitor_Alert { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'SMS'; /** - * @var object _alert + * The alert object to be used + * + * @var object $_alert * @access private */ - var $_alert = NULL; + var $_alert = null; /** * function Net_Monitor_Alert_SMS * * @access public */ function Net_Monitor_Alert_SMS() + { $this->_alert = new Net_SMS(); } http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Alert/SMTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Alert/SMTP.php diff -u pear/Net_Monitor/Monitor/Alert/SMTP.php:1.1 pear/Net_Monitor/Monitor/Alert/SMTP.php:1.2 --- pear/Net_Monitor/Monitor/Alert/SMTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Alert/SMTP.php Mon Mar 28 19:28:33 2005 @@ -16,7 +16,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: SMTP.php,v 1.2 2005/03/29 00:28:33 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.6 (proposal) + * @version 0.0.7 */ /** * requires and extends the Net_Monitor_Alert class @@ -46,21 +46,26 @@ class Net_Monitor_Alert_SMTP extends Net_Monitor_Alert { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'SMTP'; /** - * @var object _alert + * The alert object to be used + * + * @var object $_alert * @access private */ - var $_alert = NULL; + var $_alert = null; /** * function Net_Monitor_Alert_SMTP * * @access public */ function Net_Monitor_Alert_SMTP() + { $this->_alert = new Net_SMTP(); } @@ -68,6 +73,11 @@ * function alert * * Sends the specified results to the specified SMTP server + * <ul> + * <li> $server is the SMTP server + * <li> $results is the array of results to send + * </ul> + * Returns true on success, PEAR_Error object on failure * * @access private * @param mixed server @@ -75,11 +85,12 @@ * @return mixed */ function alert($server,$result_array,$options=array()) + { if ($options['subject_line']) { $subject = $options['subject_line']; } else { - Pear::raiseError('Using default subject', NULL, PEAR_ERROR_EXCEPTION, E_USER_WARNING); + PEAR::raiseError('Using default subject', null, PEAR_ERROR_EXCEPTION, E_USER_WARNING); $subject = 'Net_Monitor Alert'; } $server_array = explode('@',$server); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/DNS.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/DNS.php diff -u pear/Net_Monitor/Monitor/Service/DNS.php:1.1 pear/Net_Monitor/Monitor/Service/DNS.php:1.2 --- pear/Net_Monitor/Monitor/Service/DNS.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/DNS.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: DNS.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: DNS.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** @@ -46,17 +46,23 @@ class Net_Monitor_Service_DNS extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'DNS'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -66,19 +72,21 @@ * @access public */ function Net_Monitor_Service_DNS() + { $this->_client = new Net_DNS_Resolver(); } /** * function check * - * Checks the specified DNS server for availability. + * Checks the specified DNS server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $c = $this->_client; $c->nameservers = array($host); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/FTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/FTP.php diff -u pear/Net_Monitor/Monitor/Service/FTP.php:1.1 pear/Net_Monitor/Monitor/Service/FTP.php:1.2 --- pear/Net_Monitor/Monitor/Service/FTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/FTP.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: FTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: FTP.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** @@ -46,17 +46,23 @@ class Net_Monitor_Service_FTP extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'FTP'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -66,23 +72,25 @@ * @access public */ function Net_Monitor_Service_FTP() + { $this->_client = new Net_FTP(); } /** * function check * - * Checks the specified FTP server for availability. + * Checks the specified FTP server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $c = $this->_client; $e = $c->connect($host); - if (!Pear::isError($e)) { + if (!PEAR::isError($e)) { $this->_last_code = '200'; return false; } else { http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/HTTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/HTTP.php diff -u pear/Net_Monitor/Monitor/Service/HTTP.php:1.1 pear/Net_Monitor/Monitor/Service/HTTP.php:1.2 --- pear/Net_Monitor/Monitor/Service/HTTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/HTTP.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: HTTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: HTTP.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** * require and extend the Net_Monitor_Service class @@ -45,17 +45,23 @@ class Net_Monitor_Service_HTTP extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'HTTP'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -70,19 +76,21 @@ * @access public */ function Net_Monitor_Service_HTTP() + { $this->_client = new HTTP_Request(); } /** * function check * - * Checks the specified HTTP (web) server for availability. + * Checks the specified HTTP server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $response = 0; $full_host = $this->_prefix.$host; http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/HTTPS.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/HTTPS.php diff -u pear/Net_Monitor/Monitor/Service/HTTPS.php:1.1 pear/Net_Monitor/Monitor/Service/HTTPS.php:1.2 --- pear/Net_Monitor/Monitor/Service/HTTPS.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/HTTPS.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: HTTPS.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: HTTPS.php,v 1.2 2005/03/29 00:28:34 cyberscribe Exp $ // // Remote service monitor /** @@ -23,12 +23,12 @@ * @author Robert Peake <robert@peakepro.com> * @copyright 2004 * @license http://www.php.net/license/3_0.txt - * @version 0.0.6 (proposal) + * @version 0.0.7 */ /** * require and extend the Net_Monitor_Service_HTTP class by re-implementing the prepare() method */ -require_once 'Net/Monitor/HTTP.php'; +require_once 'Net/Monitor/Service/HTTP.php'; /** * class Net_Monitor_Service_HTTPS * @@ -41,12 +41,16 @@ class Net_Monitor_Service_HTTPS extends Net_Monitor_Service_HTTP { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'HTTPS'; /** - * @var string _prefix + * The prefix used to form a fully-qualified URL + * + * @var string $_prefix * @access public */ var $_prefix = 'https://'; @@ -56,6 +60,7 @@ * @access public */ function Net_Monitor_Service_HTTPS() + { if (!extension_loaded('openssl')) { PEAR::raiseError('Net_Monitor_Service_HTTPS requires OpenSSL'); http://cvs.php.net/diff.php/pear/Net_Monitor/Monitor/Service/SMTP.php?r1=1.1&r2=1.2&ty=u Index: pear/Net_Monitor/Monitor/Service/SMTP.php diff -u pear/Net_Monitor/Monitor/Service/SMTP.php:1.1 pear/Net_Monitor/Monitor/Service/SMTP.php:1.2 --- pear/Net_Monitor/Monitor/Service/SMTP.php:1.1 Mon Mar 28 19:25:58 2005 +++ pear/Net_Monitor/Monitor/Service/SMTP.php Mon Mar 28 19:28:34 2005 @@ -15,7 +15,7 @@ // | Author: Robert Peake <robert@peakepro.com> | // +----------------------------------------------------------------------+ // -// $Id: SMTP.php,v 1.1 2005/03/29 00:25:58 cyberscribe Exp $ +// $Id: SMTP.php,v 1.2 2005/03/29 00:28:34 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.6 (proposal) + * @version 0.0.7 */ /** * require and extend the Net_Monitor_Service class @@ -45,17 +45,23 @@ class Net_Monitor_Service_SMTP extends Net_Monitor_Service { /** - * @var string _service + * Defines the name of the service + * + * @var string $_service * @access private */ var $_service = 'SMTP'; /** - * @var object _client + * The client object used for testing + * + * @var object $_client * @access private */ - var $_client = NULL; + var $_client = null; /** - * @var int _last_code + * The last response code received + * + * @var int $_last_code * @access private */ var $_last_code = -1; @@ -65,31 +71,35 @@ * @access public */ function Net_Monitor_Service_SMTP() + { $this->_client = new Net_SMTP(); } /** * function check * - * Checks the specified SMTP (email delivery) server for availability. + * Checks the specified SMTP server ($host) for availability. * Returns false on success, or a notification array on failure. * * @param mixed host * @return mixed */ function check($host) + { $response = 0; $this->_client = new Net_SMTP($host); - $c = $this->_client; + $c = $this->_client; $e = $c->connect(); - if (!PEAR::isError($e)) { //everything is OK + if (PEAR::isError($e)) { + //return connection-specific error string + $this->_last_code = $response; + return array('host' => $host, 'service' => $this->_service, 'message' => $e->getMessage(), 'code' => $response); + } else { + //everything is OK $c->disconnect(); - $this->_last_code = 200; //set last code to 200 + $this->_last_code = 200; //set last code to 200 return false; //false signifies no problem - } else { //return connection-specific error string - $this->_last_code = $response; - return array('host' => $host, 'service' => $this->_service, 'message' => $e->getMessage(), 'code' => $response); } } }