-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_mpls_l2vpn.py
executable file
·127 lines (113 loc) · 3.8 KB
/
check_mpls_l2vpn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
#
# @descr Checks MPLS L2VPN status of Cisco IOS devices
#
# @author Johan Hedberg <[email protected]>
#
import sys
import argparse
from lib.cnh_nm import STATE_OK, STATE_CRIT, STATE_WARN
from lib.cnh_nm import my_snmp_walk, snmpresult_to_dict
from lib.cnh_nm import trigger_not_ok, check_if_ok
# Defaults
vpls_vcid_range = xrange(1, 4096)
cpw_oper_status_mapping = {
"1": "up",
"2": "down",
"3": "testing",
"4": "dormant",
"5": "notPresent",
"6": "lowerLayerDown"
}
# Argument parsing
parser = argparse.ArgumentParser(description='Check MPLS L2VPN status')
parser.add_argument('-C', metavar='<community>', required=True,
help='SNMP Community')
parser.add_argument('-H', metavar='<host>', required=True,
help='Host to check')
args = parser.parse_args()
# Get all VC's
oids = [
'CISCO-IETF-PW-MIB::cpwVcPsnType',
'CISCO-IETF-PW-MIB::cpwVcID',
'CISCO-IETF-PW-MIB::cpwVcLocalIfMtu',
'CISCO-IETF-PW-MIB::cpwVcRemoteIfMtu',
'CISCO-IETF-PW-MIB::cpwVcInboundOperStatus',
'CISCO-IETF-PW-MIB::cpwVcOutboundOperStatus',
'CISCO-IETF-PW-MIB::cpwVcAdminStatus',
'CISCO-IETF-PW-MIB::cpwVcOperStatus'
]
rawdata = my_snmp_walk(args, oids)
data = snmpresult_to_dict(rawdata)
# Now loop over data, and perform checks
status = STATE_OK
statusstr = ''
num_vc = 0
for index, vc in data.iteritems():
if int(str(vc['cpwVcID'].value)) in vpls_vcid_range:
mpls_vc_type = 'VPLS'
else:
mpls_vc_type = 'EoMPLS'
num_vc += 1
# Check VC status
if vc['cpwVcAdminStatus'].value == u'1':
if vc['cpwVcOperStatus'].value != u'1':
status, statusstr = trigger_not_ok(
status,
statusstr,
STATE_CRIT,
"OperStatus {} on {} VCID {}".format(
cpw_oper_status_mapping[vc['cpwVcOperStatus'].value],
mpls_vc_type,
vc['cpwVcID'].value)
)
continue
if vc['cpwVcInboundOperStatus'].value != '1':
status, statusstr = trigger_not_ok(
status,
statusstr,
STATE_CRIT,
"InboundOperStatus {} on {} VCID {}".format(
cpw_oper_status_mapping[vc['cpwVcInboundOperStatus'].value],
mpls_vc_type,
vc['cpwVcID'].value)
)
if vc['cpwVcOutboundOperStatus'].value != '1':
status, statusstr = trigger_not_ok(
status,
statusstr,
STATE_CRIT,
"OutboundOperStatus {} on {} VCID {}".format(
cpw_oper_status_mapping[vc['cpwVcOutboundOperStatus'].value],
mpls_vc_type,
vc['cpwVcID'].value)
)
if status == STATE_CRIT: # No point in checking more minor issues if OperStatus isn't up
continue
else:
status, statusstr = trigger_not_ok(
status,
statusstr,
STATE_WARN,
"Admin shutdown on {} VCID {}".format(
mpls_vc_type,
vc['cpwVcId'].value)
)
continue
# Check for MTU mismatches
if vc['cpwVcLocalIfMtu'].value != vc['cpwVcRemoteIfMtu'].value:
status, statusstr = trigger_not_ok(
status,
statusstr,
STATE_CRIT,
"MTU mismatch (local={}, remote={}) on {} VCID {}".format(
vc['cpwVcLocalIfMtu'].value,
vc['cpwVcRemoteIfMtu'].value,
mpls_vc_type,
vc['cpwVcId'].value
)
)
# All checks completed, exiting with the relevant message
check_if_ok(status, statusstr)
print "OK: All ({}) VPLS/EoMPLS VC's are up and running".format(num_vc)
sys.exit(STATE_OK)