1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
<?php
/**
*
* @author Christian Doebler <christian.doebler@netways.de>
*
*/
class IcingaApiConnectionFile extends IcingaApiConnection {
/*
* VARIABLES
*/
protected $inputFiles = array();
private $inputFilesCheck = array('status.dat', 'objects.cache', 'retention.dat');
/*
* METHODS
*/
/**
* class constructor
*
* @param void
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function __construct () {}
/**
* checks whether all defined files are accessible
*
* @param array $config associative array storing configuration
* @return boolean true if configuration is OK, false on error(s)
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function checkConfig (array $config) {
$configOk = true;
// loop through array of input files, check availability and add them to list of available ones
foreach ($this->inputFilesCheck as $currentFile) {
if (array_key_exists($currentFile, $config)) {
if (!file_exists($config[$currentFile]) ) {
throw new IcingaApiConnectionFileException('Configuration error: ' . $currentFile . ' not found!');
$configOk = false;
} elseif (!is_readable($config[$currentFile])) {
throw new IcingaApiConnectionFileException('Configuration error: ' . $currentFile . ' not readable!');
$configOk = false;
} else {
$this->inputFiles[$currentFile] = $config[$currentFile];
}
}
}
// perform global checks
$configOkParent = parent::checkConfig($config);
if (!$configOkParent && $configOk) {
$configOk = false;
}
return $configOk;
}
/**
* triggers config check and puts config into right place
* @param array $config associative array storing configuration
* @return boolean true on success otherwise false
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function setConfig (array $config) {
if (!$this->checkConfig($config)) {
return false;
}
$this->config = $config;
return $this;
}
/**
* right now just a dummy
* @param void
* @return void
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function connect () {
return $this;
}
/**
* calls initialization method for new search
*
* @param void
* @return IcingaApiSearchFile search object
* @author Christian Doebler <christian.doebler@netways.de>
*/
public function createSearch () {
$class = 'IcingaApiSearch' . $this->icingaType;
$searchObject = new $class;
$searchObject->setDebug($this->debug);
$searchObject->setInputFiles($this->config);
$searchObject->loadColumns($this->icingaType);
return $searchObject;
}
}
// extend exceptions
class IcingaApiConnectionFileException extends IcingaApiConnectionException {}
?>
|