-
Notifications
You must be signed in to change notification settings - Fork 92
/
SNMPv1v2Config.py
72 lines (63 loc) · 3.23 KB
/
SNMPv1v2Config.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
#!/usr/bin/env python
'''
Wizard to configure SNMP
'''
#############################################################################
# SNMP v1/v2 Variable definitions
#############################################################################
#clierrormode = raw_input("If this script encounters errors, do you wish to abort or ignore?: ")
ynsnmpconfig = raw_input("Congifigure SNMP v1/v2 access? (yes or no): ")
ynsnmpdisable = raw_input("Disable SNMP v1/v2 access? (yes or no): ")
ynsnmpcommadd = raw_input("Add SNMP v1/v2 communities? (yes or no): ")
snmprwname = raw_input("Read/Write SNMP Community Name?: ")
snmproname = raw_input("Read-Only SNMP Community Name?: ")
ynsnmpcommrem = raw_input("Remove default SNMP Communities? (yes or no): ")
snmpname = raw_input("SNMP Switch Name?: ")
snmplocation = raw_input("SNMP Location?: ")
snmpcontact = raw_input("SNMP Contact?: ")
snmptrapcount = raw_input("Number of SNMP Trap Receivers (Script supports: 1-3): ")
snmptrap1 = raw_input("SNMP Trap Receiver #1: ")
snmptrap2 = raw_input("SNMP Trap Receiver #2: ")
snmptrap3 = raw_input("SNMP Trap Receiver #3: ")
#############################################################################
# SNMP V1/V2 Configuration
#############################################################################
#if (re.match(clierrormode,"ignore")):
# configure cli mode scripting ignore-error
# create log message "CLI mode set for Ignore on Error"
#else
# configure cli mode scripting abort-on-error
# create log message "CLI mode set for Abort on Error"
if (re.match(ynsnmpconfig,"yes")):
exsh.clicmd("create log message \"Starting SNMP Configuration\"", True)
print("Starting SNMP Configuration")
exsh.clicmd("configure snmp sysName %s" % snmpname, True)
exsh.clicmd("configure snmp sysLocation %s" % snmplocation, True)
exsh.clicmd("configure snmp sysContact %s" % snmpcontact, True)
if (snmptrapcount >= 1):
exsh.clicmd("configure snmp add trapreceiver %s community %s" % (snmptrap1,snmproname), True)
if (snmptrapcount >= 2):
exsh.clicmd("configure snmp add trapreceiver %s community %s" % (snmptrap2,snmproname), True)
if (snmptrapcount >= 3):
exsh.clicmd("configure snmp add trapreceiver %s community %s" % (snmptrap3,snmproname), True)
if (re.match(ynsnmpcommadd,"yes")):
exsh.clicmd("configure snmp add community readwrite %s" % snmprwname, True)
exsh.clicmd("configure snmp add community readonly %s" % snmproname, True)
exsh.clicmd("create log message \"New SNMP Communities Created\"", True)
print("New SNMP Communities Created")
if (re.match(ynsnmpcommrem,"yes")):
exsh.clicmd("configure snmp delete community readwrite private", True)
exsh.clicmd("configure snmp delete community readonly public", True)
exsh.clicmd("create log message \"Default SNMP Communities Removed\"", True)
print("Default SNMP Communities Removed")
else:
exsh.clicmd("create log message \"Default SNMP Communities NOT Removed\"", True)
print("Default SNMP Communities NOT Removed")
else:
if (re.match(ynsnmpdisable,"yes")):
exsh.clicmd("create log message \"Disabling SNMP access\"", True)
print("Disabling SNMP access")
exsh.clicmd("disable snmp access snmp-v1v2", True)
else:
exsh.clicmd("create log message \"SNMP Not Configured\"", True)
print("SNMP Not Configured")