Author:   Lars Michelsen <[email protected]>
Date:     Mon Jun 25 09:09:07 2012 +0200
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Mon Jun 25 09:09:07 2012 +0200

Added nice error message when problems can not be acknowledged using a specific 
backend

---

 share/server/core/classes/CoreBackendMgmt.php |    2 +-
 share/server/core/classes/CoreModAction.php   |   34 ++++++++++++------------
 share/server/core/classes/NagVisViewAck.php   |   13 +++++++++
 3 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/share/server/core/classes/CoreBackendMgmt.php 
b/share/server/core/classes/CoreBackendMgmt.php
index 70d52a7..3966ca7 100644
--- a/share/server/core/classes/CoreBackendMgmt.php
+++ b/share/server/core/classes/CoreBackendMgmt.php
@@ -507,7 +507,7 @@ class CoreBackendMgmt {
      * @author         Lars Michelsen <[email protected]>
      */
     public function checkBackendFeature($backendId, $feature, $printErr = 1) {
-        $backendClass = 
'GlobalBackend'.cfg('backend_'.$backendId,'backendtype');
+        $backendClass = 'GlobalBackend'.cfg('backend_'.$backendId, 
'backendtype');
         if(method_exists($backendClass, $feature)) {
             return true;
         } else {
diff --git a/share/server/core/classes/CoreModAction.php 
b/share/server/core/classes/CoreModAction.php
index aa72057..951965d 100644
--- a/share/server/core/classes/CoreModAction.php
+++ b/share/server/core/classes/CoreModAction.php
@@ -27,6 +27,7 @@
  */
 class CoreModAction extends CoreModule {
     private $name = null;
+    private $MAPCFG = null;
 
     public function __construct(GlobalCore $CORE) {
         // Register valid actions
@@ -49,21 +50,27 @@ class CoreModAction extends CoreModule {
                         'notify'    => MATCH_BOOLEAN_EMPTY,
                         'persist'   => MATCH_BOOLEAN_EMPTY,
                     );
-                    $aVals = $this->getCustomOptions($aOpts, Array(), true);
+                    $attrs = $this->getCustomOptions($aOpts, Array(), true);
 
-                    $VIEW = new NagVisViewAck();
+                    $this->verifyMapExists($attrs['map']);
+
+                    $this->MAPCFG = new 
GlobalMapCfg(GlobalCore::getInstance(), $attrs['map']);
+                    $this->MAPCFG->skipSourceErrors();
+                    $this->MAPCFG->readMapConfig();
+
+                    $VIEW = new NagVisViewAck($this->MAPCFG);
 
                     $err     = null;
                     $success = null;
                     if($this->submitted()) {
                         try {
-                            $success = $this->handleAck($aVals);
+                            $success = $this->handleAck($attrs);
                         } catch(FieldInputError $e) {
                             $err = $e;
                         }
                     }
 
-                    $sReturn = json_encode(Array('code' => 
$VIEW->parse($aVals, $err, $success)));
+                    $sReturn = json_encode(Array('code' => 
$VIEW->parse($attrs, $err, $success)));
                 break;
             }
         }
@@ -76,28 +83,20 @@ class CoreModAction extends CoreModule {
     }
 
     protected function handleAck($attrs) {
-        $this->verifyMapExists($attrs['map']);
-        $MAPCFG = new GlobalMapCfg(GlobalCore::getInstance(), $attrs['map']);
-
-        try {
-            $MAPCFG->skipSourceErrors();
-            $MAPCFG->readMapConfig();
-        } catch(MapCfgInvalid $e) {}
-
         if(!isset($attrs['object_id']) && $attrs['object_id'] == '')
             throw new NagVisException(l('The object_id value is missing.'));
 
         $objId = $attrs['object_id'];
 
-        if(!$MAPCFG->objExists($objId))
+        if(!$this->MAPCFG->objExists($objId))
             throw new NagVisException(l('The object does not exist.'));
 
-        $type  = $MAPCFG->getValue($objId, 'type');
+        $type  = $this->MAPCFG->getValue($objId, 'type');
 
         if($type == 'host')
-            $spec = $MAPCFG->getValue($objId, 'host_name');
+            $spec = $this->MAPCFG->getValue($objId, 'host_name');
         else
-            $spec = $MAPCFG->getValue($objId, 
'host_name').';'.$MAPCFG->getValue($objId, 'service_description');
+            $spec = $this->MAPCFG->getValue($objId, 
'host_name').';'.$this->MAPCFG->getValue($objId, 'service_description');
 
         if(!isset($attrs['comment']) || $attrs['comment'] == '')
             throw new FieldInputError('comment', l('The attribute needs to be 
set.'));
@@ -107,7 +106,8 @@ class CoreModAction extends CoreModule {
 
         // Now send the acknowledgement
         global $_BACKEND, $AUTH;
-        $BACKEND = 
$_BACKEND->getBackend($MAPCFG->getValue($attrs['object_id'], 'backend_id'));
+        $backendId = $this->MAPCFG->getValue($attrs['object_id'], 
'backend_id');
+        $BACKEND = $_BACKEND->getBackend($backendId);
         $BACKEND->actionAcknowledge(
             $type, $spec, $attrs['comment'],
             $attrs['sticky'] == '1',
diff --git a/share/server/core/classes/NagVisViewAck.php 
b/share/server/core/classes/NagVisViewAck.php
index ff12135..ac3978f 100644
--- a/share/server/core/classes/NagVisViewAck.php
+++ b/share/server/core/classes/NagVisViewAck.php
@@ -27,9 +27,22 @@
  */
 class NagVisViewAck {
     private $errors = array();
+    private $MAPCFG = null;
+
+    public function __construct($MAPCFG) {
+        $this->MAPCFG = $MAPCFG;
+    }
 
     public function parse($attrs, $err, $success) {
         $s = '';
+
+        global $_BACKEND;
+        $backendId = $this->MAPCFG->getValue($attrs['object_id'], 
'backend_id');
+        if(!$_BACKEND->checkBackendFeature($backendId, 'actionAcknowledge', 
false)) {
+            return '<div class=err>'
+             .l('The requested feature is not available for this backend. The 
MKLivestatus backend supports this feature.')
+             .'</div>';
+        }
         
         if($err)
             $this->errors[$err->field] = array($err->msg);


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to