Pages

Showing posts with label cisco. Show all posts
Showing posts with label cisco. Show all posts

3/22/2020

Monitor Cisco ASA with snmp using powershell

With the entire company working remotely, the bosses want to see an hourly report of ASA connections since our capacity is limited.
  • To find the SNMP OIDs of interest I used a freeware MIB walker and lots of googling in he past 2 days about this and everything else.
  • I already had SNMPGET for the cisco backup script I've been using for years.
  • This was a good opportunity to learn more about using RRDTOOLS.  I downloaded RRD from www.rrdtool.org to use for saving the connection history and graphing it.
  • I also wanted to capture internet circuit bandwidth and utilization.  I have been using the free Solarwinds Realtime Bandwidth Monitor for this to show all the peaks that get averaged out in Orion and others.  I was able to find a powershell script that grabbed a screen shot and adjusted it to only capture the half of the server screen where the internet circuit monitors are open on,
    • It turns out that this requires that I be RDPd to this machine all the time.  So this isn't a long term kind of thing.
  • Using windows task scheduler a batch file runs that executes the powershell to take a screenshot and save it in the working folder.  Then my powershell launches. 
  • Roughly the powershell does the following:
    • create $report and then add the text of HTML BODY and TABLE headers
    • run SNMPGET to pull the svc and webvpn current connection counts from two ASA's we refer to as PRI and SEC.  svc is anyconnect client connections and webvpn is "clientless" which in my case is workspot user sessions.
    • calculate the total sessions on PRI & SEC and grand total.
    • add table rows and table data fields to $report
    • use rrdtool update to save the total to rrd database.
    • use rrdtool graph to create graph and save to working directory
    • add HTML image tags to insert the RRD graph and the screenshot image to $report
    • save $report as HTML file in working directory 
    • use send-mailmessage to e-mail $report to the recipients.  
      • NOTE:  for the images to be included in the message it is necessary to also attach them.
      • ALSO:  to specify more than one attachment or recipient, they need to be entered in quotes separated by commas.  Like:
        • "joe@cool.net", "woodstock@cool.net"
  • Code for screenprint script is below.  Followed by code for main script.

######################

# send-screen.ps1

#
#start-process "PATH TO AN APPLICATION.EXE"
#Start-Sleep -Milliseconds 1000
$File = "\util\asa\internetbw.bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = ($Screen.Width/2+256)
$Height = ($Screen.Height-64)
$Left = ($Screen.Left+800)
$Top = $Screen.Top
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
$bitmap.Save($File) 
Write-Output $File
#$SendTo = "joe@cool.net"
#$SMTPServer = "smtp" 
#$EmailFrom = “noreply@cool.net”
#$EmailSubject = “SCREENSHOT”
#$Image = $File
#$Message = new-object Net.Mail.MailMessage
#Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -erroraction silentlyContinue
#$attachment = new-object Net.Mail.Attachment($Image)
#$attachment.ContentId = "att"
#$smtp = new-object Net.Mail.SmtpClient($smtpServer)
#$body = ''
#$Message.From = $EmailFrom
#$Message.To.Add($SendTo)
#$Message.Subject = $EmailSubject
#$Message.Body = $body
#$Message.IsBodyHTML = $true
#$Message.Attachments.Add($attachment)
#$smtp.Send($Message)
#$attachment.Dispose()
#
#     END
#######################


##########################################
#
# CONRPT.PS1
#
# ASA Connection Report
#

$community = 'readonly'
$SEC = '10.66.1.16'
$PRI = '10.66.1.6'
$svc = '.1.3.6.1.4.1.9.9.392.1.3.35.0'
$webvpn = '.1.3.6.1.4.1.9.9.392.1.3.38.0'
$outfile = "asa-connect.html"
$logfile = "log.txt"
$rptname = "VPN Connections & Internet Bandwidth Usage"
$recipient = "matt.kunkel@troutman.com","lloyd.petrey@troutman.com"
$today = get-date

############################################################################################
# Report Heading

$report=@'
<STYLE>
BODY{font-family: Verdana, Arial, Helvetica, sans-serif;font-size:12;font-color: #000000}
TABLE{border-width: 2px;padding: 1px;border-style: solid;border-color: black;border-collapse: collapse;} 
TH{border-width: 2px;padding: 4px;border-style: solid;border-color: black;background-color: #dddddd;font-size:16;font-weight:bold}
TD{border-width: 2px;padding: 4px;border-style: solid;border-color: black;background-color: #efefef; font-size:12;font-weight:normal} 
TD.error{border-width: 2px;padding: 4px;border-style: solid;border-color: black;background-color: #ffffff;font face="monospace";font-size:10;font-color: #cccccc}
</STYLE> 
<HTML>
<HEAD> 
<TITLE></TITLE> 
</HEAD> 
<BODY>
'@

$report+="<H2>VPN Connections</H2><H4>"
$report+=$today
$report+="</H4><table><th>Connection </th><th>PRI </th><th>SEC </th></tr>"

############################################################################################




$cmd = "c:\snmp\bin\snmpget -M c:\snmp\mib -O nQ -v 2c -r 2 -t 1000 -c $community $SEC $svc"
$result = invoke-expression $cmd
$output = $result -split "= "
$anyconnectsec = $output[1]
$result=''
$output=''

$cmd = "c:\snmp\bin\snmpget -M c:\snmp\mib -O nQ -v 2c -r 2 -t 1000 -c $community $PRI $svc"
$result = invoke-expression $cmd
$output = $result -split "= "
$anyconnectpri = $output[1]
$result=''
$output=''

$cmd = "c:\snmp\bin\snmpget -M c:\snmp\mib -O nQ -v 2c -r 2 -t 1000 -c $community $PRI $webvpn"
$result = invoke-expression $cmd
$output = $result -split "= "
$workspotpri = $output[1]
$result=''
$output=''

$cmd = "c:\snmp\bin\snmpget -M c:\snmp\mib -O nQ -v 2c -r 2 -t 1000 -c $community $SEC $webvpn"
$result = invoke-expression $cmd
$output = $result -split "= "
$workspotsec = $output[1]
$result=''
$output=''

$totalPRI = [int]$anyconnectpri + [int]$workspotpri
$totalSEC = [int]$anyconnectsec + [int]$workspotsec

$report+="<tr><td>anyconnect</td><td>$anyconnectpri</td><td>$anyconnectsec</td></tr>"
$report+="<tr><td>workspot</td><td>$workspotpri</td><td>$workspotsec</td></tr>"
$report+="<tr><td>total</td><td>$totalPRI</td><td>$totalSEC</td></tr>"

$total = $totalPRI + $totalSEC

$log = "`t`t`t PRI `t SEC `n"
$log+= "anyconnect `t $anyconnectpri `t $anyconnectsec `n"
$log+= "workspot `t $workspotpri `t $workspotsec `n"
$log+= "total `t`t $totalPRI `t $totalSEC `n"
$log+= "$total `n"

$log | out-file $logfile

$now = get-date -date $today -uformat %s
$timestamp = [int]$now

& \rrd\bin\rrdtool update allcon.rrd N:$total 

& & \rrd\bin\rrdtool graph all-week.png --units-exponent 0 --start now-7d --end now DEF:ds1a=allcon.rrd:all:AVERAGE VDEF:ds1max=ds1a`,MAXIMUM LINE3:ds1a#FF0000:"Total Connections = $total" GPRINT:ds1max:"Max for Week=%5.0lf     "

$image=@'
</TABLE><img src="all-week.png"></img>
</img>
'@
$report+=$image
$report+="</BODY></HTML>" 

$report | out-file $outfile 

############################################################################################
#e-mail the report

$messageSubject = $rptname
$smtpServer = "smtp.cool.net"
$smtpFrom = "noreply@cool.net"
$smtpTo = $recipient
$message = $report 
#send-mailmessage -to $smtpTo -cc "joe@cool.net" -from $smtpFrom -subject $messageSubject -body $message -smtpserver $smtpServer -BodyAsHtml
send-mailmessage -to $smtpTo -cc "cool.net" -from $smtpFrom -subject $messageSubject -body $message -smtpserver $smtpServer -BodyAsHtml -attachments "\util\asa\all-week.png","\util\asa\internetbw.bmp"
###


10/28/2016

Map ports to ASIC on Cisco 7K

Map Port to ASIC on Cisco 7K Switch

From:  Nexus 7000 NXOS VDC Config Guide

Find the slot# of the module:
    show mod

Enter command:
    slot 3 show hardware internal dev-port-map

Sample Output:
--------------------------------------------------------------
CARD_TYPE:       48 port 10G
>Front Panel ports:48
--------------------------------------------------------------
 Device name             Dev role              Abbr num_inst:
--------------------------------------------------------------
> Clipper MAC            DEV_ETHERNET_MAC       MAC_0  12
> Clipper FWD            DEV_LAYER_2_LOOKUP     L2LKP  12
> Clipper XBAR           DEV_QUEUEING           QUEUE  12
> Sacramento Xbar ASIC   DEV_SWITCH_FABRIC      SWICHF 1
> PHY                    DEV_PHY                PHYS   12
> Clipper L3 Driver      DEV_LAYER_3_LOOKUP     L3LKP  12
+----------------------------------------------------------------+
+---------+++FRONT PANEL PORT TO ASIC INSTANCE MAP+++------------+
+----------------------------------------------------------------+
FP port |  PHYS | MAC_0 | L2LKP | L3LKP | QUEUE |SWICHF
   1       0       0       0       0       0       0
   2       0       0       0       0       0       0
   3       0       0       0       0       0       0
   4       0       0       0       0       0       0
   5       1       1       1       1       1       0
   6       1       1       1       1       1       0
   7       1       1       1       1       1       0
. . .

  • Port number = FP port column.
  • ASIC = MAC_0 column.
  • So, ASIC=int(Port/4) - 1

One port in each port group can be dedicated to 10Gb using the rate-mode command.


 

4/21/2016

Cisco Nexus: EthAnalyzer

I've been fighting with getting EthAnalyzer trying to get it to do something useful.  But it always only showed me traffic to/from the switch itself, not packets that pass through it. 
Today I found the following information and EUREKA!
ethanalyzer data plane traffic analysis



ACLs and Ethanalyzer for Data Plane Sampling:
The Ethanalyzer captures only traffic on CPU, so seems as unsuitable solution for the data plane traffic analysis. However, this limitation can be avoided with a use of ACL logging to sample specific packets from data plane.
              .   .   .
When we use ACLs and the “log” keyword, access control entries (ACEs) with log keyword cause system to punt a copy of matching packets to supervisor CPU. Key point is that original traffic forwarded or dropped in hardware with no performance penalty. Note that punted copies subjected to hardware rate limiter, forwarding engine hardware enforces rate to avoid saturating inband interface/CPU.

So the following accomplished what I have been trying to do for a long time:
IP access list acl-cap

  10 permit ip 10.10.10.11/32 any log

  20 permit ip any any
Eth6/28
  ip port access-group acl-cap in

ethanalyzer local int inband limit-captured-frames 0 autostop duration 60 write bootflash:test-2.pcap




7/12/2015

Packet Capture From Cisco Router


7K

ethanalyzer local interface inband limit-captured-frames 20000 autostop duration 120 write bootflash:capture.pcap

IOS-XE Router


monitor capture CAP int Gi0/0/1 both
monitor capture CAP match ipv4 any any
monitor capture CAP start
show monitor capture CAP buffer brief
monitor capture CAP stop
monitor capture CAP export ftp://10.1.10.27/CAP.pcap
no monitor capture CAP

IOS Router

  1. create access-list for packet filter
  2. access-list 1 permit 10.100.1.45
  3. create buffer
  4. monitor capture buffer holdpackets
  5. filter buffer
  6. monitor capture buffer holdpackets filter access-list 1
  7. create capture point
  8. monitor capture point ip cef mytrace all both
  9. associate capture point with buffer
  10. monitor capture point associate mytrace holdpackets
  11. start capture
  12. monitor capture point start mytrace
    • Look at progress
    show monitor capture buffer all parameters
    • See list of capture points
    show monitor capture point all
  13. Stop the capture
  14. monitor capture point stop mytrace
  15. Export buffer as PCAP
  16. monitor capture buffer holdpackets export tftp://10.1.10.27/mytrace.pcap
  17. Remove buffer
  18. no monitor capture buffer holdpackets
  19. Remove capture point
  20. no monitor capture point ip cef mytrace all both



8/18/2014

Cisco ASA - peak concurrent vpn connections

Cisco ASA - Peak Concurrent VPN Connections

How many concurrent VPN connections have I ever had? From CLI:
show vpn-sessiondb detail

5/15/2014

Redistribute selected static routes into OSPF

Cisco:  Redistribute Selected Static Routes into OSPF


ip access-list standard 10
10 permit 10.15.1.0 0.0.0.255
20 permit 10.15.10.0 0.0.0.255
30 permit 10.15.101.0 0.0.0.255
40 permit 10.15.201.0 0.0.0.255

route-map CLT-Routes permit 10
match ip address 10

router ospf 1
redistribute static subnets route-map CLT-Routes

4/14/2014

Link: DMVPN Explained

Link: DMVPN Explained

The following is a great blog post about how mGRE tunnels work and DMVPN: DMVPN Explained
As a PDF: DMVPN-Explained.PDF

3/20/2014

Cisco Nexus SNMP Hang

SNMP Process hangs on Cisco Nexus Switch

The SNMP process will stop responding on Nexus 5010 NXOS version 5.0(3)N2(1)
It appears upgrading to latest version is supposed to fix it.
Or a workaround is to unload the BRIDGE-MIB with the following command from config mode:
    no snmp-server load-mib dot1dbridgesnmp
(this will not persist after a reload.)

2/07/2014

2/06/2014

Cisco Daisy Chained Consoles

Cisco Daisy Chain Console

Daisy Chaining from one device to another can be a great backup method to access network devices without having to have a modem (or more than one.) So, if I want to be able to get to the console on a core switch at a site after having a local contact boot it up, I could enable this by connecting a cisco rollover cable from my router to the switch. This would allow me to connect to the router over the WAN side interface and then connect to the switch from the router.

Cable to buy

Need a “rollover cable.” This is the product:
Rollover Cable
http://www.cdw.com/shop/products/StarTech.com-Cisco-Console-Rollover-Cable-RJ45-Ethernet-network-cable/2437620.aspx

Setup

  • connect rollover cable from router AUX port to Core Switch CONSOLE port
  • Config on Router:
    • line aux 0
    • transport input telnet ssh

How to use

  • Connect to router and logon
  • telnet [ROUTER IP] 2001
  • Logon
  • To exit and return to router session, type CTRL+SHIFT+6 and then hit X

12/20/2013

12/13/2013

ASA SSL VPN

SSL VPN Clients not getting DNS

PROBLEM

- Clients are getting IP assigned from address pool on ASA (not DHCP.)
- Connect successfully but do not get name resolution.  DNS servers are not being assigned
- NOT doing split tunnel

CHECK

DNS settings are defined all over the place.  Confirm the correct DNS server IP numbers are defined in the following locations:

Configuration > Remote Access VPN > DNS

Configuration > Remote Access VPN > Network (Client) Access > Group Policies
          Select Policy > Edit > Servers > DNS Servers field
                    This field will only allow 2 server IP#'s

9/25/2013

SPANning ports on Cisco Nexus 5K Switch "brings down network"

DO NOT SPAN PORTS ON NEXUS 5K

Cisco Nexus 5000 Series NX-OS System Management Configuration Guide, Release 5.1(3)N1(1) - Configuring SPAN  [Cisco Nexus 5000 Series Switches] - Cisco Systems: If a destination port is oversubscribed, it can become congested. This congestion can affect traffic forwarding on one or more of the source ports.

I'm told this is not an issue on 7K's.

9/17/2013

Cisco Identity Services Engine (ISE) - Cisco Systems

Cisco Identity Services Engine (ISE) - Cisco Systems: Cisco Identity Services Engine

Cisco ACS - Accounting

Configure a device to log every command to the ACS server:

aaa accounting commands 15 default start-stop group tacacs+

aaa accounting connection default start-stop group tacacs+

aaa accounting system default start-stop group tacacs+