THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

Network Change & Configuration Management

Reply

script that finds the cdp n and uses that outcome as the interface description

New Member
Posts: 6
9926     1

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

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

 

 

 

Re: script that finds the cdp n and uses that outcome as the interface description

Superuser
Posts: 115
9926     1

Can you post the output of your "show cdp neighbor detail"?

 

Then we can modify the script

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: script that finds the cdp n and uses that outcome as the interface description

New Member
Posts: 6
9926     1

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

Superuser
Posts: 115
9926     1

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

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: script that finds the cdp n and uses that outcome as the interface description

New Member
Posts: 6
9926     1

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

Superuser
Posts: 115
9926     1

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
Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: script that finds the cdp n and uses that outcome as the interface description

New Member
Posts: 6
9927     1

Thank you. This works!

 

Re: script that finds the cdp n and uses that outcome as the interface description

Superuser
Posts: 115
9927     1

Can you share it on GitHub or here?

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com
Showing results for 
Search instead for 
Did you mean: 

Recommended for You