Command mask: Add documentation

refs #4355
This commit is contained in:
Marius Hein 2013-07-22 12:18:54 +02:00
parent f7369969cf
commit 1511cc4662
4 changed files with 459 additions and 0 deletions

175
doc/command.md Normal file
View File

@ -0,0 +1,175 @@
# Commands
## Abstract
Commands are one important intersection between the monitoring core and the
frontend. This is the writable interface where you can control the core how
checks will be processed. Usually you can interact by buttons in the frontend.
This document describes the URL interface and what commands can be used.
## Configuration
**To be done.**
## URL Interface
The interface offers to options how to deal with commands:
1. Show html forms to enter information about the commands (GET requests)
2. Send commands when providing post data
### Endpoint
Endpoint of commands is specified as follow:
```
http://localhost:8080/icinga2-web/monitoring/command/<name_of_command>
```
### List of commands
To see which commands are support you can supply the **list** argument:
```
http://localhost:8080/icinga2-web/monitoring/command/list
```
### Examples of command urls:
```
# Schedule downtime for an object
http://localhost:8080/icinga2-web/monitoring/command/scheduledowntime
# Provide a new commend for an object
http://localhost:8080/icinga2-web/monitoring/command/addcomment
```
## List of commands
*Please note that the list is not complete yet, more commands will follow*
<p></p>
<table>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
<tr>
<td>disableactivechecks</td>
<td>Disable active checks for an object</td>
</tr>
<tr>
<td>enableactivechecks</td>
<td>Enable active checks for an object</td>
</tr>
<tr>
<td>reschedulenextcheck</td>
<td>Reschedule next active check</td>
</tr>
<tr>
<td>submitpassivecheckresult</td>
<td>Submit a passive result set for this check</td>
</tr>
<tr>
<td>stopobsessing</td>
<td>Stop obsessing over object</td>
</tr>
<tr>
<td>startobsessing</td>
<td>Start obsessing over object</td>
</tr>
<tr>
<td>stopacceptingpassivechecks</td>
<td>Stop accepting passive results for this object</td>
</tr>
<tr>
<td>startacceptingpassivechecks</td>
<td>Start accepting passive results for this object</td>
</tr>
<tr>
<td>disablenotifications</td>
<td>Disable sending messages for problems</td>
</tr>
<tr>
<td>enablenotifications</td>
<td>Enable sending messages for problems</td>
</tr>
<tr>
<td>sendcustomnotification</td>
<td>Send a custom notification for this object</td>
</tr>
<tr>
<td>scheduledowntime</td>
<td>Schedule a downtime for this object</td>
</tr>
<tr>
<td>scheduledowntimeswithchildren</td>
<td>Schedule a downtime for host and all services</td>
</tr>
<tr>
<td>removedowntimeswithchildren</td>
<td>Remove all downtimes from this host and its services</td>
</tr>
<tr>
<td>disablenotificationswithchildren</td>
<td>Disable all notification from this host and its services</td>
</tr>
<tr>
<td>enablenotificationswithchildren</td>
<td>Enable all notification from this host and its services</td>
</tr>
<tr>
<td>reschedulenextcheckwithchildren</td>
<td>Reschedule next check of host ans its services</td>
</tr>
<tr>
<td>disableactivecheckswithchildren</td>
<td>Disable all checks of this host and its services</td>
</tr>
<tr>
<td>enableactivecheckswithchildren</td>
<td>Disable all checks of this host and its services</td>
</tr>
<tr>
<td>disableeventhandler</td>
<td>Disable event handler for this object</td>
</tr>
<tr>
<td>enableeventhandler</td>
<td>Disable event handler for this object</td>
</tr>
<tr>
<td>disableflapdetection</td>
<td>Disable flap detection</td>
</tr>
<tr>
<td>enableflapdetection</td>
<td>Enable flap detection</td>
</tr>
<tr>
<td>addcomment</td>
<td>Add a new comment to this object</td>
</tr>
<tr>
<td>resetattributes</td>
<td>Reset all changed attributes</td>
</tr>
<tr>
<td>acknowledgeproblem</td>
<td>Acknowledge problem of this object</td>
</tr>
<tr>
<td>removeacknowledgement</td>
<td>Remove problem acknowledgement</td>
</tr>
<tr>
<td>delaynotification</td>
<td>Delay next object notification</td>
</tr>
<tr>
<td>removedowntime</td>
<td>Remove a specific downtime</td>
</tr>
</table>

190
doc/form.md Normal file
View File

@ -0,0 +1,190 @@
# Forms
## Abstract
This document describe how to develop forms in Icinga 2 Web. This is important
if you want to write modules or extend Icinga 2 Web with your flavour of code.
## Architecture
Forms are basically Zend_Form classes with Zend_Form_Element items as controls.
To ensure common functionallity and control dependent fields Icinga 2 Web
provides sub classes to build forms on that.
![Basic form design][form1]
*(Methods and attributes are exemplary and does not reflect the full class implementation)*
### Key design
#### Build of forms
Creating elements is done within protected function *create()* of your subclass.
In here you can add elements to your form, add validations and filters of your
choice. The creation method is invoked lazy just before a form is rendered or
*isValid()* is called.
#### Calling is *isValid()*
*isValid()* is used to test of all needed parameters there. Our form class
respects just a couple of data:
1. *null*. If a request was set before (*setRequest()*) and you provide null to
this method, the data or the current request is used to validate
2. *Zend_Controller_Request_Abstract*. If you provide a Zend request class the
data to test validity is extracted from the request data.
3. *array*. The Zend default style, provide you test data as an array
#### Pre- and post validation
To handle dependend fields you can just override *preValid()* or *postValid()*
to dynamically add or remove validations. This behaviour reduces the overhead
to write own validator classes.
* *preValid()* Work just before pre validation
* *postValid()* Override validation status afterwards
#### Autoloading of form code
Because of forms are no library code we need to put them into application code.
The application or the module has an reserved namespace for forms which loads
code from special directories:
<p></p>
<table>
<tr>
<th>Class name</th>
<th>File path</tg>
</tr>
<tr>
<td>\Icinga\Form\Test\MyForm</td>
</td>application/forms/Test/MyForm.php</td>
</tr>
<tr>
<td>\MyModule\Form\Test</td>
</td>modules/forms/Test.php</td>
</tr>
</table>
If you want to create custom elements or organize library code in form context
use an other namesoace for, e.g.
```
\Icinga\Web\Form\Element\MySpecialElement
\MyModule\Web\Form\Element\FancyDatePicker
```
## Example implementation
namespace MyModule\Form;
use Icinga\Web\Form;
class TestForm extends Form
{
/**
* Add elements to this form (used by extending classes)
*/
protected function create()
{
$this->addElement(
'checkbox',
'flag',
array(
'label' => 'Check this box to user feature 1'
)
);
$this->addElement(
'text',
'flagValue',
array(
'label' => 'Enter text'
)
);
}
/**
* Check dependent fields
* @param array $data
*/
protected function preValid(array $data)
{
if (isset($data['flag']) && $data['flag'] === '1') {
$textField = $this->getElement('flagValue');
$textField->setRequired(true);
$textField->addValidator(
'alnum',
true,
array(
'allowWhitespace' => true
)
);
}
}
}
The example above adds to elements to the form: A checkbox and a textfield.
The function *preValid()* set the textfield required if checkbox was
checked before.
### Full overriding example
The following example shows form with most usefull method utilization of
interface methods:
namespace MyModule\Form;
use Icinga\Web\Form;
class TestForm extends Form
{
/**
* When sub-classing replace the constructor
*/
public function init()
{
// Do some initializing work here if needed
}
/**
* Add elements to this form (used by extending classes)
*/
protected function create()
{
// Add elements to form
}
/**
* Pre validation
* @param array $data
*/
protected function preValid(array $data)
{
// Add depending filters or validation here
}
/**
* Post validation
* @param array $data
* @param bool $isValid
*/
protected function postValid(array $data, &$isValid)
{
// Test validation setting and overriding afterwards
}
}
## Additional resources
* [API documentation](http://build.icinga.org/jenkins/view/icinga2-web/job/icinga2web-development/javadoc/?)
* Live examples: application/forms or modules/monitoring/application/forms
* [Zend API documentation](http://framework.zend.com/apidoc/1.10/_Form.html#Zend_Form)
[form1]: res/Form.png

BIN
doc/res/Form.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

94
doc/res/Form.violet Normal file
View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_25" class="java.beans.XMLDecoder">
<object class="com.horstmann.violet.ClassDiagramGraph">
<void method="addNode">
<object class="com.horstmann.violet.ClassNode" id="ClassNode0">
<void property="methods">
<void property="text">
<string>init()
isValid()
</string>
</void>
</void>
<void property="name">
<void property="text">
<string>Zend_Form</string>
</void>
</void>
</object>
<object class="java.awt.geom.Point2D$Double" id="Point2D$Double0">
<void class="java.awt.geom.Point2D$Double" method="getField">
<string>x</string>
<void method="set">
<object idref="Point2D$Double0"/>
<double>50.0</double>
</void>
</void>
<void class="java.awt.geom.Point2D$Double" method="getField">
<string>y</string>
<void method="set">
<object idref="Point2D$Double0"/>
<double>70.0</double>
</void>
</void>
<void method="setLocation">
<double>50.0</double>
<double>70.0</double>
</void>
</object>
</void>
<void method="addNode">
<object class="com.horstmann.violet.ClassNode" id="ClassNode1">
<void property="methods">
<void property="text">
<string>create(): void
preValid(data: array): void
postValid(data: array, isValid: boolean): void
isValid(data: mixed): boolean
setRequest(request: Zend_Controller_Request_Abstract)
getRequest(): Zend_Controller_Request_Abstract
buildForm(): void
initCsrfToken(): void</string>
</void>
</void>
<void property="name">
<void property="text">
<string>Icinga\Web\Form</string>
</void>
</void>
</object>
<object class="java.awt.geom.Point2D$Double" id="Point2D$Double1">
<void class="java.awt.geom.Point2D$Double" method="getField">
<string>x</string>
<void method="set">
<object idref="Point2D$Double1"/>
<double>310.0</double>
</void>
</void>
<void class="java.awt.geom.Point2D$Double" method="getField">
<string>y</string>
<void method="set">
<object idref="Point2D$Double1"/>
<double>30.0</double>
</void>
</void>
<void method="setLocation">
<double>310.0</double>
<double>30.0</double>
</void>
</object>
</void>
<void method="connect">
<object class="com.horstmann.violet.ClassRelationshipEdge">
<void property="bentStyle">
<object class="com.horstmann.violet.BentStyle" field="VHV"/>
</void>
<void property="endArrowHead">
<object class="com.horstmann.violet.ArrowHead" field="TRIANGLE"/>
</void>
</object>
<object idref="ClassNode1"/>
<object idref="ClassNode0"/>
</void>
</object>
</java>