Viewing custom action results
Custom actions can return a status indicator (for example, completed successfully, completed with warnings, or completed with errors) for job reporting. In addition, the return status might be used to stop the job from executing subsequent actions.
The script snippet from the Ping (IOS) factory-installed custom action shows the return value capability. The onFailure option in the <assert> tag is the result code. In this example, if ping’s success rate is 20, 40, 60, or 80 percent, then a warning is returned. If it is 0 percent, then a failure (that is, abort). If it is 100 percent, then it is successful.
<prompt>\Q%prompt%\E</prompt>
<command>ping %runtime.Node To Ping%</command>
<response property="cmd.pingSuccess">Success rate is 100 percent</response>
<response property="cmd.pingWarning">Success rate is (20|40|60|80) percent </response>
<response property="cmd.pingAbort">Success rate is 0 percent</response>
</interaction>
<assert condition="((-EXISTS- cmd.pingSuccess) -OR- (-EXISTS- cmd.pingWarning))" onFailure="abort">
Ping returned Success rate of 0 percent.</assert>
<assert condition="(-EXISTS- cmd.pingSuccess)" onFailure="warning">
Ping returned Success rate of greater than 0 but less than 100 percent.</assert>
Recommendations to direct the custom action results
The results of custom actions can be directed to the following locations:
- The custom action execution transcript
- Captured results column in the Job Details report
- Dynamic fields (single-value text or menu, or multi-value menu)
- Imported hardware inventory
When determining which location to direct the custom action results, use the following recommendations:
- Transcripts: Use for long lists containing a lot of data that you want to review, or for transient reports (for example, run a show ipc queue every 24 hours and report the results). Custom action transcripts can be attached to job email notifications and included in the Job Details Export and Email options. The Print View option on the Job Details page displays all the transcripts for the job.
- Captured results: Use for small amounts of data that you want parsed out of longer show command results and presented systematically in the Job Details report. Also, use captured results for custom actions that you use often (for example, show current vlans defined on all switches).
- Dynamic fields: Use for small bits of persistent information that do not change often (for example, serial numbers, uplink interfaces, and so on). Dynamic field values are limited in length, but a device can have many dynamic fields and a field can have either a single value or multiple values. Devices can be autogrouped on the value, and the value can be referenced by compliance rules as a device substitution parameter.
- Imported inventory: Use for a single large blob of information related to the hardware installed on the device that does not change very often (for example, the output of the IOS show module command). A device has a single imported inventory that can be viewed from the Device View page, and viewed and exported from the Device Inventory Report.
When you direct the custom action results to the preceding locations (except the imported hardware inventory), you can store up to 2000 characters in the captured results. Through imported hardware inventory, you can store unlimited number of characters. In case of dynamic fields, you can store up to 2000 characters only for the Device type component and Text type dynamic fields. For all other component and value types, you can store up to 255 characters in the captured results. For information about defining a dynamic field to store up to 2000 characters, see Adding dynamic fields.