- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 08:07 AM
Dear All,
I have a script that finds the cdp n and uses that outcome as the interface description.
PS: I found this script on github
This script works well, a bit to well. I only want to change the interfaces of the Cisco swicthes as a neighbor not Cisco phones, but I can live with that.
The issue is when I run the script all is well but if the day after someone moves a cable (yes this happens) and I re run the script than I will have 2 interfaces pointing to a neighborg swicth, but only 1 is correct.
What is the easiest way to solve this? This is a css script.
Can I create a script(action) that searches for a part of the description and if that descriptions doesn't have a neighbor anymore, then delete the description on that port? I understand that I will have to run the script atleast Once before this new action will apply.
Or how would you solve this?
script:
###########################################################################
## Export of Script: PS - Update Interface from CDP Neighbor
## Script-Level: 3
## Script-Category:
## Script-Language: CCS
###########################################################################
Script-Filter:
$Vendor eq "Cisco" and $sysDescr like /IOS/
################################
Action:
Run the Show CDP Neighbor Detail Command to gather neighbor data.
Action-Commands:
SET: $UpdateMade = "no"
show cdp neighbor detail
Output-Triggers:
Find Neighbor
#################################
Trigger:
Find Neighbor
Trigger-Variables:
$Neigh_Name /[A-Za-z0-9\-_]+/
$Local_Int string
$Neigh_IntName /[A-Za-z0-9\/]+/
Trigger-Template:
Device ID: [[$Neigh_Name]].*
Entry .+
IP address: .+
Platform: .+
Interface: [[$Local_Int]], .+: [[$Neigh_IntName]]
Trigger-Commands: { $UpdateMade eq "no"}
config t
Trigger-Commands:
interface $Local_Int
Description Connection to $Neigh_Name on Interface $Neigh_IntName
SET: $UpdateMade = "yes"
########################################
Action:
End and Write Memory
Action-Commands: { $UpdateMade eq "yes" }
end
write mem
#########################################
Solved! Go to Solution.
Re: script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 08:57 AM
Can you post the output of your "show cdp neighbor detail"?
Then we can modify the script
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 09:08 AM
SH CDP N D
-------------------------
Device ID: SEP00215554DCD0
Entry address(es):
IP address: 10.2.104.55
Platform: Cisco IP Phone 7945, Capabilities: Host Phone Two-port Mac Relay
Interface: GigabitEthernet0/21, Port ID (outgoing port): Port 1
Holdtime : 128 sec
Second Port Status: Down
Version :
SCCP45.9-4-2SR1-1S
advertisement version: 2
Duplex: full
Power drawn: 12.000 Watts
Power request id: 56528, Power management id: 3
Power request levels are:12000 0 0 0 0
Management address(es):
-------------------------
Device ID: BEWZSW035_L5_FAB3_MEESTERGASTEN
Entry address(es):
IP address: 10.2.2.35
Platform: cisco WS-C3560G-24PS, Capabilities: Switch IGMP
Interface: GigabitEthernet0/24, Port ID (outgoing port): GigabitEthernet0/3
Holdtime : 151 sec
Version :
Cisco IOS Software, C3560 Software (C3560-IPBASEK9-M), Version 12.2(55)SE6, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2012 by Cisco Systems, Inc.
Compiled Mon 23-Jul-12 13:10 by prod_rel_team
advertisement version: 2
Protocol Hello: OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000002256A64C80FF0000
VTP Management Domain: 'BC'
Native VLAN: 1
Duplex: full
Application: VoIP using vlan 104
Management address(es):
IP address: 10.2.2.35
-------------------------
Device ID: SEP00260BD74E8A
Entry address(es):
IP address: 10.2.104.11
Platform: Cisco IP Phone 7945, Capabilities: Host Phone Two-port Mac Relay
Interface: GigabitEthernet0/19, Port ID (outgoing port): Port 1
Holdtime : 127 sec
Second Port Status: Down
Version :
SCCP45.9-4-2SR1-1S
advertisement version: 2
Duplex: full
Power drawn: 12.000 Watts
Power request id: 20106, Power management id: 3
Power request levels are:12000 0 0 0 0
Management address(es):
-------------------------
Device ID: 00180a7b53f5
Entry address(es):
IP address: 10.2.3.152
Platform: Meraki MR18 Cloud Managed AP, Capabilities: Router Switch
Interface: GigabitEthernet0/23, Port ID (outgoing port): Port 0
Holdtime : 139 sec
Version :
1
advertisement version: 2
Management address(es):
Re: script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2019 09:32 AM
The cool part is you just need to tweak a few lines
Add a new Trigger Variable:
$Plat string
Modify the Tigger Template
Platform: [[$Plat]]
Trigger-Commands: { $UpdateMade eq "no" and $Plat not like /Cisco IP Phone/}
Now we modify Trigger-Commands:{$Plat not like /Cisco IP Phone/}
When you are done, do you mind posting it to GitHub and a link to it here?
Thanks
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 01:02 AM
I adjusted the script, but I have an issue now when the first device it sees is a phone, the script will stopand won't check the other devices.
Now we modify Trigger-Commands:{$Plat not like /Cisco IP Phone/ and $Plat not like /Meraki MR/ }
I assume I will need to add this part after the command triggers?
Like this?:
Trigger-Commands: { $UpdateMade eq "no" and $Plat not like /Cisco IP Phone/ and $Plat not like /Meraki MR/ }
config t
Trigger-Commands:{$Plat not like /Cisco IP Phone/ and $Plat not like /Meraki MR/ }
Trigger-Commands:
interface $Local_Int
Description Connection to $Neigh_Name on Interface $Neigh_IntName
SET: $UpdateMade = "yes"
###########################################################################
## Export of Script: PS - Update Interface from CDP Neighbor
## Script-Level: 3
## Script-Category:
## Script-Language: CCS
###########################################################################
Script-Filter:
$Vendor eq "Cisco" and $sysDescr like /IOS/
################################
Action:
Run the Show CDP Neighbor Detail Command to gather neighbor data.
Action-Commands:
SET: $UpdateMade = "no"
show cdp neighbor detail
Output-Triggers:
Find Neighbor
#################################
Trigger:
Find Neighbor
Trigger-Variables:
$Neigh_Name /[A-Za-z0-9\-_]+/
$Local_Int string
$Neigh_IntName /[A-Za-z0-9\/]+/
$Plat string
Trigger-Template:
Device ID: [[$Neigh_Name]].*
Entry .+
IP address: .+
Platform: [[$Plat]]
Interface: [[$Local_Int]], .+: [[$Neigh_IntName]]
Trigger-Commands: { $UpdateMade eq "no" and $Plat not like /Cisco IP Phone/ and $Plat not like /Meraki MR/ }
config t
Trigger-Commands:
interface $Local_Int
Description Connection to $Neigh_Name on Interface $Neigh_IntName
SET: $UpdateMade = "yes"
########################################
Action:
End and Write Memory
Action-Commands: { $UpdateMade eq "yes" }
end
write mem
#########################################
Re: script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2019 08:22 AM
Try this
Trigger-Commands: { $UpdateMade eq "no" and $Plat not like /Cisco IP Phone/ or $Plat not like /Meraki MR/ } config t SET: $UpdateMade = "yes" Trigger-Commands:{ $UpdateMade eq "yes" and $Plat not like /Cisco IP Phone/ or $Plat not like /Meraki MR/ } interface $Local_Int Description Connection to $Neigh_Name on Interface $Neigh_IntName
I would combine the two not like
Trigger-Commands: { $UpdateMade eq "no" and $Plat not like /Cisco IP Phone|Meraki MR/ } config t SET: $UpdateMade = "yes" Trigger-Commands:{ $UpdateMade eq "yes" and $Plat not like /Cisco IP Phone|Meraki MR/ } interface $Local_Int Description Connection to $Neigh_Name on Interface $Neigh_IntName
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 12:02 AM
Thank you. This works!
Re: script that finds the cdp n and uses that outcome as the interface description
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 07:37 AM
Can you share it on GitHub or here?
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com