Net_Monitor
[ class tree: Net_Monitor ] [ index: Net_Monitor ] [ all elements ]

Class: Net_Monitor

Source Location: /Net_Monitor-0.3.0/Net/Monitor.php

Class Overview


class Net_Monitor


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 40]
class Net_Monitor


[ Top ]


Class Variables

$_alerters = array()

[line 85]

Array of alerter objects to be used when sending alerts
  • Access: protected

Type:   array


[ Top ]

$_alerts = array()

[line 56]

Array of alerts to be sent organized by alerter protocols
  • Access: protected

Type:   array


[ Top ]

$_clients = array()

[line 77]

Array of client objects to be used when testing a service
  • Access: protected

Type:   array


[ Top ]

$_options = array('state_directory' => '/tmp/',
                          'state_file'      => 'Net_Monitor_State',
                          'subject_line'    => 'Net_Monitor Alert',
                          'alert_line'      => '%h: %s: %m',
                          'notify_change'   => 1,
                          'notify_ok'       => 1,
                          'smtp_debug'      => false)

[line 64]

Array of options to be used in the current monitoring session
  • Access: protected

Type:   array


[ Top ]

$_results = array()

[line 93]

Array of results from most recent service check
  • Access: protected

Type:   array


[ Top ]

$_services = array()

[line 48]

Array of services to check 'url' => array('services')
  • Access: protected

Type:   array


[ Top ]



Method Detail

__construct (Constructor)   [line 148]

void __construct( [array $services = array()], [array $alerts = array()], [array $options = array()])

function Net_Monitor
  • Access: public

Parameters:

array   $services     services to check 'url' => array('services') example: array('example.com' => array('SMTP', 'HTTP', 'HTTPS'), 'example.net' => array('DNS', 'FTP'))
array   $alerts     

alerts to be sent organized by alerter protocols as array('SMTP' => array(SMTP_adressees), 'SMS' => array(SMS_adressees)) If this array is empty, alerts will be only printed and nothing sent

SMTP_adressees is a simple string email, then $options['SMTP_default'] will be used to configure the SMTP sender, or can itself be an array of options for a prioritary adressee (useful to monitor SMTP itself) in this case, the adressee is the 'email' => 'email@adress.com' element. see Mail for these options

SMS_adressees is a simple string phone number, then $options['SMS_default'] will be used to configure the SMS sender, or can itself be an array of options for a prioritary adressee (useful to specify alternate provider) in this case, the adressee is the 'phone_number' => '0123456789' element. see Net_SMS for these options

array   $options     options to be used in the current monitoring session Options (default) are:
  • state_directory - the directory where the state file gets saved ('/tmp/')
  • state_file - the name of the state file ('Net_Monitor_State')
  • subject_line - the subject line of the alert message ('Net_Monitor Alert')
  • alert_line - the format string for the alert ('%h: %s: %m') where: %h = host %s = service %m = message %c = code
  • notify_change - send alerts only on state change (1)
  • notify_ok - send an alert when a service returns to a code 200 state (1)
  • smtp_debug - send debugging output to STDOUT for the SMTP alert (false)
  • from_email - who is the sender for the SMTP alert ('pear.Net_Monitor')
  • SMTP_default - array of options for Mail_SMTP used for normal adressees (array())
  • sms_debug - send debugging output to STDOUT for the SMS alert (false)
  • sms_from - who is the sender for the SMS alert, ('Net_Monitor')
  • SMS_default - array of options for Net_SMS used for normal adressees (array())

[ Top ]

alert   [line 420]

mixed alert( string $method, mixed $server)

function alert

Send a single alert specified in $method to the server specified in $server

  • Access: public

Parameters:

string   $method     Method
mixed   $server     Server

[ Top ]

check   [line 321]

mixed check( mixed $server, string $service)

function check

Check a single service ($service) on a single server ($server)

  • Access: public

Parameters:

mixed   $server     Host
string   $service     Service

[ Top ]

checkAll   [line 247]

void checkAll( )

function checkAll

Checks all services and sends all alerts.

  • Access: public

[ Top ]

getAlerter   [line 402]

object getAlerter( string $type)

function getAlerter

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: public

Parameters:

string   $type     Class / Type of alerter to fetch

[ Top ]

getClient   [line 383]

object getClient( string $type)

function getClient

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: public

Parameters:

string   $type     Class / Type of service to fetch

[ Top ]

getResults   [line 163]

void getResults( )

  • Access: public

[ Top ]

getState   [line 481]

array getState( )

function getState

Retrieves previous state information from the directory specified in $_options['state_directory'] via a file named $_options['state_file']

  • Access: public

[ Top ]

loadAlerters   [line 361]

void loadAlerters( )

function loadAlerters

Load alert objects into Net_Monitor so that each type of alert is only used once.

  • Access: public

[ Top ]

loadClients   [line 336]

void loadClients( )

function loadClients

Load all clients into the Net_Monitor object so that each type of service client is only instantiated once.

  • Access: public

[ Top ]

printAlert   [line 647]

void printAlert( string $host, string $service, array $result)

function printAlert

Prints the alert for a host/service to STDOUT. Formats the alert according to $_options['alert_line'].

  • Access: public

Parameters:

string   $host     Host name
string   $service     Service
array   $result     (code, message)

[ Top ]

resetHostState   [line 612]

void resetHostState( string $host, [mixed $service = null])

function resetHostState

Resets the state for a single host ($host). Optionally takes in a second parameter, $service which maybe an array, whereby the function only resets the results for that/those particular host/service test.

  • Access: public

Parameters:

string   $host     Host
mixed   $service     Service

[ Top ]

resetState   [line 579]

boolean resetState( )

function resetState

Resets the results and results differential arrays and deletes the state file.

Returns true if the file has been deleted or never existed in the first place; false otherwise.

  • Access: public

[ Top ]

saveState   [line 444]

void saveState( [array $results = null])

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 ($results) is passed to the function, that array is saved as state, otherwise this function acts upon $_results.

  • Access: public

Parameters:

array   $results     Results

[ Top ]

setAlerts   [line 227]

void setAlerts( array $alerts)

function setAlerts

Sets the alerts for the class

Overwrites $_alerts with input array ($alerts)

Net_Monitor_Alerts are of the form:

 $alerts = array('User1' => array('SMTP'=>'user1@example.com'),
                 'User2' => array('SMTP'=>'user2@example.com'));

  • Access: public

Parameters:

array   $alerts     Alerts

[ Top ]

setOptions   [line 184]

void setOptions( array $options)

function setOptions

Sets additional options for the class

Merges input array ($options) with $this->_options

  • Access: public

Parameters:

array   $options     Options to set

[ Top ]

setResults   [line 168]

void setResults( $results)

  • Access: public

Parameters:

   $results     

[ Top ]

setServices   [line 207]

void setServices( array $services)

function setServices

Sets the services to monitor for the class

Overwrites $_services with input array ($services)

Net_Monitor_Services are of the form:

 $services = array('foo.example.com'=>array('SMTP','DNS'),
                   'bar.example.com'=>array('HTTP','FTP','DNS'));

  • Access: public

Parameters:

array   $services     Services per domain

[ Top ]

stateDiff   [line 528]

array stateDiff( array $secondary)

function stateDiff

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 not in primary unless $_options['notify_ok'] is set to false.

Returns values in primary whose code value differs from values in secondary unless $_options['notify_change'] is set to false.

  • Access: public

Parameters:

array   $secondary     states to compare to current

[ Top ]


Documentation generated on Sun, 30 Mar 2014 14:30:04 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.