-
Notifications
You must be signed in to change notification settings - Fork 5
utilities script.py cycle elements
Executes a simple command specified as a text of this element. The command has to immediately return its output terminate.
-
context
Ignored for devices with VDOMs disabled. Specifies in which context the command should be execute. Can beglobal
to execute in global context,mgmt_vdom
to execute in the context of currently configured management vdom, orvdom
to execute in the context of VDOM presented invdom
attribute. If this attribute is not present,global
context is used. -
vdom
Used when thecontext
isvdom
- in that case it is mandatory attribute.
<simple context="global"> get system performance status </simple>
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
.
-
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.
-
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 theseparator
attribute. Escape characters are interpreted in this string.
<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>
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.
-
name
Name of the parser in the source code.
-
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.
-
<input>
If the parser expects some input parameters, those must be specified here.The
<input>
element has one or moreparam
child elements that specify what local parameter will be forwarded, orstatic
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 attributestype
to specify what kind of information should be extracted andname
to specify the name of the parameter that will store this information.
<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>
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.
-
name
Name of the cycle to call.
<subcycle name="anothercycle"/>
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.
-
name
of the parameter to set.
<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>
Deletes the parameter from the parameters list.
-
name
of the parameter to delete.
<unset name="npu_id"/>
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.
-
name
Name of the parameter where the output will be saved.
-
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 areint
for a number andstr
for a simple string.
-
<param>
With the only mandatory attribute "name" specifies the parameter name to be merged. It is expected that multiple<param>
elements will be used.
<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>
Executes different commands depending on the FortiOS version running on the device.
-
<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.
<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>
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.
-
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.
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>
Prints the text value of this element to the standard output. The output is prepended with '>>> '. This is not saved into the output file.
<echo>The current value of the parameter "test" is ${test}.</echo>
Prints the current parameter list with all the parameters and their values on the standard output. This is not saved into the output file.
<dump_params/>