[icinga-checkins] icinga.org: icinga-web/master: * Added logging to the command sending process

git at icinga.org git at icinga.org
Tue Sep 7 20:45:35 CEST 2010


Module: icinga-web
Branch: master
Commit: 71d2964317162ca6c8f1a3eddcb45dc45973ef45
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=71d2964317162ca6c8f1a3eddcb45dc45973ef45

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Sep  7 18:17:32 2010 +0200

* Added logging to the command sending process

---

 .gitignore                                         |    1 +
 .../AppKit/lib/action/AppKitBaseAction.class.php   |    7 ++++-
 .../System/ViewProc/SendCommandAction.class.php    |   16 ++++++++++-
 .../Cronks/lib/action/CronksBaseAction.class.php   |    2 +-
 .../Cronks/lib/model/CronksBaseModel.class.php     |    5 +--
 .../models/System/CommandSenderModel.class.php     |    2 -
 .../Web/models/Icinga/ApiContainerModel.class.php  |   26 ++-----------------
 7 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9b0bd48..0c2dc14 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.settings/org.eclipse.php.core.prefs
 autom4te.cache/
 app/cache/config/*.php
 app/cache/content
diff --git a/app/modules/AppKit/lib/action/AppKitBaseAction.class.php b/app/modules/AppKit/lib/action/AppKitBaseAction.class.php
index 00e194d..ba655cb 100755
--- a/app/modules/AppKit/lib/action/AppKitBaseAction.class.php
+++ b/app/modules/AppKit/lib/action/AppKitBaseAction.class.php
@@ -4,7 +4,12 @@
  * The base action from which all AppKit module actions inherit.
  */
 class AppKitBaseAction extends IcingaBaseAction {
-	// EMPTY
+	
+	protected function log($arg1) {
+		$args = func_get_args();
+		return AppKitAgaviUtil::log($args);
+	}
+	
 }
 
 ?>
diff --git a/app/modules/Cronks/actions/System/ViewProc/SendCommandAction.class.php b/app/modules/Cronks/actions/System/ViewProc/SendCommandAction.class.php
index 5196f75..135aebc 100755
--- a/app/modules/Cronks/actions/System/ViewProc/SendCommandAction.class.php
+++ b/app/modules/Cronks/actions/System/ViewProc/SendCommandAction.class.php
@@ -24,11 +24,14 @@ class Cronks_System_ViewProc_SendCommandAction extends CronksBaseAction
 	}
 	
 	public function executeWrite(AgaviParameterHolder $rd) {
+		
 		$data = json_decode( $rd->getParameter('data') );
 		$selection = json_decode( $rd->getParameter('selection') );
 		$command = $rd->getParameter('command');
 		$auth = $rd->getParameter('auth');
 		
+		$this->log('SendCommandAction: Prepare to send command (command=%s)', $command, AgaviLogger::INFO);
+		
 		$IcingaApiCommand = $this->getContext()->getModel('Icinga.ApiContainer', 'Web');
 		
 		// The model
@@ -36,6 +39,8 @@ class Cronks_System_ViewProc_SendCommandAction extends CronksBaseAction
 		
 		if ($sender->checkAuth($rd->getParameter('command'), $rd->getParameter('selection'), $rd->getParameter('data'), $auth) === true) {
 			
+			$this->log('SendCommandAction: Successfull authentication (hmac=%s)', $auth, AgaviLogger::DEBUG);
+			
 			// Prepare the data
 			$sender->setCommandName($command);
 			$sender->setSelection($selection);
@@ -45,6 +50,9 @@ class Cronks_System_ViewProc_SendCommandAction extends CronksBaseAction
 			$coa = $sender->buildCommandObjects();
 
 			if ($IcingaApiCommand->checkDispatcher() !== true) {
+				
+				$this->log('SendCommandAction: IcingaApi dispatcher is not ready!', AgaviLogger::ERROR);
+				
 				$this->setAttribute('ok', false);
 				$this->setAttribute('error', 'No command dispatchers configured!');
 				
@@ -54,10 +62,12 @@ class Cronks_System_ViewProc_SendCommandAction extends CronksBaseAction
 			// Send the bundle
 			try {
 				$IcingaApiCommand->dispatchCommandArray($coa);
+				$this->log('SendCommandAction: Commands sent', AgaviLogger::INFO);
 			}
 			catch (IcingaApiCommandException $e) {
 				$errors = $IcingaApiCommand->getLastErrors();
 				$error = array();
+				
 				foreach ($errors as $err) {
 					$error[] = sprintf('%s: %s', get_class($err), $err->getMessage());
 				}
@@ -65,6 +75,8 @@ class Cronks_System_ViewProc_SendCommandAction extends CronksBaseAction
 				$this->setAttribute('ok', false);
 				$this->setAttribute('error', join(', ', $error));
 				
+				$this->log('SendCommandAction: Command distribution failed! (error=%s)', join(', ', $error), AgaviLogger::FATAL);
+				
 				return $this->getDefaultViewName();
 			}
 		
@@ -74,8 +86,7 @@ class Cronks_System_ViewProc_SendCommandAction extends CronksBaseAction
 		else {
 			$this->setAttribute('ok', false);
 			$this->setAttribute('error', 'Authentification failed');
-			$this->getContext()->getLoggerManager()
-			->log('Command auth failed!', AgaviLogger::ERROR);
+			$this->log('SendCommandAction: Authentification failed! (hmac=%s)', $auth, AgaviLogger::DEBUG);
 		}
 		
 		return $this->getDefaultViewName();
@@ -92,6 +103,7 @@ class Cronks_System_ViewProc_SendCommandAction extends CronksBaseAction
 	public function handleError(AgaviRequestDataHolder $rd) {
 		$this->setAttribute('ok', false);
 		$this->setAttribute('error', 'Validation failed');
+		$this->log('SendCommandAction: Validation failed, wrong parameters!', AgaviLogger::ERROR);
 		return $this->getDefaultViewName();
 	}
 }
diff --git a/app/modules/Cronks/lib/action/CronksBaseAction.class.php b/app/modules/Cronks/lib/action/CronksBaseAction.class.php
index 60e0bf0..59a35c7 100755
--- a/app/modules/Cronks/lib/action/CronksBaseAction.class.php
+++ b/app/modules/Cronks/lib/action/CronksBaseAction.class.php
@@ -3,7 +3,7 @@
 /**
  * The base action from which all Cronks module actions inherit.
  */
-class CronksBaseAction extends IcingaBaseAction
+class CronksBaseAction extends AppKitBaseAction
 {
 
 }
diff --git a/app/modules/Cronks/lib/model/CronksBaseModel.class.php b/app/modules/Cronks/lib/model/CronksBaseModel.class.php
index 8054434..5eabefe 100755
--- a/app/modules/Cronks/lib/model/CronksBaseModel.class.php
+++ b/app/modules/Cronks/lib/model/CronksBaseModel.class.php
@@ -3,9 +3,8 @@
 /**
  * The base model from which all Cronks module models inherit.
  */
-class CronksBaseModel extends IcingaBaseModel
-{
-
+class CronksBaseModel extends IcingaBaseModel {
+	// EMPTY
 }
 
 ?>
\ No newline at end of file
diff --git a/app/modules/Cronks/models/System/CommandSenderModel.class.php b/app/modules/Cronks/models/System/CommandSenderModel.class.php
index 98a7fcd..6c824ad 100755
--- a/app/modules/Cronks/models/System/CommandSenderModel.class.php
+++ b/app/modules/Cronks/models/System/CommandSenderModel.class.php
@@ -79,8 +79,6 @@ class Cronks_System_CommandSenderModel extends CronksBaseModel {
 		$data = $command. '-'. $json_selection. '-'. $json_data;
 		$test = hash_hmac(self::TIME_ALGO, $data, $this->genTimeKey());
 		
-		// var_dump(array($test, $key));
-		
 		if ($key === $test) {
 			return true;
 		}
diff --git a/app/modules/Web/models/Icinga/ApiContainerModel.class.php b/app/modules/Web/models/Icinga/ApiContainerModel.class.php
index b0db380..31ac61d 100755
--- a/app/modules/Web/models/Icinga/ApiContainerModel.class.php
+++ b/app/modules/Web/models/Icinga/ApiContainerModel.class.php
@@ -284,19 +284,17 @@ implements AgaviISingletonModel {
 				->log($lerror, AgaviLogger::ERROR);
 			}
 			else {
-
+				
 				foreach ($ds as $dk=>$d) {
-
 					try {
-						$d->setCommand($arry);
+						$d->setCommands($arry);
 						$d->send();
 					}
 					catch (IcingaApiCommandException $e) {
 						$this->errors[] = $e;
 						$error = true;
 
-						AgaviContext::getInstance()->getLoggerManager()
-						->log('Command dispatch failed on '. $dk. ': '.  str_replace("\n", " ", print_r($d->getCallStack(), true)), AgaviLogger::ERROR);
+						$this->log('Command dispatch failed on '. $dk. ': '.  str_replace("\n", " ", print_r($d->getCallStack(), true)), AgaviLogger::ERROR);
 					}
 
 					$d->clearCommands();
@@ -304,24 +302,6 @@ implements AgaviISingletonModel {
 
 			}
 		}
-
-//		foreach ($this->apiDispatcher as $d) {
-//
-//			try {
-//				$d->setCommand($arry);
-//				$d->send();
-//			}
-//			catch (IcingaApiCommandSendException $e) {
-//				$this->errors[] = $e;
-//				$error = true;
-//
-//				AgaviContext::getInstance()->getLoggerManager()
-//				->logError('Command dispatch failed: '.  str_replace("\n", " ", print_r($d->getCallStack(), true)) );
-//			}
-//
-//			// Reset into ready-state
-//			$d->clearCommands();
-//		}
 		
 		if ($error === true) {
 			throw new IcingaApiCommandException('Errors occured try getLastError to fetch a exception stack!');





More information about the icinga-checkins mailing list