.. meta:: :description: How to run external scripts and the types of script interfaces in Micetro :keywords: DNS records, DNS .. _admin-change-events: Change Events ============== The system can be configured to run scripts in the event that object properties are changed. The script is also run when an object is created, but not when an object is deleted. .. note:: Scripts for the DNS Record object type are handled a bit differently. They are not run upon modifying the custom properties of a record, but rather when the content of the zone changes (record added, modified, or deleted.) For more information, refer to :ref:`zone-content-change-script-interface`. Scripts associated with object types are often used to perform lookups in external data sources and return data from these sources. Adding a Change Event --------------------- 1. On the **Admin** page, select the :guilabel:`Configuration` tab. 2. Select :guilabel:`Event Hooks` in the left sidebar. 3. In the **Change Events** section, select :guilabel:`Add`. 4. In the **Add Change Event** dialog, select the **Object type** (Zone, IP Address etc.), and then select the **Script name**. It's assumed that the script is located in a folder named `scripts` under Central's data folder. 5. When completed, select :guilabel:`Add`. *Example*: Running a Python script named ``mytest.py``. To run a script named ``mytest.py`` that is located in the `scripts` folder, select ``mytest.py`` from the dropdown. Editing and Removing Change Events ---------------------------------- #. Navigate to :menuselection:`Admin --> Configuration --> Event Hooks`. #. In the **Change Events** section, locate the change event you want to edit or remove. #. Use the Row :guilabel:`...` menu to select either :guilabel:`Edit` or :guilabel:`Remove`. #. In the dialog, make the necessary changes to the event. Script Interfaces ----------------- When Micetro Central runs an external script associated with a change event, it sends an XML structure as an argument to the script being called. The XML structure contains information about all custom properties that are defined for the object type. The XML structure also contains the login name of the user that triggered the script. The XML structures differ a little depending on the type of script (property change, zone contents change, DNS record change, scope monitoring). .. note:: The API knows change events as "External Scripts", which is why the element name is ``externalScriptParameters``. Standard Script Interface ^^^^^^^^^^^^^^^^^^^^^^^^^ The XML schema for all objects is as follows: .. code-block:: XML Change Request Script Interface ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following example shows the XML structure for a change request script: .. code-block:: XML 18 28 18 .. _zone-content-change-script-interface: Zone Content Change Script Interface ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The XML structure for a DNS zone change script differs depending on whether the zone is or is not in a view. **Zone that exists in a view**: The following example shows the XML structure for a zone change script for a zone that exists in a view: .. code-block:: XML 2534 13 bind1.corp.net. internal my.zone.com. bind1.corp.net.:internal:zone.com. **Zone not in a view**: The following example shows the XML structure for a zone change script for a zone that is not in a view: .. code-block:: XML 2635 13 dns1.corp.net. my.zone.com. dns1.corp.net.::my.zone.com. .. _dns-record-xml-schema: **DNS record change**: The following example shows the XML structure for a DNS record change script: .. code-block:: XML 1 13 dns1.corp.net. my.zone.com dns1.corp.net.::my.zone.com. Workflow Change Script Interface ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The following XML structure is used for changes to a workflow: .. code-block:: XML 14 13 gaman7 1 bind1.corp.net. bind1.corp.net.:internal:zone.com. master 0 0 Data Returned by Change Event Scripts ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Micetro Central uses the information in the XML structure to either update other custom properties or display an error message if the success attribute on the result element is set to ``0``. The following XML example shows how an error message can be returned by the change event script: .. code-block:: XML The XML structure is not required to return information about all custom properties, only fields that the script has changed. Unknown property fields are ignored by Micetro Central.