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 do I combine multiple attributes in SYSLOG message and set environment variables?

I have written a simple EEM script to poll an OID which records the ADSL sync speed and generates a syslog if it falls below 4Mbit.

event manager applet ADSL_SPEED

event snmp oid 1.3.6.1.2.1.10.94.1.1.2.1.8.11 get-type exact entry-op lt entry-val "4000000" poll-interval 1800

action 1.0 syslog priority notifications msg "ADSL sync speed has fallen below 4Mbps"

I would like to do is to improve on this and have the syslog message log the current sync speed, current noise margin and number of interface flaps on the DSL interface, such as:

"Current ADSL speed is X Mbps, Noise Margin is Y DB,  Z WAN interface resets since counters last cleared"

How can I combine these 3 things in one SYSLOG message?

I would also like to see the same output when I login to the router. How can I set this as a banner?

action x.0 cli command "banner motd Current ADSL speed is (??) Mbps, Noise Margin is (??) DB,  (??) WAN interface resets since counters last cleared"

How do I set the variables to use here?

Thanks in advance.

Ryan

1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

Try this instead:

action 91.3 cli command "banner exec Z\x0a \x0aCurrent ADSL speed is $dsl_rate Mbps Noise Margin is $noise_margin dB,  $carrier_transitions WAN interface resets since counters last cleared\x0a \x0aZ"

Leave off the pattern stuff.

15 REPLIES
Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

What version of IOS are you using?  How would you obtain these values manually?

New Member

How do I combine multiple attributes in SYSLOG message and set e

I have the 3 OIDs and will get the values via SNMP.

New Member

How do I combine multiple attributes in SYSLOG message and set e

OK, I have a working configuration however there are some changes I would like to make.

1. I would like to inset a carriage return in the banner, before and after the text, how can I do this? Is there a variable which can do this?

2. The dB is reported in tenths of a dB, so 6.0 dB shows as 60. How can I take the output from the SNMP get (e.g. 60) and reformat it to display in dB (e.g. 6.0)?

My current config is below:

event manager applet report_adsl_health

event none

action 1.0 info type snmp oid 1.3.6.1.2.1.10.94.1.1.2.1.8.11 get-type exact community RO

action 2.0 set dsl_rate $_info_snmp_value

action 3.0 info type snmp oid 1.3.6.1.2.1.10.94.1.1.2.1.4.11 get-type exact community RO

action 4.0 set noise_margin $_info_snmp_value

action 5.0 info type snmp oid 1.3.6.1.4.1.9.2.2.1.1.21.16 get-type exact community RO

action 6.0 set carrier_transitions $_info_snmp_value

action 90.0 syslog priority notifications msg "Current ADSL speed is $dsl_rate bps, Noise Margin is $noise_margin dB, $carrier_transitions WAN interface resets since counters last cleared"

action 91.0 cli command "enable"

action 91.1 cli command "conf t"

action 91.2 cli command "banner exec ZCurrent ADSL speed is $dsl_rate bps, Noise Margin is $noise_margin dB, $carrier_transitions WAN interface resets since counters last clearedZ"

end

New Member

Re: How do I combine multiple attributes in SYSLOG message and s

I've solved 2 using the divide command. Any idea how to do create multi line banners using a one line statement?

event manager applet report_adsl_health

event none

action 1.1 info type snmp oid 1.3.6.1.2.1.10.94.1.1.2.1.8.11 get-type exact community RO

action 1.2 divide $_info_snmp_value 1000000

action 1.3 regex "^." $_remainder

action 1.4 set final_remainder $_regexp_result

action 1.5 set dsl_rate "$_result.$final_remainder"

action 2.1 info type snmp oid 1.3.6.1.2.1.10.94.1.1.2.1.4.11 get-type exact community RO

action 2.2 divide $_info_snmp_value 10

action 2.3 set noise_margin "$_result.$_remainder"

action 3.1 info type snmp oid 1.3.6.1.4.1.9.2.2.1.1.21.16 get-type exact community RO

action 3.2 set carrier_transitions $_info_snmp_value

action 90.1 syslog priority notifications msg "Current ADSL speed is $dsl_rate Mbps, Noise Margin is $noise_margin dB, $carrier_transitions WAN interface resets since counters last cleared"

action 91.1 cli command "enable"

action 91.2 cli command "conf t"

action 91.3 cli command "banner exec ZCurrent ADSL speed is $dsl_rate Mbps, Noise Margin is $noise_margin dB, $carrier_transitions WAN interface resets since counters last clearedZ"

end

Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

You'll need to use interactive commands for this.  I believe this will work:

action 91.3 cli command "banner exec ZCurrent ADSL speed is $dsl_rate Mbps" pattern "Enter"

action 91.4 cli command "Noise Margin is $noise_margin dB" pattern ".*"

... (using pattern ".*")

action 92.0 cli command "Z"

Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

Have you got some more examples or some documentation you could refer me to? I'm have trouble getting my head around this.

Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

Not around multi-line banners.  However, the "pattern" keyword simply tells EEM not to expect a prompt after the command is executed.  Instead, it waits for the pattern specified.  The pattern is a regular expression.

New Member

How do I combine multiple attributes in SYSLOG message and set e

OK, Why have you used "Enter" in your example?

By interactive do you mean the user has to enter text?

Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

I used "Enter" because when you type that command manually on the command line, you are prompted with text that includes the word "Enter".  Try it.

By interactive, I mean you have to anticipate a custom prompt and react to or interact with it.  The policy itself still runs to completion without human intervention.

New Member

How do I combine multiple attributes in SYSLOG message and set e

Can you post the full config you are proposing? I'm having trouble getting my head around it.

Also, I've noticed with my script it is not picking up when an OID changes so the log messages are staying the same even though the noise margin is changing. Any idea why this would be the case?

Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

event manager applet report_adsl_health

event none

action 1.1 info type snmp oid 1.3.6.1.2.1.10.94.1.1.2.1.8.11 get-type exact community RO

action 1.2 divide $_info_snmp_value 1000000

action 1.3 regex "^." $_remainder

action 1.4 set final_remainder $_regexp_result

action 1.5 set dsl_rate "$_result.$final_remainder"

action 2.1 info type snmp oid 1.3.6.1.2.1.10.94.1.1.2.1.4.11 get-type exact community RO

action 2.2 divide $_info_snmp_value 10

action 2.3 set noise_margin "$_result.$_remainder"

action 3.1 info type snmp oid 1.3.6.1.4.1.9.2.2.1.1.21.16 get-type exact community RO

action 3.2 set carrier_transitions $_info_snmp_value

action  90.1 syslog priority notifications msg "Current ADSL speed is $dsl_rate  Mbps, Noise Margin is $noise_margin dB, $carrier_transitions WAN  interface resets since counters last cleared"

action 91.1 cli command "enable"

action 91.2 cli command "conf t"

action 91.3 cli command "banner exec ZCurrent ADSL speed is $dsl_rate Mbps" pattern "Enter"

action 91.4 cli command "Noise Margin is $noise_margin dB" pattern ".*"

action 91.5 cli command "Carrier transitions are $carrier_transitions" pattern ".*"

action 92.0 cli command "Z"

The applet will read the OID value at the time it runs.  You may want to print the raw value to confirm it's relfecting what you see from a manual SNMP GET.

New Member

How do I combine multiple attributes in SYSLOG message and set e

Hi Joseph,

I ran this as a test, however it did not generate a banner with a blank line before and after as expected. Any ideas?

event manager applet test

event none

action 91.1 cli command "enable"

action 91.2 cli command "conf t"

action 91.3 cli command "banner exec Z" pattern "Enter"

action 91.4 cli command " " pattern ".*"

action 91.5 cli command "Current ADSL speed is $dsl_rate Mbps Noise Margin is $noise_margin dB, $carrier_transitions WAN interface resets since counters last cleared" pattern ".*"

action 91.6 cli command " " pattern ".*"

action 91.7 cli command "Z"

Cisco Employee

How do I combine multiple attributes in SYSLOG message and set e

Try this instead:

action 91.3 cli command "banner exec Z\x0a \x0aCurrent ADSL speed is $dsl_rate Mbps Noise Margin is $noise_margin dB,  $carrier_transitions WAN interface resets since counters last cleared\x0a \x0aZ"

Leave off the pattern stuff.

New Member

Re: How do I combine multiple attributes in SYSLOG message and s

What you suggested works however I modified it slightly as it was adding two line feeds and I only wanted one.

action 91.3 cli command "banner exec Z\x0aCurrent ADSL speed is $dsl_rate Mbps Noise Margin is $noise_margin dB, $carrier_transitions WAN interface resets since counters last cleared \x0aZ"

The \x0a is a hex code, I had been trying ASCII codes which is where I was going wrong.

Cheers!

Cisco Employee

Re: How do I combine multiple attributes in SYSLOG message and s

\x0a is an ASCII code, just the hex numbering of it.  Octal should also work (i.e., \012).

1290
Views
0
Helpful
15
Replies