cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
104
Views
2
Helpful
0
Comments
alanssie
Cisco Employee
Cisco Employee

Information 

This code is looking at neighbour discovery, learns remote name and remote interface and push it in the 

description of the local interface 

Note: the length of the remote interface name can be tuned by set len_intn [value]

 

code 2024-first_version 

::cisco::eem::event_register_neighbor_discovery interface Gig cdp add

namespace import ::cisco::eem::*

namespace import ::cisco::lib::*

 

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

#

# Copyright (c) 2024 Alain Lanssiers <alanssie@cisco.com>

#

#

# Redistribution and use in source and binary forms, with or without

# modification, are permitted provided that the following conditions

# are met:

# 1. Redistributions of source code must retain the above copyright

#    notice, this list of conditions and the following disclaimer.

# 2. 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.

#

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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

#Platform

#---------

# Tested on NCS  (should work on any ios_xr platform)

# Purpose

# ========

# Grab CDP even and modify the description of the interface coming up

 

 

array set arr_einfo [event_reqinfo]

 

## Number of character of an interface needed, start counting from 0 (1 == 2 characters)

set len_intn 1

 

 

if [catch {cli_open} result] {

   error $result $errorInfo

} else {

   array set cli1 $result

}

 

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {

  error $_cli_result $errorInfo

}

if [catch {cli_exec $cli1(fd) "config t"} _cli_result] {

   error $_cli_result $errorInfo

}

if [catch {cli_exec $cli1(fd) "interface $arr_einfo(local_intf_name)"} _cli_result] {

  error $_cli_result $errorInfo

}

if [catch {cli_exec $cli1(fd) "description  *** [lindex [split $arr_einfo(cdp_entry_name) "."] 0] [string range $arr_einfo(port_id) 0 $len_intn] ***"} _cli_result] {

   error $_cli_result $errorInfo

}

if [catch {cli_exec $cli1(fd) "commit"} _cli_result] {

  error $_cli_result $errorInfo

}

if [catch {cli_exec $cli1(fd) "end"} _cli_result] {

  error $_cli_result $errorInfo

}

 

action_syslog msg "EEM script updated description on $arr_einfo(local_intf_name) and commit config"

catch {cli_close $cli1(fd) $cli1(tty_id)} result

 

 

 

 

 

 

 

code 2024-1708 (split char. and slot...)

::cisco::eem::event_register_neighbor_discovery interface Gig cdp add
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*

##################################################################################
#
# Copyright (c) 2024 Alain Lanssiers <alanssie@cisco.com>
#
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. 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.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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
#Platform
#---------
# Tested on NCS (should work on any ios_r, ios_xe platform)
# Purpose
# ========
# Grab CDP even and modify the description of the interface coming up
# version 2024-0718 added possibility to rstrict length of aplha character but keep the x/y/z/.. after


array set arr_einfo [event_reqinfo]

## Number of character of an interface needed, start counting from 0 (1 == 2 characters)
set len_intn 1
regsub -all {[[:alpha:]]+} $arr_einfo(port_id) {} int_num

if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}

if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "config t"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "interface $arr_einfo(local_intf_name)"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "description *** [lindex [split $arr_einfo(cdp_entry_name) "."] 0] [string range $arr_einfo(port_id) 0 $len_intn]$int_num ***"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "commit"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "end"} _cli_result] {
error $_cli_result $errorInfo
}

action_syslog msg "EEM script updated description on $arr_einfo(local_intf_name) and commit config"
catch {cli_close $cli1(fd) $cli1(tty_id)} result

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: