Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Capacity Planning

by Aatus (Initiate)
on Dec 05, 2016 at 15:25 UTC ( [id://1177230]=perlquestion: print w/replies, xml ) Need Help??

Aatus has asked for the wisdom of the Perl Monks concerning the following question:

I am VERY new to Perl but know its power and really need help to create a script that:
  1. Uses Perl::SSH
  2. SSH into appliances using username:password
  3. OPens a notepad or excel for IP address list
  4. Pings particular IP
  5. Writes to each IP the average latency
  6. Moves to next IP and logs into different appliance and repeats process

Replies are listed 'Best First'.
Re: Capacity Planning
by marto (Cardinal) on Dec 05, 2016 at 15:27 UTC
      Thanks for reply, honestly I really want to learn how to do this but need guideance on the "how to." What I need is: ex: 10.1.1.1 40ms 10.1.1.2 40ms I can provide IP's for the perl script to log into but need it to automate the process. I have over 800 appliances I need this done on, so yes, it would be preferred to automate the process.
Re: Capacity Planning
by FreeBeerReekingMonk (Deacon) on Dec 06, 2016 at 19:04 UTC
    Although there are perl tools to read directly from your input file: Spreadsheet::XLSX (it comes with an example that will get you up and running in no time, just remember to do "cpanm Spreadsheet::XLSX" to install the extra libraries), I think it is better to save the spreadsheet as csv and read it in with something like Text::CSV.

    you can implement it in pure perl, or mix a bit of .bat code, to bring up a notepad with your results.

    As for something that types in the results, and alt-tabs to excel and notepad individually, try another language, specialized in Windows, for example Autoit3, and that has a working multiping example.

    However, if you want an automated, lightweight, app that runs each 10 minutes, and report if thresholds are out of range... do it in Perl. :)

    There are some perl GUI's... but it is not for beginners.

    so for example:

Re: Capacity Planning
by stevieb (Canon) on Dec 05, 2016 at 15:29 UTC

    Welcome to the Monastery, Aatus!

    Please show us the code that you've written and are having issues with. We're here to help with code problems, not to completely do all of your work for you.

      Wish I had a code to give you, again I am learning this from scratch and was hoping there was something out there already I could learn from.

        The first step is to clearly lay out how you would go about doing it yourself.

        Then break that description down to steps simple enough for a 3 year old to follow.

        You'll want to look into opening a file, <$reading> a line at a time to get your IP addresses, chomping off the CRLF at the end of each line so you have only the IP, useing probably Net::Ping or a similar module to do the pinging for you, and then printing the results, either to screen or a file.

Re: Capacity Planning
by VinsWorldcom (Prior) on Dec 05, 2016 at 16:05 UTC

    Without further clarification on what devices you're talking about, I'll assume Cisco since I have a solution for what you're after if the devices you're connecting to are Cisco.

    https://github.com/vinsworldcom/crapps

      Thanks, Cisco CLI works: Basically if I was doing this manually: putty ssh -l username 10.1.1.1 password: router#ping 10.1.1.2 reply from 10.1.1.2: bytes=32 time=37ms TTL=56 reply from 10.1.1.2: bytes=32 time=37ms TTL=56 reply from 10.1.1.2: bytes=32 time=37ms TTL=56 reply from 10.1.1.2: bytes=32 time=37ms TTL=56 If anything if I could grab the 3rd reply for time=37ms and put that next to the IP in the list.

        There is an entire POD in the script, access by:

        > crapps.pl --man

        Basically, you can use:

        > crapps.pl devices.txt --ssh --username SSHUSER --password SSHPASS -- +command file.txt --write

        The above uses SSH to connect to each host by IP or hostname, 1 per line, in the file devices.txt using the username SSHUSER and password SSHPASS executing on each device the commands in, 1 per line, in the file file.txt and saving the session transcript in a file by the hostname or IP connected to.

        Preparing devices.txt and file.txt as well as parsing the output from the session files is left as an exercise for the reader.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1177230]
Approved by 1nickt
Front-paged by 1nickt
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-18 00:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found