[icinga-checkins] icinga.org: icinga-api/mhein/default: * fixed livestatus output in search class

git at icinga.org git at icinga.org
Tue Jan 12 14:21:31 CET 2010


Module: icinga-api
Branch: mhein/default
Commit: 0d3d9a52e137ccf7c0e6bb3f7e530bf427a02dd2
URL:    https://git.icinga.org/?p=icinga-api.git;a=commit;h=0d3d9a52e137ccf7c0e6bb3f7e530bf427a02dd2

Author: Christian Doebler <christian.doebler at netways.de>
Date:   Wed Dec 23 10:48:22 2009 +0100

* fixed livestatus output in search class

---

 objects/result/IcingaApiResultLivestatus.php |    5 ++-
 objects/search/IcingaApiSearchLivestatus.php |   29 +++++++------------------
 2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/objects/result/IcingaApiResultLivestatus.php b/objects/result/IcingaApiResultLivestatus.php
index cda126f..70cd8c8 100644
--- a/objects/result/IcingaApiResultLivestatus.php
+++ b/objects/result/IcingaApiResultLivestatus.php
@@ -36,7 +36,6 @@ class IcingaApiResultLivestatus
 	 */
 	public function setSearchColumns (array $columns) {
 		$this->searchColumns = $columns;
-		$this->numResults = count($columns);
  		return $this;
 	}
 
@@ -48,8 +47,10 @@ class IcingaApiResultLivestatus
 	 * @author	Christian Doebler <christian.doebler at netways.de>
 	 */
 	public function setSearchResult (array $data) {
+var_dump($data);
 		$this->resultArray = $data;
- 		return $this;
+		$this->numResults = count($data);
+		return $this;
 	}
 
 	/**
diff --git a/objects/search/IcingaApiSearchLivestatus.php b/objects/search/IcingaApiSearchLivestatus.php
index 8c280a4..e9c40c3 100644
--- a/objects/search/IcingaApiSearchLivestatus.php
+++ b/objects/search/IcingaApiSearchLivestatus.php
@@ -91,16 +91,16 @@ class IcingaApiSearchLivestatus
 		$data = null;
 
 		while($offset < $length) {
-			if(($data = @socket_read($this->socket, $length - $offset)) === false) {
+			if(($dataTmp = @socket_read($this->socket, $length - $offset)) === false) {
 				$data = false;
 				break;
 			}
 
-			$dataLength = strlen($data);
+			$dataLength = strlen($dataTmp);
 
 			if ($dataLength) {
 				$offset += $dataLength;
-				$data .= $data;
+				$data .= $dataTmp;
 			} else {
 				break;
 			}
@@ -182,9 +182,9 @@ class IcingaApiSearchLivestatus
 	private function getQueryFilter () {
 		$filter = null;
 
-		$numAnd = count($this->searchFilter);
+		//$numAnd = count($this->searchFilter);
 
-		if ($numAnd) {
+		if (count($this->searchFilter)) {
 			foreach ($this->searchFilter as $column => $columnData) {
 				$numOr = 0;
 
@@ -213,9 +213,11 @@ class IcingaApiSearchLivestatus
 				}
 			}
 
+			/*
 			if ($numAnd > 1) {
 				$filter .= 'And: ' . $numAnd . "\n";
 			}
+			*/
 		}
 
 		return $filter;
@@ -254,21 +256,6 @@ class IcingaApiSearchLivestatus
 	}
 
 	/**
-	 * postprocesses data returned from livestatus socket
-	 * @param	string				$data		data received from livestatus socket
-	 * @return	array							postprocessed data
-	 */
-	private function postProcessData ($data) {
-		$data = preg_replace('/]\n\[/s', '],[', $data);
-		$data = str_replace(chr(10), null, $data);
-		$data = '[' . $data . ']';
-
-		$data = json_decode($data);
-
-		return $data;
-	}
-
-	/**
 	 * queries livestatus socket and returns answer (inspired by NagVis' GlobalBackendmklivestatus)
 	 * @param	string		$queryObject		livestatus object to query for
 	 * @return	
@@ -318,7 +305,7 @@ class IcingaApiSearchLivestatus
 
 		}
 
-		$data = $this->postProcessData($data);
+		$data = json_decode(utf8_decode($data));
 
 		return $data;
 	}





More information about the icinga-checkins mailing list