-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathmibview.py
More file actions
68 lines (47 loc) · 1.72 KB
/
mibview.py
File metadata and controls
68 lines (47 loc) · 1.72 KB
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
#!/usr/bin/env python2.7
# usage: mibview.py [-h] mibString
#
# Convert wildcarded OID MIB views into OID/mask format as used by EXOS.
#
# positional arguments:
# mibString Wildcard MIB string to be translated into OID/mask format
#
# optional arguments:
# -h, --help show this help message and exit
import argparse
import sys
class ArgParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
def main():
parser = ArgParser(prog='mibview.py',
description='Convert wildcarded OID MIB views into OID/mask format as used by EXOS.')
parser.add_argument('mibString',
help='Wildcard MIB string to be translated into OID/mask format',
type=str, nargs=1)
args = parser.parse_args()
mibView = args.mibString[0].split('.')
#Bitmask to be used in the final output.
mask = 0
newMibView = []
for branch in mibView:
#Left shift the bits in the mask.
mask = mask << 1
if branch is not '*':
#Insert a 1 in the low-order bits of the mask.
mask = mask + 1
#Also, add this value to the new MIB view we are building.
newMibView.append(branch)
else:
#Keep the zero in the low-order bit. Add a zero to the new MIB view we are building.
newMibView.append('0')
newMibView = ".".join(newMibView)
print newMibView + '/' + format(mask, 'X')
if __name__ == '__main__':
try:
main()
except SystemExit:
#Catch SystemExit to prevent EXOS shell from exiting to login prompt, if we're running this in EXOS
pass