Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove constantly updating value from custom SNMP OID #3281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

syn-bit
Copy link

@syn-bit syn-bit commented Oct 9, 2024

Adding a custom SNMP OID means having a different "expression " line each time the config is pulled. Add a rule to remove the expression value.

EEM code to generate the custom SNMP OID is:

event manager applet TotalNatTranslations
event timer watchdog time 300 maxrun 60
action 010 cli command "enable"
action 020 cli command "configure terminal"
action 030 cli command "do-exec show ip nat translations total"
action 040 regexp "^.+\s([0-9]+)" "$_cli_result" match total_translations
action 050 cli command "snmp mib expression owner nat name 1"
action 060 if $_regexp_result eq "1"
action 070 cli command "expression $total_translations"
action 080 else
action 090 cli command "expression 0"
action 100 cli command "exit"
action 110 end

The resulting configuration block is:

snmp mib expression owner nat name 1
description Total active translations
value type integer32
expression 1234
!

After this commit the resulting configuration block is:

snmp mib expression owner nat name 1
description Total active translations
value type integer32
expression
!

Pre-Request Checklist

  • Passes rubocop code analysis (try rubocop --auto-correct)
  • Tests added or adapted (try rake test)
  • Changes are reflected in the documentation
  • User-visible changes appended to CHANGELOG.md

Description

Adding a custom SNMP OID means having a different "expression <value>"
line each time the config is pulled. Add a rule to remove the expression
value.

EEM code to generate the custom SNMP OID is:

event manager applet TotalNatTranslations
 event timer watchdog time 300 maxrun 60
 action 010 cli command "enable"
 action 020 cli command "configure terminal"
 action 030 cli command "do-exec show ip nat translations total"
 action 040 regexp "^.+\s([0-9]+)" "$_cli_result" match total_translations
 action 050 cli command "snmp mib expression owner nat name 1"
 action 060 if $_regexp_result eq "1"
 action 070  cli command "expression $total_translations"
 action 080 else
 action 090  cli command "expression 0"
 action 100  cli command "exit"
 action 110 end

The resulting configuration block is:

snmp mib expression owner nat name 1
  description Total active translations
  value type integer32
  expression 1234
!

After this commit the resulting configuration block is:

snmp mib expression owner nat name 1
  description Total active translations
  value type integer32
  expression <value removed>
!
@robertcheramy
Copy link
Collaborator

This is an uncommon use case for me, but if you made the effort of submitting a PR, it is worth integrating it into oxidized. Thanks for your PR!

The gsub should be placed within the show running-config command (not cmd :all), before returning the resulting cfg:

Also please document your Change in CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants