-
Notifications
You must be signed in to change notification settings - Fork 60
User Guide: Diagnostics
Thanks to the Diagnostics section, you can collect custom data from your equipments, by making Netshot run specific commands on the devices (and possibly process the result).
Once the diagnostics are defined within Netshot, the commands are effectively executed, and the output is effectively collected by running a Run diagnostics task. This can be done manually by scheduling this type of task, and this is, by default, automatic after a snapshot task.
After the data is saved in the database, it is possible to build search and dynamic group queries based on it. One may also create compliance rules to check the diagnostic result.
Creating, deleting or modifying diagnostics requires read-write & device commands permissions.
Simple diagnostics consist of one command to execute in a specific mode of a certain type of device. The output of the command may be further processed by applying a search and replace regular expression.
To create a simple diagnostic, click the Create diagnostics... button in the main toolbar, in the Diagnostics tab. Then select Simple diagnostic and fill in the required information. The RegEx pattern and Replace with fields are optional.
For example, assume you want to collect the reload reason of Cisco IOS devices. A way to collect this information is to look at the output of the show version command:
router1#show version Cisco IOS XE Software(...) router1 uptime is 2 days, 23 hours, 21 minutes (...) Last reload reason: Reload Command (...) Configuration register is 0x2102
Thus the following diagnostic may be added to execute the command and exact the interesting part:
Note the (?s) modifier in the regular expression: this will make .* match all the lines before and after the interesting line, to remove them all.
When simple diagnostics are not smart enough to properly collect some diagnostic information, Javascript-based diagnostics>should bring all the needed flexibility.
A Javascript-based diagnostic is a piece of Javascript code which must define a diagnose function which will be called by Netshot to run the diagnostic. This entry point will be called with the following parameters:
- cli: an object to interact with the device through CLI.
- cli.macro(macro): use a macro to change mode as defined in the device driver.
- cli.command(command): sends a command to the device and returns the result.
- device: an object to retrieve known information about the device.
- device.get(attributeName): get the current value of a known attribute.
- diagnostic: an object to set the diagnostic result value.
- diagnostic.set(value): set the diagnostic result for the current device.
- diagnostic.set(diagnosticName, value): set the result of the diagnostic identified by its name.
For example, the following code retrieved the current OSPF routed-id from IOS-XR devices:
function diagnose(cli, device, diagnostic) {
if (device.get("type") !== "Cisco IOS-XR") {
return;
}
cli.macro("exec");
var showOspf = cli.command("show ospf");
debug("showOspf = " + showOspf);
var routerId = showOspf.match(/Routing Process .\* with ID (\[0-9\\.\]+)/m);
routerId = routerId ? routerId\[1\] : "Unknown";
diagnostic.set(routerId);
}
To create a Javascript-based diagnostic, click the Create diagnostics... button in the main toolbar, in the Diagnostics tab. Then select Javascript-based diagnostic and fill in the required information. The Result type must be consistent with the value the script will be setting.