Skip to content

Commit

Permalink
Merge pull request #228 from napalm-automation/nxos-msg
Browse files Browse the repository at this point in the history
Adding a couple of new messages for NX-OS, and support for a different message format
  • Loading branch information
luke-orden committed May 8, 2018
2 parents 11f06e2 + 19ac2bb commit 15cc403
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 2 deletions.
25 changes: 25 additions & 0 deletions napalm_logs/config/nxos/INTERFACE_DOWN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Interface Ethernet1/33 is down (Link failure)

messages:
- error: INTERFACE_DOWN
tag: ETHPORT-5-IF_DOWN_LINK_FAILURE
values:
interface: (\w+[\.\-\d\/\w+]+)
reason: (.*)
line: 'Interface {interface} is down ({reason})'
model: openconfig-interfaces
mapping:
variables:
interfaces//interface//{interface}//state//change_reason: reason
static:
interfaces//interface//{interface}//state//admin_status: DOWN
- error: INTERFACE_DOWN
tag: ETH_PORT_CHANNEL-5-PORT_INDIVIDUAL_DOWN
values:
interface: (\w+[\.\-\d\/\w+]+)
line: 'individual port {interface} is down'
model: openconfig-interfaces
mapping:
variables: {}
static:
interfaces//interface//{interface}//state//admin_status: DOWN
19 changes: 19 additions & 0 deletions napalm_logs/config/nxos/INTERFACE_DUPLEX_MODE.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This message type is received when there's a notification that the interface
# changed the duplex mode, e.g.,
#
# .. code-block:: text
#
# Interface Ethernet1/33, operational duplex mode changed to Full

messages:
- error: INTERFACE_DUPLEX_MODE
tag: ETHPORT-5-IF_DUPLEX
values:
interface: (\w+[\.\-\d\/\w+]+)
mode|upper: (\w+)
line: 'Interface {interface}, operational duplex mode changed to {mode}'
model: openconfig-interfaces
mapping:
variables:
interfaces//interface//{interface}//ethernet//state//duplex_mode: mode
static: {}
15 changes: 15 additions & 0 deletions napalm_logs/config/nxos/INTERFACE_UP.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Interface Ethernet1/33 is up in mode trunk

messages:
- error: INTERFACE_UP
tag: ETHPORT-5-IF_UP
values:
interface: (\w+[\.\-\d\/\w+]+)
mode|upper: (\w+)
line: 'Interface {interface} is up in mode {mode}'
model: openconfig-interfaces
mapping:
variables:
interfaces//interface//{interface}//ethernet//switched_vlan//state//interface_mode: mode
static:
interfaces//interface//{interface}//state//admin_status: UP
16 changes: 14 additions & 2 deletions napalm_logs/config/nxos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@
('message', r'(.*)')
]
_RGX_PARTS = OrderedDict(_RGX_PARTS)

_RGX = r'\<{0[pri]}\>{0[host]}: {0[date]} {0[time]} {0[timeZone]}: %{0[tag]}: {0[message]}'.format(_RGX_PARTS)

_ALT_RGX_PARTS = [
('pri', r'(\d+)'),
('date', r'(\d+ \w+ +\d+)'),
('time', r'(\d\d:\d\d:\d\d)'),
('host', r'([^ ]+)'),
('tag', r'([\w\d-]+)'),
('message', r'(.*)')
]
_ALT_RGX_PARTS = OrderedDict(_ALT_RGX_PARTS)
_ALT_RGX = r'\<{0[pri]}\>{0[date]} {0[time]} {0[host]} %{0[tag]}: {0[message]}'.format(_ALT_RGX_PARTS)

_TIME_FORMAT = ('{date} {time} {timeZone}', '%Y %b %d %H:%M:%S %Z')
_ALT_TIME_FORMAT = ('{date} {time}', '%Y %b %d %H:%M:%S')


def extract(msg):
return napalm_logs.utils.extract(_RGX, msg, _RGX_PARTS, _TIME_FORMAT)
return napalm_logs.utils.extract(_RGX, msg, _RGX_PARTS, _TIME_FORMAT) or\
napalm_logs.utils.extract(_ALT_RGX, msg, _ALT_RGX_PARTS, _ALT_TIME_FORMAT)
1 change: 1 addition & 0 deletions tests/config/nxos/INTERFACE_DOWN/default/syslog.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<190>2018 Apr 20 13:15:07 nexus-switch %ETHPORT-5-IF_DOWN_LINK_FAILURE: Interface Ethernet1/33 is down (Link failure)
32 changes: 32 additions & 0 deletions tests/config/nxos/INTERFACE_DOWN/default/yang.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"ip": "127.0.0.1",
"host": "nexus-switch",
"error": "INTERFACE_DOWN",
"yang_message": {
"interfaces": {
"interface": {
"Ethernet1/33": {
"state": {
"admin_status": "DOWN",
"change_reason": "Link failure"
}
}
}
}
},
"facility": 23,
"yang_model": "openconfig-interfaces",
"os": "nxos",
"severity": 6,
"message_details": {
"date": "2018 Apr 20",
"tag": "ETHPORT-5-IF_DOWN_LINK_FAILURE",
"host": "nexus-switch",
"message": "Interface Ethernet1/33 is down (Link failure)",
"facility": 23,
"severity": 6,
"pri": "190",
"time": "13:15:07"
},
"timestamp": 1524230107
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<190>2018 Apr 20 13:15:07 nexus-switch %ETH_PORT_CHANNEL-5-PORT_INDIVIDUAL_DOWN: individual port Ethernet1/33 is down
31 changes: 31 additions & 0 deletions tests/config/nxos/INTERFACE_DOWN/individual_port_down/yang.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"ip": "127.0.0.1",
"message_details": {
"message": "individual port Ethernet1/33 is down",
"time": "13:15:07",
"date": "2018 Apr 20",
"facility": 23,
"severity": 6,
"tag": "ETH_PORT_CHANNEL-5-PORT_INDIVIDUAL_DOWN",
"pri": "190",
"host": "nexus-switch"
},
"error": "INTERFACE_DOWN",
"yang_model": "openconfig-interfaces",
"facility": 23,
"severity": 6,
"yang_message": {
"interfaces": {
"interface": {
"Ethernet1/33": {
"state": {
"admin_status": "DOWN"
}
}
}
}
},
"host": "nexus-switch",
"timestamp": 1524230107,
"os": "nxos"
}
1 change: 1 addition & 0 deletions tests/config/nxos/INTERFACE_DUPLEX_MODE/default/syslog.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<190>2018 Apr 20 13:15:15 nexus-switch %ETHPORT-5-IF_DUPLEX: Interface Ethernet1/33, operational duplex mode changed to Full
33 changes: 33 additions & 0 deletions tests/config/nxos/INTERFACE_DUPLEX_MODE/default/yang.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"severity": 6,
"yang_message": {
"interfaces": {
"interface": {
"Ethernet1/33": {
"ethernet": {
"state": {
"duplex_mode": "FULL"
}
}
}
}
}
},
"yang_model": "openconfig-interfaces",
"ip": "127.0.0.1",
"facility": 23,
"host": "nexus-switch",
"error": "INTERFACE_DUPLEX_MODE",
"os": "nxos",
"message_details": {
"date": "2018 Apr 20",
"message": "Interface Ethernet1/33, operational duplex mode changed to Full",
"facility": 23,
"host": "nexus-switch",
"severity": 6,
"pri": "190",
"tag": "ETHPORT-5-IF_DUPLEX",
"time": "13:15:15"
},
"timestamp": 1524230115
}
1 change: 1 addition & 0 deletions tests/config/nxos/INTERFACE_UP/mode_trunk/syslog.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<190>2018 Apr 20 13:15:38 nexus-switch %ETHPORT-5-IF_UP: Interface Ethernet1/33 is up in mode trunk
38 changes: 38 additions & 0 deletions tests/config/nxos/INTERFACE_UP/mode_trunk/yang.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"facility": 23,
"yang_model": "openconfig-interfaces",
"yang_message": {
"interfaces": {
"interface": {
"Ethernet1/33": {
"ethernet": {
"switched_vlan": {
"state": {
"interface_mode": "TRUNK"
}
}
},
"state": {
"admin_status": "UP"
}
}
}
}
},
"ip": "127.0.0.1",
"host": "nexus-switch",
"message_details": {
"facility": 23,
"pri": "190",
"date": "2018 Apr 20",
"message": "Interface Ethernet1/33 is up in mode trunk",
"severity": 6,
"time": "13:15:38",
"host": "nexus-switch",
"tag": "ETHPORT-5-IF_UP"
},
"severity": 6,
"os": "nxos",
"error": "INTERFACE_UP",
"timestamp": 1524230138
}

0 comments on commit 15cc403

Please sign in to comment.