Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

How to use event parameters?

Hi

I've made simple eem applet for shutdown the port which trigered storm control event.

It is look like that:

event manager applet shut-storm

  event storm-control

  action 1.0 cli local python bootflash:shut-storm.py

and the script is

from cisco import CLI

from cisco import cli

import sys

import datetime

import time

import re

whitelist = [

"Ethernet1/1",

"Ethernet1/2"]

shlog = CLI('sh logg last 100 | i ETHPORT-5-STORM_CONTROL_ABOVE_THRESHOLD | last 3',False).get_output()

pat = re.compile(r'(\d{4} \w{3} \d{2} \d\d:\d\d:\d\d) \S+ \%ETHPORT-5-STORM_CONTROL_ABOVE_THRESHOLD: Traffic in port (Eth\S+|[Pp]o\S+)')

now = datetime.datetime.now()

delta = datetime.timedelta(seconds=180)

for l in shlog:

  mobj = pat.match(l)

  if mobj:

    port       = mobj.group(2)

    logTimeStr = mobj.group(1)

    logTimeObj = time.strptime(logTimeStr, "%Y %b %d %H:%M:%S")

    logTime    = datetime.datetime(*logTimeObj[:6])

    if now-logTime < delta:

      if port not in whitelist:

        cli("conf t")

        cli("interface %s" % port)

        cli("shutdown")

But the python script is a bit complecs because it shoud find triggered interfece in log.

Is it possible to use event parameters? And how?

I know that they are:

sw1# sh event manager history events det

Event ID Time of Event        Event Type                   Slot       Policies

32       09/30/2013 15:40:51  storm_control                active(1)  shut-storm

    interface = "Ethernet1/16", cause = "storm-control"

1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

How to use event parameters?

You should be able to do:

cli local python bootflash:shut-storm.py $interface $cause

However, calling Python scripts from EEM applets on Nexus is not officially supported yet, so your mileage may vary.

2 REPLIES
Cisco Employee

How to use event parameters?

You should be able to do:

cli local python bootflash:shut-storm.py $interface $cause

However, calling Python scripts from EEM applets on Nexus is not officially supported yet, so your mileage may vary.

New Member

How to use event parameters?

Thank you Joseph.

It works.

Now the applet looks like:

event manager applet shut-storm2

  event storm-control

  action 1.0 cli local python bootflash:shut-storm2.py $interface

And the script:

from cisco import cli

from syslog import syslog

import sys

whitelist = [

"Ethernet1/1",

"Ethernet1/2"]

port = sys.argv[1]

if port not in whitelist:

  cli("conf t")

  cli("interface %s" % port)

  cli("shutdown")

  syslog(2, "Interface %s was shutdown due to storm conditions" % port)

575
Views
0
Helpful
2
Replies