Class exec_monitor

Description

A monitor class to exec a script/program on the OS. This allows you

to hook up an external script or program to the monitoring system with the flexibility to determine success/failure by return code, or by comparing output with an expected (regex) pattern. The default test is to test the return code of the script/program and if it is zero (0), then the check is deemed to be successful, otherwise not. There is also a flag, in the constructor ($publish_output) which, if true, directs the monitor to include any output lines returned from the script in the email/SMS messages. This can sometimes be useful for providing extra information in error reports.

Located in /monitor-defs.php (line 198)

generic_monitor
   |
   --exec_monitor
Variable Summary
Method Summary
 exec_monitor exec_monitor (string $exec, [string $success_regex = ""], [boolean $publish_output = false])
 integer check ()
 void set_success_code (integer $code)
 void set_success_regex (mixed $success_regex, string $regex)
Variables
mixed $execparms = "" (line 200)
mixed $execpath = "" (line 199)
mixed $publish_output = false (line 203)
mixed $success_code = 0 (line 201)
mixed $success_regex = "" (line 202)
Methods
Constructor exec_monitor (line 211)

Define a new exec check object.

exec_monitor exec_monitor (string $exec, [string $success_regex = ""], [boolean $publish_output = false])
  • string $exec: Script/program to execute, including any parameters
  • string $success_regex: Regex to match on output of script/program
  • boolean $publish_output: Publish script/program output in all messages
check (line 255)

Make the check by executing the script/program which has been

specified. We check that this exists and is executable, and raise warnings if not. The success/failure of the check is determined by the settings, but is either done via return code or by returned output matching.

  • return: Condition determined by this check
integer check ()
set_success_code (line 233)

Allows you to specify an integer code which, if returned by the called script/program, will designate success.

NOTES: 1) The default code for success is already zero (0), so no need to specify it in that particular case. 2) This code will be over-ridden if you specify a regular expression with the set_success_pattern() method.

void set_success_code (integer $code)
  • integer $code: Return code indicating success
set_success_regex (line 244)

Allows you to specify a regular expression which will be applied to the output of the executed script/program and if matched will be taken to mean the check was successful. If specified, this takes the place of the default behaviour of checking the return code.

void set_success_regex (mixed $success_regex, string $regex)
  • string $regex: Regular expression to match on output for success

Documentation generated by phpDocumentor 1.3.0RC3