Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F25691134
check_vcp.py
ayounsi (Arzhel Younsi)
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Authored By
ayounsi
Sep 7 2018, 3:57 PM
2018-09-07 15:57:24 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
check_vcp.py
View Options
#!/usr/bin/python
from
__future__
import
print_function
from
socket
import
inet_ntoa
from
snimpy.manager
import
Manager
as
M
from
snimpy.manager
import
load
from
snimpy.snmp
import
SNMPNoSuchObject
import
ipaddress
import
socket
import
sys
import
argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--host"
,
nargs
=
1
,
dest
=
'host'
,
required
=
True
,
help
=
"Target hostname"
)
parser
.
add_argument
(
"--community"
,
nargs
=
1
,
dest
=
'community'
,
required
=
True
,
help
=
"SNMP community"
)
options
=
parser
.
parse_args
()
load
(
"./mib-jnx-smi.txt"
)
load
(
"./mib-jnx-chassis.txt"
)
load
(
"./mib-jnx-ex-smi.txt"
)
load
(
"./mib-jnx-virtualchassis.txt"
)
m
=
M
(
options
.
host
[
0
],
options
.
community
[
0
],
2
,
cache
=
True
)
return_code
=
1
return_message
=
''
up_count
=
0
down_count
=
0
unknown_count
=
0
for
index
in
m
.
jnxVirtualChassisPortAdminStatus
:
adminStatus
=
m
.
jnxVirtualChassisPortAdminStatus
[
index
]
operStatus
=
m
.
jnxVirtualChassisPortOperStatus
[
index
]
try
:
portName
=
m
.
jnxVirtualChassisPortName
[
index
]
fpcId
=
m
.
jnxVirtualChassisFpcId
[
index
]
except
SNMPNoSuchObject
:
portName
=
'N/A'
fpcId
=
'N/A'
if
adminStatus
==
3
:
#If adminStatus is Unknown
unknown_count
+=
1
return_code
=
2
# Still alert as critical
return_message
+=
'FPC '
+
str
(
fpcId
)
+
' port '
+
portName
+
' unknown status
\n
'
elif
adminStatus
==
1
:
#If adminStatus is UP
if
operStatus
==
1
:
up_count
+=
1
elif
operStatus
==
2
:
down_count
+=
1
return_code
=
2
return_message
+=
'FPC '
+
str
(
fpcId
)
+
' port '
+
portName
+
' down
\n
'
elif
operStatus
==
3
:
unknown_count
+=
1
return_code
=
2
return_message
+=
'FPC '
+
str
(
fpcId
)
+
' port '
+
portName
+
' unknown
\n
'
if
return_code
==
1
:
print
(
'OK:'
+
' UP: '
+
str
(
up_count
))
else
:
print
(
'CRIT: Down: '
+
str
(
down_count
)
+
' Unknown: '
+
str
(
unknown_count
)
+
'
\n
'
+
return_message
)
sys
.
exit
(
return_code
)
File Metadata
Details
Attached
Mime Type
text/x-python
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6384062
Default Alt Text
check_vcp.py (1 KB)
Attached To
Mode
T201097: Add virtual chassis port status alerting
Attached
Detach File
Event Timeline
Log In to Comment