Skip to content

utilities script.py cycle elements

Ondrej Holecek edited this page Sep 15, 2018 · 6 revisions

Commands to execute

<simple>

Executes a simple command specified as a text of this element. The command has to immediately return its output terminate.

Optional attributes:

  • context Ignored for devices with VDOMs disabled. Specifies in which context the command should be execute. Can be global to execute in global context, mgmt_vdom to execute in the context of currently configured management vdom, or vdom to execute in the context of VDOM presented in vdom attribute. If this attribute is not present, global context is used.
  • vdom Used when the context is vdom - in that case it is mandatory attribute.

Example:

<simple context="global"> get system performance status </simple>

<continuous>

Executes a command that does not simply return an output and terminates. Instead, such command prints repetitive output with updated values every few seconds. For example diagnose sys top or diagnose sys mpstat.

Mandatory attributes:

  • context, vdom Have the same meaning as for <simple> element.
  • separator String in the output that separates two consecutive parts.
  • timeout How log in seconds to keep the command running.
  • quit What sequence of characters to send in order to terminate the command. Escape characters are interpreted.

Optional attributes:

  • ignore If this string is present in the output of the command, it is removed. This happens even before the output is divided into parts using the separator attribute. Escape characters are interpreted in this string.

Example:

<continuous separator="Run Time:" timeout="30" ignore="\x1b[H\x1b[J" quit="q">
   diag sys top 5 30
</continuous>

or

<continuous separator="   CPU [" timeout="30" ignore="\x1b[H\x1b[J" quit="q">
   diag sys top-summary "-i 5 -s mem"
</continuous>

<parser>

Calls one of the internal parsers. The parser usually runs one or more commands and extract and combine the interesting parts. The results are returned as a parser-dependent JSON structure.

Please note that to correctly configure parsers inputs and outputs, one needs to understand the FortiDebug source code. Therefore such parameters are not explained in depth here and I would suggest to check the sample XML files and the source code to understand it completely.

Mandatory attributes:

  • name Name of the parser in the source code.

Optional attributes:

  • silent Normally the JSON output of the parser is printed to standard output and also written to output file. If this is set to "yes", nothing will be printed or saved. Outputs can still be saved to parameters as written bellow.

Optional child elements:

  • <input> If the parser expects some input parameters, those must be specified here.

    The <input> element has one or more param child elements that specify what local parameter will be forwarded, or static child elements to specify the parser parameter manually.

  • <store> The parser can voluntarily implement a function to convert its results into a simple string or list, which can be further used as a parameter to other functions.

    The <store> element must have one or more <param> child elements with attributes type to specify what kind of information should be extracted and name to specify the name of the parameter that will store this information.

Example:

<parser name="WADSummary">
   <store>
      <param type="wad_contexts_managers"    name="wad_contexts_managers"/>     <!-- get wad context managers -->
      <param type="wad_contexts_dispatchers" name="wad_contexts_dispatchers"/>  <!-- get wad dispatchers -->
      <param type="wad_contexts_workers"     name="wad_contexts_workers"/>      <!-- get wad workers (+wanopt) -->
      <param type="wad_contexts_informers"   name="wad_contexts_informers"/>    <!-- get wad informers -->
   </store>
</parser>

or

<parser name="DiagSysTop">
   <input>
      <static value="1" type="int"/>               <!-- collect interval -->
      <static value="pid"/>                        <!-- filter by PID    -->
      <parameter name="wad_pids_all" type="int"/>  <!-- send wad pids    -->
   </input>
</parser>

<subcycle>

The running cycle can call other cycles from the same XML file. When the other cycle finishes, the next command from the current cycle is executed.

The profile and parameters attributes specified in the definition of the sub-cycle are ignored and the profile and parameters list from the current cycle are used.

If --cycle-time option is used on command line, this time is measured for the whole main (1st) cycle. This means that the time spent in sub-cycle is counted into the time of the main cycle.

Mandatory attributes:

  • name Name of the cycle to call.

Example:

<subcycle name="anothercycle"/>

Command to manipulate with parameters

<set>

Sets the parameter to specific value provided as the element text.

Normally the parameters are not saved in the output file. But if the parameter name starts with > it will be saved (without the initial >).

Please be aware that some of such parameters can have special meaning:

  • stdout If set to 0, the command result will not be displayed on standard output.

Mandatory attributes:

  • name of the parameter to set.

Example:

<set name="npu_id">1</set>

or - to set the parameter that will also be saved in the output file (note the > character as the first character in the parameter name):

<set name=">wad:process">informer:${pid}:${ctx}</set>

<unset>

Deletes the parameter from the parameters list.

Mandatory attributes:

  • name of the parameter to delete.

Example:

<unset name="npu_id"/>

<merge>

Merges multiple independent parameters into a single list parameter. If the original parameter contains also a list, the result will be a list of lists.

Mandatory parameters:

  • name Name of the parameter where the output will be saved.

Optional parameters:

  • positions Space separated indexes to the list-to-be-merged (starting by 0). Only the values on the specified positions will be merged. If only one position is specified, the resulting list will be a simple list and not a list of lists.
  • type The value is converted to a specific type in the merged list. The possible types are int for a number and str for a simple string.

Child elements:

  • <param> With the only mandatory attribute "name" specifies the parameter name to be merged. It is expected that multiple <param> elements will be used.

Example:

<merge name="wad_pids_all" positions="1">
   <param name="wad_contexts_managers"/>
   <param name="wad_contexts_dispatchers"/>
   <param name="wad_contexts_workers"/>
   <param name="wad_contexts_informers"/>
</merge>

Commands for conditions and cycles

<version>

Executes different commands depending on the FortiOS version running on the device.

Optional child elements:

  • <if> The content will be only executed if the FortiOS version matches the version specified by its attributes:

    • major Major version (for version 5.6.4 this would be "5")
    • minor Minor version (for version 5.6.4 this would be "6")
    • patch Patch version (for version 5.6.4 this would be "4")
    • build Build number (for version 5.6.4 this would be "1575")

    All the attributes are optional and if the attribute is missing, any version is matched.

    The attributes value can be in following formats:

    • 5 Single number matches only single version
    • 5- Version 5 or higher
    • -5 Version 5 or lower
    • 3-5 Version can be 3 or 4 or 5
    • (empty) Any version
    • - Any version
  • <else> If none of the previous <if> elements matched, this is executed. This should be the last child element.

Example:

<version>
   <if major="5" minor="4" patch="1">
      <echo>Matching version 5.4.1</echo>
   </if>

   <if major="5" minor="4-6">
      <echo>Matching any patch on version 5.4 or 5.6 (or 5.5 if existed)</echo>
   </if>

   <else>
      <echo>Not matching anything, running generic commands</echo>
   </else>
</version>

<foreach>

Cycles through each string (or integer represented as string) in the parameter that contains a list of strings. If the parameter contains a list of lists, then all the strings in the inner list are used each cycle.

Mandatory attributes:

  • list Name of the parameter that contains a "list of strings" or "list of lists (of strings)".

  • name Name of the temporary parameters (valid only within this <foreach> element) to hold the variables extracted from the original parameter for every iteration of the cycle.

    If the original parameter is a "list of string", the only a single name is needed. However, if the original parameter is a "list of lists", there should be as many parameter names as is the size of the inner list, separated by space.

Example:

Parameter "cp8_ids" is a list of simple strings (internally integer in this case, but it does not matter):

<foreach list="cp8_ids" name="cp_id">
   <simple context="global"    >diagnose cp cp8 register ${cp_id}  </simple>
   <simple context="global"    >diagnose cp cp8 stats ${cp_id}     </simple>
</foreach>

or when parameter "wad_contexts_dispatchers" is a list of list (each inner list is composed of (context_id, process_id) ):

<foreach list="wad_contexts_dispatchers" name="ctx pid">
   <set name=">wad:process">informer:${pid}:${ctx}</set>

   <simple context="global"       >diagnose test app wad ${ctx}         </simple>
   <simple context="global"       >diagnose test app wad 10             </simple>
   <simple context="global"       >diagnose test app wad 11             </simple>
   <simple context="global"       >diagnose test app wad 12             </simple>
</foreach>

Commands for information and debugging

<echo>

Prints the text value of this element to the standard output. The output is prepended with '>>> '. This is not saved into the output file.

Example:

<echo>The current value of the parameter "test" is ${test}.</echo>

<dump_params>

Prints the current parameter list with all the parameters and their values on the standard output. This is not saved into the output file.

Example:

<dump_params/>
Clone this wiki locally