SwitchTool
A utillity to do bulk configuration of switches using SNMP and telnet
Run using: switchtool.pl jobfile.job
The following is from the README file, and is also the most current
documentation:
SwitchTool 0.1, (c) 2008, Jon Langseth, Gjøvik University College.
----------------------------------------------------------------------
SwitchTool is, as the name implies, a tool to help working with Switches and managed network i
equipment. The tool works on batch-jobs defined in a job-description configuration file.
The tool relies on having access to SNMP and Telnet on the netboxes that you wish to work on.
Copyright (c) 2008, Jon Langseth
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Gjøvik University College nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY Jon Langseth ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL Jon Langseth BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The principle of operation is:
* Given a set of CIDR denoted IP ranges, iterate through each box in those segments.
* Try to get information via SNMP. If retrieval is successful:
* Try to confirm a regexp match on the sysDescription OID, identifying the netbox as
applicable for the job at hand
* If not applicable, ignore the box and continue to the next.
* If applicable, log in via Telnet, and iterate through the commands listed in the job-file.
The format of the job-file is given using the following example.
Lines starting with # are comments:
-------------------------------------------------------------------------------------------
#
# Job description example for SwitchTool 0.1
#
# O: logfile = STRING
# Define a log-file-name to store the job run into. If this option is not present in the
# configuration file, there will be no logging to file, but still to STDOUT.
# Note the use of macros, theese will be replaced by respective dynamic content.
logfile = run-%{YEAR}-%{MONTH}-%{DAY}-%{HOUR}-%{MINUTE}.log
# R: iprange = @STRING
# List IP ranges in CIDR format. At least one range needs to be listed.
# Single hosts must also be denoted as CIDR, using the blocksize /32
iprange = 192.168.16.0/25
iprange = 192.168.19.12/32
# R: @COMMUNITY
# List any SNMP READ communities applicable for the netboxes in this job. A minimum
# of one community must be listed. Place the most-commonly-occurring one first..
community = public
community = secret
# R: sysident = STRING
# The string to match in the systemDescription OID. The rest of the job will be run on
# the netbox if this string matches, otherwise it will be ignored. This is placed in
# a perl regexp match, so standard regexp rules should apply.
# This option is _mandatory_.
sysident = ProCurve
# O: loginprompt = STRING
# O: username = STRING
# The string to wait for as a login prompt. The tool will send two linefeeds over Telnet,
# and then wait for this regexp to match. If no match is recieved withing two seconds,
# the box will be seen as "failed", and the tool continues to the next box.
# If the netbox does not request a username, and only requires a password, omit this option,
# and also omit the username option, as it is not used if lofinprompt is absent.
loginprompt = Username:
# The username send avter recieving the loginprompt match..
username = admin
# R: passprompt = STRING
# R: password = STRING
# The string to wait for before sending the mandatory login passphrase. See description for
# loginprompt and username. This option is required.
passprompt = Password:
# The string to send after recieving the passprompt.
password = V3ry5cr7
# R: prompt = STRING
# The prompt option is listened for after sending username (optional) and password to the box.
# The match of this string indicates a successful login, and that the box is ready to recieve
# the strings in the command list.
prompt = \#
# O: execprompt = STRING
# If this is set, the tool will listen for this prompt after each command, and log deviation
# from this string as a prompt. Useful to log e.g. enabled/not enabled status.
# Failure to recieve this prompt will not cause execution to stop, though that is a planned
# feature.
#execprompt = \#
# O: execdelay = INTEGER
# Setting the execdelay, the tool will sleep for the given amount of seconds after each command.
#execdelay = 1;
# O/R: command = @STRING
# The following is a nice mix of required and optional. If you wish to build a job that basically
# logs in to your boxes, and thedo nothing, simply omit all "command =" lines.
# If you do include "command =" lines, these will be sent to the netbox, after first parsing
# any given macros. The commands will be executed in the order given, each followed by a newline.
command = configure
command = time %{MONTH}/%{DAY}/%{YEAR}
command = time %{HOUR}:%{MINUTE}
command = exit
command = write mem
command = exit
# MACROS
# The following macro substitutions are available at the moment:
#
# %{HOUR} Current localtime hour in two-digit format
# %{MINUTE} Current localtime minute in two-digit format
# %{SEC} Current localtime second in two-digit format
# %{DAY} Current localtime day-of-month in two-digit format
# %{MONTH} Current localtime month in two-digit format
# %{YEAR} Current localtime year in four-digit format
# %{HOST} The hostname or IP address used for SNMP connection