public function handleAction() { global $CORE; $sReturn = ''; if ($this->offersAction($this->sAction)) { switch ($this->sAction) { case 'custom_action': $aOpts = array('map' => MATCH_MAP_NAME, 'object_id' => MATCH_OBJECTID, 'cmd' => MATCH_STRING_NO_SPACE); $attrs = $this->getCustomOptions($aOpts, array()); // Input validations // - Valid custom action? $actions = $CORE->getDefinedCustomActions(); if (!isset($actions[$attrs['cmd']])) { throw new NagVisException(l('The given custom action is not defined.')); } // - does the map exist? if (count($CORE->getAvailableMaps('/^' . $attrs['map'] . '$/')) <= 0) { throw new NagVisException(l('The map does not exist.')); } // - does the object exist on the map? $MAPCFG = new GlobalMapCfg($attrs['map']); $MAPCFG->skipSourceErrors(); $MAPCFG->readMapConfig(); if (!isset($attrs['object_id']) && $attrs['object_id'] == '') { throw new NagVisException(l('The object_id value is missing.')); } if (!$MAPCFG->objExists($attrs['object_id'])) { throw new NagVisException(l('The object does not exist.')); } $objId = $attrs['object_id']; $func = 'handle_action_' . $attrs['cmd']; if (!function_exists($func)) { throw new NagVisException(l('Action handler not implemented.')); } $func($MAPCFG, $objId); break; case 'acknowledge': $VIEW = new ViewAck(); $sReturn = json_encode(array('code' => $VIEW->parse())); break; } } return $sReturn; }
public function parse() { global $CORE, $_BACKEND, $AUTH; ob_start(); $map = req('map'); if (!$map || count($CORE->getAvailableMaps('/^' . $map . '$/')) == 0) { throw new NagVisException(l('Please provide a valid map name.')); } $object_id = req('object_id'); if (!$object_id || !preg_match(MATCH_OBJECTID, $object_id)) { throw new NagVisException(l('Please provide a valid object id.')); } $MAPCFG = new GlobalMapCfg($map); $MAPCFG->skipSourceErrors(); $MAPCFG->readMapConfig(); if (!$MAPCFG->objExists($object_id)) { throw new NagVisException(l('The object does not exist.')); } $backendIds = $MAPCFG->getValue($object_id, 'backend_id'); foreach ($backendIds as $backendId) { 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 (is_action()) { try { $type = $MAPCFG->getValue($object_id, 'type'); if ($type == 'host') { $spec = $MAPCFG->getValue($object_id, 'host_name'); } else { $spec = $MAPCFG->getValue($object_id, 'host_name') . ';' . $MAPCFG->getValue($object_id, 'service_description'); } $comment = post('comment'); if (!$comment) { throw new FieldInputError('comment', l('You need to provide a comment.')); } $sticky = get_checkbox('sticky'); $notify = get_checkbox('notify'); $persist = get_checkbox('persist'); // Now send the acknowledgement foreach ($backendIds as $backendId) { $BACKEND = $_BACKEND->getBackend($backendId); $BACKEND->actionAcknowledge($type, $spec, $comment, $sticky, $notify, $persist, $AUTH->getUser()); } success(l('The problem has been acknowledged.')); js('window.setTimeout(function() {' . 'popupWindowClose(); refreshMapObject(null, \'' . $object_id . '\');}, 2000);'); } catch (FieldInputError $e) { form_error($e->field, $e->msg); } catch (NagVisException $e) { form_error(null, $e->message()); } catch (Exception $e) { if (isset($e->msg)) { form_error(null, $e->msg); } else { throw $e; } } } echo $this->error; js_form_start('acknowledge'); echo '<label>' . l('Comment'); input('comment'); echo '</label>'; echo '<label>'; checkbox('sticky', cfg('global', 'dialog_ack_sticky')); echo l('Sticky') . '</label>'; echo '<label>'; checkbox('notify', cfg('global', 'dialog_ack_notify')); echo l('Notify contacts') . '</label>'; echo '<label>'; checkbox('persist', cfg('global', 'dialog_ack_persist')); echo l('Persist comment') . '</label>'; submit(l('Acknowledge')); form_end(); focus('comment'); return ob_get_clean(); }
protected function doModifyObject($a) { $MAPCFG = new GlobalMapCfg($a['map']); try { $MAPCFG->readMapConfig(); } catch (MapCfgInvalid $e) { } // Give the sources the chance to load the object $MAPCFG->handleSources('load_obj', $a['id']); if (!$MAPCFG->objExists($a['id'])) { throw new NagVisException(l('The object does not exist.')); } // set options in the array foreach ($a['opts'] as $key => $val) { $MAPCFG->setValue($a['id'], $key, $val); } // write element to file $MAPCFG->storeUpdateElement($a['id']); // delete map lock if (!$MAPCFG->deleteMapLock()) { throw new NagVisException(l('mapLockNotDeleted')); } return json_encode(array('status' => 'OK', 'message' => '')); }