ON THIS PAGE
Example: Creating the Junos Snapshot Administrator Configuration File
This example creates a basic sample Junos Snapshot Administrator configuration file.
Requirements
Junos Snapshot Administrator Release 1.0 is installed on the server.
Overview
This example creates a Junos Snapshot Administrator configuration
file with one test section named re0-master
. The re0-master
test section retrieves
and parses the XML output from the Junos OS operational mode command show chassis routing-engine
. A sample of the XML output
from a dual Routing Engine device is shown here:
<route-engine-information xmlns="http://xml.juniper.net/junos/11.4R1/junos-chassis"> <route-engine> <slot>0</slot> <mastership-state>master</mastership-state> <mastership-priority>master (default)</mastership-priority> <status>OK</status> <temperature junos:celsius="30">30 degrees C / 86 degrees F</temperature> <cpu-temperature junos:celsius="27"> 27 degrees C / 80 degrees F </cpu-temperature> <memory-dram-size>768</memory-dram-size> <memory-buffer-utilization>48</memory-buffer-utilization> <cpu-user>1</cpu-user> <cpu-background>0</cpu-background> <cpu-system>5</cpu-system> <cpu-interrupt>1</cpu-interrupt> <cpu-idle>94</cpu-idle> <model>RE-5.0</model> <serial-number>19995858810</serial-number> <start-time junos:seconds="1337708989"> 2012-05-22 10:49:49 PDT </start-time> <up-time junos:seconds="8735869"> 101 days, 2 hours, 37 minutes, 49 seconds </up-time> <last-reboot-reason> Router rebooted after a normal shutdown. </last-reboot-reason> <load-average-one>0.00</load-average-one> <load-average-five>0.00</load-average-five> <load-average-fifteen>0.00</load-average-fifteen> </route-engine> </route-engine-information>
For a dual Routing Engine device, the test case checks the XML
output to determine if the Routing Engine in slot 0 is the primary
Routing Engine. The test section uses the item route-engine[slot = '0']
expression to select the route-engine
element that has the child element slot
value of "0". The test case uses the is-equal
test operator to compare the value of the mastership-state
child element with the string value "master". If the test case returns
true, the Routing Engine in slot 0 is the primary Routing Engine.
If the test case returns false, the code reports two error statements.
The mandatory do
section includes
the names of all test sections that should be executed when Junos
Snapshot Administrator references this configuration file. For this
example, the do
section contains only re0-master
.
Configuration
The Junos Snapshot Administrator configuration
consists of a mandatory do
section and
one or more test sections.
Configuring Test Sections
Step-by-Step Procedure
The Junos Snapshot Administrator configuration consists of test sections that define the commands and evaluation criteria that are used in a snapshot or snapshot comparison. To configure a test section:
- Name the test section using a unique and descriptive string.
re0-master { ... }
- Add the
command
statement, and specify the Junos OS operational mode command that the code executes to retrieve the desired XML data.re0-master { command show chassis routing-engine; }
- Add the
iterate
oritem
statement followed by the XPath expression that selects the desired elements.re0-master { command show chassis routing-engine; item route-engine[slot = '0'] { } }
- If the test section compares elements from two snapshots,
add the
id
statement specifying a unique ID to map the first snapshot data item to the second snapshot data element.This example does not require an
id
statement. - Create the test case condition used during the check.
re0-master { command show chassis routing-engine; item route-engine[slot = '0'] { is-equal mastership-state, "master" { } } }
- Within the test case code block, add the
info
statement describing the test case or normal operating conditions.re0-master { command show chassis routing-engine; item route-engine[slot = '0'] { is-equal mastership-state, "master" { info re0 is always master; } } }
- Within the test case code block, add one or more
err
statements, which are executed if the test case fails.re0-master { command show chassis routing-engine; item route-engine[slot = '0'] { is-equal mastership-state, "master" { info re0 is always master; err " re0 is not master, rather %s", mastership-state; err " Correct so that re0 is the master!"; } } }
Configuring the "do" Section
Step-by-Step Procedure
The Junos Snapshot Administrator configuration file must
begin with a do
code block that defines
the test sections to be used in the snapshot.
- At the beginning of the configuration file, add the
do
code block.do { }
- Add the name of each test section that will be used in
the snapshot.
do { re0-master; }
Results
do { re0-master; } re0-master { command show chassis routing-engine; item route-engine[slot = '0'] { is-equal mastership-state, "master" { info re0 is always master; err " re0 is not master, rather %s", mastership-state; err " Correct so that re0 is the master!"; } } }