- Timestamp:
- Mar 31, 2010, 1:32:46 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/config.php
r7633 r7637 18 18 19 19 /* 20 * This files we need to include, we do this is init.php 20 * This files we require for our application 21 * We include the files in init.php 21 22 */ 22 23 $config['require'] = array(); -
trunk/src/inc/ErrorHandler.php
r7631 r7637 8 8 /* 9 9 * PHP errors: 10 * E_ERROR ( integer ) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. 11 * E_WARNING ( integer ) Run-time warnings (non-fatal errors). Execution of the script is not halted. 12 * E_PARSE ( integer ) Compile-time parse errors. Parse errors should only be generated by the parser. 13 * E_NOTICE ( integer ) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. 10 * E_ERROR ( integer ) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. 11 * E_WARNING ( integer ) Run-time warnings (non-fatal errors). Execution of the script is not halted. 12 * E_PARSE ( integer ) Compile-time parse errors. Parse errors should only be generated by the parser. 13 * E_NOTICE ( integer ) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. 14 14 * E_CORE_ERROR ( integer ) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP. since PHP 4 15 15 * E_CORE_WARNING ( integer ) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP. since PHP 4 … … 21 21 * E_STRICT ( integer ) Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. since PHP 5 22 22 * E_RECOVERABLE_ERROR ( integer ) Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR. since PHP 5.2.0 23 * E_DEPRECATED ( integer ) Run-time notices. Enable this to receive warnings about code that will not work in future versions. since PHP 5.3.024 * E_USER_DEPRECATED ( integer ) User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error(). since PHP 5.3.025 23 * E_ALL ( integer ) All errors and warnings, as supported, except of level E_STRICT in PHP < 6. 26 24 */ 27 25 28 26 /* 29 * Function: ErrorHandler27 * Function: NodeErrorHandler 30 28 * Parameters: int $errno, string $errstr, string $errfile, int $errline, array $errcontext 31 * Function: Handling with errors, decides what to do with it29 * Function: Handling with errors, decides what log level it is and send it to LogHandler 32 30 */ 33 function ErrorHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext) {31 function NodeErrorHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext) { 34 32 switch ($errno) { 35 33 case E_ERROR: 36 echo 'E_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 37 // TODO 38 break; 39 case E_WARNING: 40 echo 'E_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 41 // TODO 42 break; 43 case E_PARSE: 44 echo 'E_PARSE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 45 // TODO 46 break; 47 case E_NOTICE: 48 echo 'E_NOTICE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 49 // TODO 50 break; 34 trigger_log(SYSLOG_ERR, $errstr, $errfile, $errline); 35 break; 36 case E_WARNING: 37 trigger_log(SYSLOG_WARNING, $errstr, $errfile, $errline); 38 break; 39 case E_PARSE: 40 trigger_log(SYSLOG_ERR, $errstr, $errfile, $errline); 41 break; 42 case E_NOTICE: 43 trigger_log(SYSLOG_NOTICE, $errstr, $errfile, $errline); 44 break; 51 45 case E_CORE_ERROR: 52 echo 'E_CORE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 53 // TODO 54 break; 46 trigger_log(SYSLOG_ERR, $errstr, $errfile, $errline); 47 break; 55 48 case E_CORE_WARNING: 56 echo 'E_CORE_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 57 // TODO 58 break; 49 trigger_log(SYSLOG_WARNING, $errstr, $errfile, $errline); 50 break; 59 51 case E_COMPILE_ERROR: 60 echo 'E_COMPILE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 61 // TODO 62 break; 52 trigger_log(SYSLOG_ERR, $errstr, $errfile, $errline); 53 break; 63 54 case E_COMPILE_WARNING: 64 echo 'E_COMPILE_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 65 // TODO 66 break; 55 trigger_log(SYSLOG_WARNING, $errstr, $errfile, $errline); 56 break; 67 57 case E_USER_ERROR: 68 echo 'E_USER_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 69 // TODO 70 break; 58 trigger_log(SYSLOG_ERR, $errstr, $errfile, $errline); 59 break; 71 60 case E_USER_WARNING: 72 echo 'E_USER_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 73 // TODO 74 break; 61 trigger_log(SYSLOG_WARNING, $errstr, $errfile, $errline); 62 break; 75 63 case E_USER_NOTICE: 76 echo 'E_USER_NOTICE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 77 // TODO 78 break; 64 trigger_log(SYSLOG_NOTICE, $errstr, $errfile, $errline); 65 break; 79 66 case E_STRICT: 80 echo 'E_STRICT: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 81 // TODO 82 break; 67 trigger_log(SYSLOG_NOTICE, $errstr, $errfile, $errline); 68 break; 83 69 case E_RECOVERABLE_ERROR: 84 echo 'E_RECOVERABLE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 85 // TODO 86 break; 87 case E_DEPRECATED: 88 echo 'E_DEPRECATED: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 89 // TODO 90 break; 91 case E_USER_DEPRECATED: 92 echo 'E_USER_DEPRECATED: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 93 // TODO 94 break; 70 trigger_log(SYSLOG_ERR, $errstr, $errfile, $errline); 71 break; 95 72 default: 96 echo 'E_DEFAULT: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>'; 97 // TODO 98 break; 73 trigger_log(SYSLOG_NOTICE, $errstr, $errfile, $errline); 74 break; 99 75 } 100 76 … … 103 79 } 104 80 105 set_exception_handler(' ErrorHandler');81 set_exception_handler('NodeErrorHandler'); -
trunk/src/inc/FileHandler.class.php
r7631 r7637 16 16 public function __construct($filename) { 17 17 try { 18 trigger_log(SYSLOG_DEBUG, 'Opening the file "' . $filename . '"', __FILE__, __LINE__); 18 19 $handle = fopen($filename, 'r'); 20 21 trigger_log(SYSLOG_DEBUG, 'Reading from file "' . $filename . '"', __FILE__, __LINE__); 19 22 $this->file = ''; 20 23 while (!feof($handle)) { 21 24 $this->file .= fread($handle, 8192); 22 25 } 26 27 trigger_log(SYSLOG_DEBUG, 'Closing file "' . $filename . '"', __FILE__, __LINE__); 23 28 fclose($handle); 29 30 trigger_log(SYSLOG_INFO, 'Reading from file "' . $filename . '" is done', __FILE__, __LINE__); 24 31 } catch (Exception $err) { 25 32 // TODO: Better error description 26 trigger_ error();33 trigger_log(SYSLOG_ERR, 'Reading from file "' . $filename . '" failed', __FILE__, __LINE__); 27 34 } 28 35 } -
trunk/src/inc/KMLFile.class.php
r7632 r7637 55 55 </kml>'; 56 56 57 private$fileFirst = 'type,host_name,has_been_checked,check_execution_time,current_state,last_hard_state,last_check,problem_has_been_acknowledged';57 static $fileFirst = 'type,host_name,has_been_checked,check_execution_time,current_state,last_hard_state,last_check,problem_has_been_acknowledged'; 58 58 private $fileContent = array('string', 'string', 'integer', 'double', 'integer', 'integer', 'integer', 'integer'); 59 59 … … 94 94 95 95 public function parseFile($file) { 96 $fileContents = explode("\r\n", $ nodeStatus->getFile());96 $fileContents = explode("\r\n", $file); 97 97 98 if ($fileContents[0] != $this->fileFirst) { 99 // TODO: Better error description 100 trigger_error(); 98 if ($fileContents[0] != KMLFile::$fileFirst) { 99 trigger_log(LOG_WARNING, 'Contents of file do not match with template of first line', __FILE__, __LINE__); 101 100 } 102 101 … … 106 105 107 106 if (count($lineContent) != count($this->fileContent)) { 108 // TODO: Better error description 109 trigger_error(); 107 trigger_log(LOG_WARNING, 'Contents of file do not match with template of lines', __FILE__, __LINE__); 110 108 } 111 109 -
trunk/src/inc/KMLPlacemark.class.php
r7632 r7637 49 49 } 50 50 51 function setL ONGITUDE($newLONGITUDE) {52 $this->longitude = (double) $newL ONGITUDE;51 function setLongitude($newLongitude) { 52 $this->longitude = (double) $newLongitude; 53 53 } 54 54 55 function setL ATITUDE($newLATITUDE) {56 $this->latitude = (double) $newL ATITUDE;55 function setLatitude($newLatitude) { 56 $this->latitude = (double) $newLatitude; 57 57 } 58 58 -
trunk/src/inc/LogHandler.class.php
r7631 r7637 8 8 /* 9 9 * Log levels: 10 * LOG_EMERG System is unusable11 * LOG_ALERT Action must be taken immediately12 * LOG_CRIT Critical conditions13 * LOG_ERR Error conditions14 * LOG_WARNING Warning conditions15 * LOG_NOTICE Normal, but significant, condition16 * LOG_INFO Informational message17 * LOG_DEBUG Debug-level message10 * SYSLOG_EMERG System is unusable 11 * SYSLOG_ALERT Action must be taken immediately 12 * SYSLOG_CRIT Critical conditions 13 * SYSLOG_ERR Error conditions 14 * SYSLOG_WARNING Warning conditions 15 * SYSLOG_NOTICE Normal, but significant, condition 16 * SYSLOG_INFO Informational message 17 * SYSLOG_DEBUG Debug-level message 18 18 */ 19 20 define('SYSLOG_NONE', 0); 21 define('SYSLOG_EMERG', 1); 22 define('SYSLOG_ALERT', 2); 23 define('SYSLOG_CRIT', 3); 24 define('SYSLOG_ERR', 4); 25 define('SYSLOG_WARNING', 5); 26 define('SYSLOG_NOTICE', 6); 27 define('SYSLOG_INFO', 7); 28 define('SYSLOG_DEBUG', 8); 29 30 /* 31 * Actions on log levels 32 */ 33 define('LOG_LEVEL_ECHO', SYSLOG_DEBUG); 34 define('LOG_LEVEL_WRITE', SYSLOG_DEBUG); 35 define('LOG_LEVEL_MAIL', SYSLOG_DEBUG); 19 36 20 37 class LogHandler { 21 38 /* 22 * Function: LogHandler 39 * Function: __construct (constructor) 40 * Parameters: - 41 * Function: Creating a LogHandler object 42 */ 43 public function __construct() { 44 } 45 46 /* 47 * Function: logEntry 23 48 * Parameters: int $logno, string $logstr, string $logfile, int $logline 24 * Function: Handling with log entries, decides what to do with it 49 * Function: Handling with log entries, decides what to do with it 25 50 */ 26 public function LogHandler(int $logno, string $logstr, string $logfile, int $logline) { 51 public function logEntry($logno, $logstr, $logfile, $logline) { 52 $errorString = 'SysLog '; 53 27 54 switch ($logno) { 28 case LOG_EMERG: 29 echo 'LOG_EMERG: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 30 // TODO 55 case SYSLOG_EMERG: 56 $errorString = 'Emergency'; 31 57 break; 32 case LOG_ALERT: 33 echo 'LOG_ALERT: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 34 // TODO 58 case SYSLOG_ALERT: 59 $errorString = 'Alert'; 35 60 break; 36 case LOG_CRIT: 37 echo 'LOG_CRIT: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 38 // TODO 61 case SYSLOG_CRIT: 62 $errorString = 'Critical'; 39 63 break; 40 case LOG_ERR: 41 echo 'LOG_ERR: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 42 // TODO 64 case SYSLOG_ERR: 65 $errorString = 'Error'; 43 66 break; 44 case LOG_WARNING: 45 echo 'LOG_WARNING: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 46 // TODO 67 case SYSLOG_WARNING: 68 $errorString = 'Warning'; 47 69 break; 48 case LOG_NOTICE: 49 echo 'LOG_NOTICE: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 50 // TODO 70 case SYSLOG_NOTICE: 71 $errorString = 'Notice'; 51 72 break; 52 case LOG_INFO: 53 echo 'LOG_INFO: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 54 // TODO 73 case SYSLOG_INFO: 74 $errorString = 'Information'; 55 75 break; 56 case LOG_DEBUG: 57 echo 'LOG_DEBUG: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 58 // TODO 76 case SYSLOG_DEBUG: 77 $errorString = 'Debug'; 59 78 break; 60 79 default: 61 echo 'LOG_DEFAULT: ' , $logno , ': ' , $logstr , '<br/>Bestand: ' , $logfile , '<br/>Regel: ' , $logline , '<br/>'; 62 // TODO 80 $errorString = 'SYSLOG_DEFAULT'; 63 81 break; 82 } 83 84 $errorString .= ' (' . $logno . '): ' . $logstr . "\r\n\t" . 'In file "' . $logfile . '" on line "' . $logline . '"' . "\r\n"; 85 86 if ($logno <= LOG_LEVEL_ECHO) { 87 echo $errorString; 88 } 89 if ($logno <= LOG_LEVEL_WRITE) { 90 // TODO: Write $errorString to file 91 } 92 if ($logno <= LOG_LEVEL_MAIL) { 93 // TODO: Mail $errorString to administrator 64 94 } 65 95 } 66 96 } 97 98 $LOG_HANDLER = new LogHandler(); 99 100 /* 101 * Function: trigger_log 102 * Parameters: int $logno, string $logstr, string $logfile, int $logline 103 * Function: Handling with log entries, forwarding them to our $LOG_HANDLER object. 104 */ 105 function trigger_log($logno, $logstr, $logfile, $logline) { 106 global $LOG_HANDLER; 107 108 $LOG_HANDLER->logEntry($logno, $logstr, $logfile, $logline); 109 } 67 110 ?> -
trunk/src/index.php
r7631 r7637 10 10 11 11 // Creating a placemark using our class 12 $kmlPlacemark = new KMLPlacemark(); 13 $kmlPlacemark->setName('Test name'); 14 $kmlPlacemark->setDescription('Test description'); 15 $kmlPlacemark->setXCoordinate(52.138476); 16 $kmlPlacemark->setYCoordinate(4.463046); 12 $kmlPlacemark1 = new KMLPlacemark(); 13 $kmlPlacemark1->setName('Test name'); 14 $kmlPlacemark1->setDescription('Test description'); 15 $kmlPlacemark1->setLatitude(52.138476); 16 $kmlPlacemark1->setLongitude(4.463046); 17 $kmlPlacemark1->setStyle(PLACEMARK_GREEN); 17 18 18 // Creating a KMLFile using our class, add our placemark and echo 19 // Creating a second placemark using our class 20 $kmlPlacemark2 = new KMLPlacemark(); 21 $kmlPlacemark2->setName('Placemark 2 name'); 22 $kmlPlacemark2->setDescription('This is the second placemark description'); 23 $kmlPlacemark2->setLatitude(52.638476); 24 $kmlPlacemark2->setLongitude(4.063046); 25 $kmlPlacemark2->setStyle(PLACEMARK_ORANGE); 26 27 // Creating a KMLFile using our class, add our placemarks and echo 19 28 $kml = new KMLFile(); 20 $kml->addPlacemark($kmlPlacemark); 29 $kml->addPlacemark($kmlPlacemark1); 30 $kml->addPlacemark($kmlPlacemark2); 21 31 echo $kml->toString(); 22 32 23 33 // Let's try to read the node status file 24 34 $nodeStatus = new FileHandler($config['node_status_file']); 25 $kmlFile = KMLFile::parseFile($nodeStatus );35 $kmlFile = KMLFile::parseFile($nodeStatus->getFile()); 26 36 ?>
Note:
See TracChangeset
for help on using the changeset viewer.